Lecture 03 - Instruction Set Architecture
Lecture 03 - Instruction Set Architecture
BYNITE
Topics covered:
Instruction Set Architecture
Instruction execution and sequencing
2
Instruction execution and sequencing (contd..)
3
Instruction execution and sequencing (contd..)
Execution steps:
0 Move A, R0
Step I:
4 Add B, R0 -PC holds address 0.
8 Move R0, C -Fetches instruction at address 0.
-Fetches operand A.
-Executes the instruction.
-Increments PC to 4.
Step II:
-PC holds address 4.
A -Fetches instruction at address 4.
-Fetches operand B.
-Executes the instruction.
-Increments PC to 8.
B Step III:
-PC holds address 8.
-Fetches instruction at address 8.
-Executes the instruction.
C -Stores the result in location C.
Instructions are executed one at a time in order of increasing addresses.
“Straight line sequencing”
4
Instruction execution and sequencing (contd..)
5
Instruction sequencing and execution (contd..)
6
Instruction execution and sequencing (contd..)
❑ Decrement R1:
◆ Initially holds the number of numbers that is to be added
(Move N, R1).
◆ Decrements the count each time a new number is added
(Decrement R1).
◆ Keeps a count of the number of the numbers added so far.
❑ Branch>0 LOOP:
◆ Checks if the count in register R1 is 0 (Branch > 0)
◆ If it is 0, then store the sum in register R0 at memory location
SUM (Move R0, SUM).
◆ If not, then get the next number, and repeat (go to LOOP). Go
to is specified implicitly.
❑ Note that the instruction (Branch > 0 LOOP) has no explicit
reference to register R1.
7
Instructions execution and sequencing (contd..)
8
Instruction execution and sequencing (contd..)
9
Instruction sequencing and execution (contd..)
Move N, R1
Move #NUM1, R2 (Initialize R2 with address of NUM1)
Clear R0
LOOP Add (R2), R0 (Indirect addressing)
Add #4, R2 (Increment R2 to point to the next number)
Decrement R1
Branch>0 LOOP
Move R3, SUM
10
Instruction execution and sequencing (contd..)
Move N, R1
Move #NUM1, R2 (Initialize R2 with address of NUM1)
Clear R0
LOOP Add (R2)+, R0 (Autoincrement)
Decrement R1
Branch>0 LOOP
Move R3, SUM
11
Stacks
12
Stacks (contd..)
13
Subroutines
14
Subroutines (contd..)
15
Subroutines (contd..)
Memory Memory
location Calling program location Subroutine SUB •Calling program calls a subroutine,
whose first instruction is at address
1000.
200 Call SUB 1000 first instruction
•The Call instruction is at address
204 next instruction 200.
•While the Call instruction is being
Return executed, the PC points to the next
instruction at address 204.
•Call instructions stores address 204
in the Link register, and loads 1000
1000
into the PC.
•Return instruction loads back the
PC 204 address 204 from the link register
into the PC.
Link 204
Call Return
16
Subroutines and stack
17
Assembly language
18
Assembly language (contd..)
20
Assembly language (contd..)
EQU:
Memory Addressing •Value of SUM is 200.
address or data
ORIGIN:
label Operation information
•Place the datablock at 204.
DATAWORD:
Assembler directives SUM EQU 200 •Place the value 100 at 204
ORIGIN 204 •Assign it label N.
N DA T AW ORD 100 •N EQU 100
NUM1 RESERVE 400 RESERVE:
ORIGIN 100 •Memory block of 400 words
Statements that ST AR T MO VE N,R1 is to be reserved for data.
generate MO VE #NUM1,R2
•Associate NUM1 with address
machine CLR R0
instructions LOOP ADD (R2),R0 208
ADD #4,R2 ORIGIN:
DEC R1 •Instructions of the object
BGTZ LOOP program to be loaded in memory
MOVE R0,SUM starting at 100.
Assembler directives RETURN RETURN:
END •Terminate program execution.
END:
•End of the program source text
21
Assembly language (contd..)
❑ Assembly language instructions have a generic form:
Label Operation Operand(s) Comment
❑ Four fields are separated by a delimiter, typically one or
more blank characters.
❑ Label is optionally associated with a memory address:
◆ May indicate the address of an instruction to be executed.
◆ May indicate the address of a data item.
❑ How does the assembler determine the values that
represent names?
◆ Value of a name may be specified by EQU directive.
• SUM EQU 100
◆ A name may be defined in the Label field of another
instruction, value represented by the name is determined by
the location of that instruction in the object program.
• E.g., BGTZ LOOP, the value of LOOP is the address of the
instruction ADD (R2) R0
22
Assembly language (contd..)
23
Encoding of machine instructions
24
Encoding of machine instructions (contd..)
One-word instruction format.
8 7 7 10
Opcode : 8 bits.
Source operand : 4 bits to specify a register
3 bits to specify the addressing mode.
Destination operand : 4 bits to specify a register.
3 bits to specify the addressing mode.
Other information : 10 bits to specify other information
such as index value.
25
Encoding of machine instructions (contd..)
What if the source operand is a memory location specified
using the absolute addressing mode?
8 3 7 14
Opcode : 8 bits.
Source operand : 3 bits to specify the addressing mode.
Destination operand : 4 bits to specify a register.
3 bits to specify the addressing mode.
26
Encoding of machine instructions (contd..)
27
Encoding of machine instructions (contd..)
❑ Insist that all instructions must fit into a single 32 bit word:
◆ Instruction cannot specify a memory location or an immediate
operand.
◆ ADD R1, R2 can be specified.
◆ ADD LOC, R2 cannot be specified.
◆ Use indirect addressing mode: ADD (R3), R2
◆ R3 serves as a pointer to memory location LOC.
❑ How to load address of LOC into R3?
◆ Relative addressing mode.
28
Encoding of machine instructions (contd..)
Three-operand instruction
29
Thank You for Listening !
30