CHAPTER 10 INSTRUCTION SETS

32
COMPUTER ORGANIZATIONS CSNB123 CHAPTER 10 INSTRUCTION SETS CSNB123 COMPUTER ORGANIZATION NSMS2013 Ver.1 Systems and Networking 1

description

CHAPTER 10 INSTRUCTION SETS. CSNB123 coMPUTER oRGANIZATION. Architecture. Recap Chapter 1. Attributes visible to the programmer Instruction set Number of bits used for data representation I/O mechanisms Addressing techniques. Machine Instruction Characteristics. - PowerPoint PPT Presentation

Transcript of CHAPTER 10 INSTRUCTION SETS

Page 1: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 1

CHAPTER 10 INSTRUCTION SETSCSNB123 COMPUTER ORGANIZATION

NSMS2013 Ver.1

Page 2: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 2

Architecture

• Attributes visible to the programmer Instruction set Number of bits used

for data representation

I/O mechanisms Addressing

techniques

Recap Chapter 1

Ver.1

Page 3: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 3

Machine Instruction CharacteristicsTerm DescriptionMachine instruction / computer instructions

Instruction which is executed by processor

Processor’s instruction set

Collection of different instructions that the processor can execute

• Each instruction must contain the information required by the processor for execution

NSMS2013 Ver.1

Page 4: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 4

Machine Instruction Characteristics (Cont.)

• Elements of Machine Instruction (MI)Elements DescriptionOperation code (opcode)

specifies the operation to be performedADD, SUB

Source operand reference

operands that are inputs for the operation

Result operand reference

the operation may produce a result

Next instruction reference

tell processor where to fetch the next instruction after the execution of this instruction is complete

NSMS2013 Ver.1

Page 5: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 5

Simple Instruction Format

• Instruction is represented by a sequence of bits• During instruction execution, an instruction is read into an

instruction register (IR) in the processor.• The processor must be able to extract the data from the various

instruction fields to perform the required operation• Opcodes are presented by abbreviations-mnemonics-that indicate

the operation ..why do this …hard to remember code in binary form

NSMS2013 Ver.1

Page 6: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 6

Simple Instruction Format (Cont.)• Operands also represented symbolically • Example:

Add the value contained in the location Y to the contents of register R

Y=refer to the address of a location in memory R=refers to a particular register

NSMS2013 Ver.1

ADD R,Y

Page 7: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 7

Instruction Types• HLL language instruction in BASIC• Instruct the computer to add the value stored

in Y to the value stored in X and put the result in X.

NSMS2013 Ver.1

X=513, Y=514X=X + Y

Page 8: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 8

Instruction Types (Cont.)

Simple instruction sets• Load a register with the contents of memory

location 513• Add the contents of memory location 514 to

the register• Store the contents of the register in memory

location 513NSMS2013 Ver.1

X=513, Y=514X=X + Y

Page 9: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 9

Instruction Types (Cont.)Category DescriptionData processing Arithmetic and logic instructionsData storage Movement of data into or out of register

and or memory locationsData movement I/O instructionsControl-test and branch instructions

• Test instructions are used to test the value of a data word or the status of the operation

• Branch instructions are used to branch to a different set of instructions depending on the decision made

NSMS2013 Ver.1

Page 10: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 10

Number of Address• Address refer to location that store the value

of the operands• In most architecture, most instructions have

1,2 or 3 operand addresses

NSMS2013 Ver.1

Page 11: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 11

Example

Y=(A-B)/[C+(DXE)]

NSMS2013 Ver.1

Page 12: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 12

3 address instructions• Each instruction specifies two source operand

locations and a destination operation location• Operand 1, Operand 2, Result• Not common since they require a relatively

long instructions format to hold the three address references

• T = temporary location-to store intermediary result

NSMS2013 Ver.1

Page 13: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 13

Example

Y=(A-B)/[C+(DXE)]

NSMS2013 Ver.1

Instruction CommentSUB Y, A, B Y A-BMPY T, D, E T D * EADD T, T, C T T + CDIV Y, Y, T Y Y / T

Page 14: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 14

2 address instructions• Each instruction specifies both an operand

and the result location• Operand 1, Operand 2, Result• MOVE – is used to move one of the values to a

result/temp loc before performing the operation

• Reduce space for address

NSMS2013 Ver.1

Page 15: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 15

Example

Y=(A-B)/[C+(DXE)]

