Addressing modes examples and subroutines

JyotiprakashMishra18 53 views 14 slides Mar 16, 2021
Slide 1
Slide 1 of 14
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14

About This Presentation

Slides for Computer Organization


Slide Content

Addressing Modes Utility and
Subroutines

Branching
N,R1Move
NUMn
NUM2
NUM1
R0,SUM
R1
"Next" number to R0
Using a loop to addnnumbers.
LOOP
Decrement
Move
LOOP
loop
Program
Determine address of
"Next" number and add
N
SUM
n
R0Clear
Branch>0



• •

Branch target
Conditional branch

Utility of using
Indirect Addressing

Using Auto-increment Mode

Utility of Indexed Addressing
A list of students’ marks

Find sum of Test1, Test2 and Test 3
scores

Subroutines
•In a given program, it is often necessary to perform a
particular subtask many times on different data values.
•Such a subtask is usually called a subroutine.
•Only one copy of the instructions that constitute the
subroutine is placed in the memory,.
•Any program that requires the use of the subroutine
simply branches to its starting location – Callingthe
subroutine.
•After a subroutine has been executed, the calling
program must resume execution, continuing
immediately after the instruction that called the
subroutine –Returningfrom subroutine.

Calling and Returning
•Calling
–Store the contents of the PC in the link register.
–Branch to the target address specified by the
instruction.
•Returning
–Branch to the address contained in the link register

Calling and
Returning

Nested subroutine call
•One subroutine calls another, which calls another and so on.
•In this case, the return address of the second call is also
stored in the link register, destroying its previous contents.
•Solution
–The last subroutine returns first.
–LIFO: Use Processor stack for storing return addresses.
•SP points the top of stack.
•The Callinstruction pushes the contents of the PC onto the
processor stack and loads the subroutine address into the PC.
•The Returninstruction pops the return address from the
processor stack into the PC.

Nested subroutine calls -example

Marks addition program using subroutine –
passing parameters through registers

Passing parameters using stack

Stack contents
Tags