Professional Documents
Culture Documents
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 1
The term addressing mode refers to the way the operand
of an instruction is specified. Different types of
addressing modes are:
Immediate
Direct
Indirect
Register
Register Indirect
Displacement (Indexed)
Auto Increment and Auto Decrement
Stack Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 2
Immediate Addressing Mode
Instruction
Opcode Operand
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 4
Direct Addressing Mode (Absolute Mode)
Instruction
Opcode Address A
Memory
Operand
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 6
Indirect Addressing Mode
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 7
Large address space
2n where n is the word length
May be nested, multilevel, cascaded
e.g. EA = (((A)))
Multiple memory accesses to find operand
Hence slower
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 8
Through a memory location Through a general purpose
register
A B B Operand
Main Memory
B Operand R1 B
Register
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 9
Indirect Addressing Mode Diagram
Instruction
Opcode Address A
Memory
Pointer to operand
Operand
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 10
Example program for indirect addressing
Address Contents
Move N, R1
Move #NUM1, R2 Initialization
Clear R0
LOOP Add (R2), R0
Increment R2
Decrement R1
Branch > 0 LOOP
Move R0, SUM
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 11
Register Addressing Mode
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 13
Register Addressing Mode Diagram
Instruction
Opcode Register Address R
Registers
Operand
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 14
Register Indirect Addressing Mode
Indirect addressing
EA = (R)
Operand is in memory cell pointed to by contents of
register R
Large address space (2n)
One fewer memory access than indirect addressing
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 15
Register Indirect Addressing Mode Diagram
Instruction
Opcode Register Address R
Memory
Registers
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 16
Index (Displacement) Addressing Mode
Aeff = X + (R)
Address field hold two values
X = base value
R = register that holds displacement
or vice versa
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 17
Index (Displacement) Addressing Diagram
Instruction
Opcode Register R Address A
Memory
Registers
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 18
Address Contents
Move LIST, R0
Move N, R1
Initialization
Clear R2
Clear R3
LOOP Add 2(R0), R2
Add 3(R0), R3
Add #4, R0
Decrement R1
Branch > 0 LOOP
Move R2, SUM2
Move R3, SUM3
(R4)+
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 21
Instruction Formats
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 22
Instruction Length
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 23
Assembly Language
Assembly Level Language uses mnemonics
The set of rules for using mnemonics in the
specification of complete instructions and programs
is called the syntax of the language.
MOVE R0, SUM
ADD #5, R3
ADDI 5, R3
MOVE #5, (R2)
MOVEI 5, (R2)
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 24
Assembler Commands
In addition to providing a mechanism for representing
instructions in a program, the assembly language allows the
programmer to specify other information needed to translate the
source program into the object program. Suppose that the name
SUM is used to represent the value 200. This fact may be
conveyed to the assembler program through a statement such as
SUM EQU 200
The above statement is not an instruction that will be executed
when the object program is run. It merely informs the assembler
that the name SUM should be replaced by the value 200
whenever it appears in the program. Such statements, called
assembler commands, are used by the assembler while it
Dr.H.S.Nagendraswamy, DoS in
translates a source program intoUoM,
CS, anMGM
object program. 25
Stacks and Queues
A stack is a list of data elements, usually words or bytes, with the
accessing restriction that elements can be added or removed at
one end of the list only. This end is called the top of the stack and
the other end is called the bottom. The structure is sometimes
referred to a pushdown stack. The terms push and pop are used to
describe placing new item on the stack and removing the top
item from the stack respectively.
Data stored in the main memory of a computer can be organized
as a stack with successive elements occupying successive
memory locations.
The following figure shows a stack of data items in the main
memory of a computer. It contains numerical values with 43 at
Dr.H.S.Nagendraswamy, DoS in
the bottom and -28 at the top.CS, UoM, MGM 26
A stack in the main memory
Stack
pointer
register
Current top
SP -28
element
17
739
Stack
Bottom
BOTTOM 43
element
2k - 1
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 27
A CPU register is used to keep track of the address of the element of
the stack that is at the top at any given time. This register is called the
stack pointer. It could be one of the general-purpose registers or a
register dedicated to this function. The push operation can now be
implemented with the following instructions, where SP represents the
stack pointer:
Decrement SP
MOVE NEWITEM, (SP)
SP 19
-28 -28
17 SP 17
Stack 739 739
43 43
NEWITEM 19 NEWITEM 19
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 30
Subroutines
In a given problem, it is often necessary to perform a particular task
many times on different data values. A repeated task is normally
implemented as a subroutine.
A set of instructions that constitute a subroutine is placed in the main
memory and any program that requires the use of the subroutine
simply branches to its starting location. When a program branches to
a subroutine we say that it is calling the subroutine. The instruction
that performs this branch operation is called a Call-subroutine
instruction.
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 31
Call_subroutine instruction is a special branch instruction that
performs the following operations.
Store the contents of the PC in the link register.
Branch to the target address specified by the instruction
After a subroutine has been executed, the calling program must
resume execution, continuing immediately after the instruction that
called the subroutine. The subroutine is said to return to the program
that called it. The location where the calling program resumes
execution is the location pointed to by the PC while the
Dr.H.S.Nagendraswamy, DoS in
Call_subroutine instruction is being executed.
CS, UoM, MGM 32
Hence, the contents of the PC must be saved by the Call_subroutine
instruction to enable correct return to the calling program.
The way in which a computer makes it possible to call and return
from subroutine is referred to as its subroutine linkage method. The
simplest subroutine linkage method is to save the return address in a
specific location, which may be a register dedicated to this function.
Such a register is called the link register. The subroutine then returns
to the calling program by branching indirectly through the link
register.
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 33
The Return_from_subroutine instruction perform operation.
Link
Register 201 201 201
Dr.H.S.Nagendraswamy, DoS in
CS, UoM, MGM 35
Subroutine Nesting
Memory Main Subroutine Subroutine
location program FACT MULT
first instruction
first instruction
200 Call FACT
201 next instruction Call MULT
next instruction
Return
Return
250 END
Dr.H.S.Nagendraswamy, DoS in
Illustration of subroutine nesting
CS, UoM, MGM 36
Program to illustrate Subroutine
END
Subroutine
ARRAY_ADD Add (R2)+, R0 : Add entry from the list to
Decrement R1 : previous sum in R0 till all
Branch > 0 ARRAY_ADD : the numbers are added
Return Dr.H.S.Nagendraswamy, DoS in: Return to the calling program
CS, UoM, MGM 37