NSMS2013 Ver.1

Instruction CommentMOVE Y, A Y ASUB Y, B Y Y – BMOVE T, D T DMPY T, E T T * EADD T, C T T + CDIV Y, T Y Y / T

Page 16: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 16

1 address instructions• Second address must be implicit (hidden)• Common in earlier machines- the implied

address being a processor register known as the accumulator (AC)

• The AC contains one of the operands and is used to store the result

NSMS2013 Ver.1

Page 17: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 17

Example

Y=(A-B)/[C+(DXE)]

NSMS2013 Ver.1

Instruction CommentLOAD D AC DMPY E AC AC * EADD C AC AC + CSTOR Y Y AC LOAD A AC ASUB B AC AC – BDIV Y AC AC / YSTOR Y Y AC

Page 18: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 18

0 address instructions• All address must be implicit (hidden)• Stack-based operations

last-in-first-out (LIFO) set of locations Interact with the stack using PUSH and POP

operations • PUSH – to push a data from memory onto the stack• POP – to pop out data from the stack to a memory

location

NSMS2013 Ver.1

Page 19: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 19

ExampleY=(A-B)/[C+(DXE)]

NSMS2013 Ver.1

InstructionPUSH APUSH BSUBPUSH CPUSH EPUSH DMPYADDDIVPOP

A

PUSH BPUSH A

A

B

A

SUB

A

PUSH C

C

A

PUSH D

C

D

APUSH E

C

D

E

A

C

MPY

D

A

C

ADDA DIVPOP

Page 20: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 20

Number of Address (Cont.)• Fewer address

require less complex processor Instruction become shorter But contain more total instructions-longer

execution time

NSMS2013 Ver.1

Page 21: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 21

Number of Address (Cont.)• Multiple address instructions – have multiple

general purpose register • Register references are faster than memory

references – speed up the execution• Most contemporary machine employ a

mixture of 2 and 3 address instructions

NSMS2013 Ver.1

Page 22: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 22

Types of Operands• Categories of data

Addresses Numbers• Integer/floating point

Characters• ASCII etc.

Logical data• 0/1-false/true

NSMS2013 Ver.1

Page 23: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 23

Types of Operations• Data transfer• Arithmetic • Logical• Conversion• I/O• Transfer of control

NSMS2013 Ver.1

Refer to Table 9.3

Page 24: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 24

Types of Operations (Cont.)

NSMS2013 Ver.1

Page 25: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 25

Types of Operations (Cont.)

NSMS2013 Ver.1

Page 26: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 26

Control Operations• Branch/jump instruction

Sequential Unconditional branch Conditional branch

• Skip• Subroutine / procedure call

NSMS2013 Ver.1

Page 27: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 27

Control Operations - Branch• Has one of its operands the address of the next

instruction to be executed• A sequence of code in a computer program which

is conditionally executed depending on whether the flow of control is altered or not (at the branching point) Conditional – the branch is made only if a certain

condition is met Unconditional – a branch instruction in which the

branch is always taken NSMS2013 Ver.1

Page 28: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 28

Control Operations - Branch (Cont.)Branch Explanation

Sequential • Normal execution• One instruction after the

otherUnconditional branch

• Non-sequential• instruction at the

designated address is unconditionally executed

Conditional branch

• Non-sequential• A branch is made

conditionally to another instruction address.

• If the condition is true, the instruction at the designated address is executed.

NSMS2013 Ver.1

Page 29: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 29

Control Operations - Skip• Useful in loop control• Implies that next instruction to be skipped

NSMS2013 Ver.1

Page 30: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 30

Control Operations – Subroutine• Also known as procedure call• A self-contained computer program that is incorporated into

a larger program• At any point in the program, the procedure may be called or

invoked• The processor is instructed to go and execute the entire

procedure and then return to the point from which the call took place

• A procedure allow the same piece of code to be used many times

• Involves two basic instructions; call and return instruction

NSMS2013 Ver.1

Page 31: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 31

Control Operations – Subroutine (Cont.)

Call instruction• Instructions that branches

from the present location to the procedure

Return instruction• Instruction that returns

from the procedure to the place from which it was called

NSMS2013 Ver.1

Page 32: CHAPTER 10  INSTRUCTION SETS

COMPUTER ORGANIZATIONSCSNB123

Systems and Networking 32

Control Operations – Subroutine (Cont.)

NSMS2013 Ver.1