0% found this document useful (0 votes)
39 views38 pages

COA CSE 2009 Module-2 Part-1

The document discusses various addressing modes used in computer organization and architecture, including immediate, register, absolute, indirect, index, and relative modes. It also covers stack operations, subroutines, and parameter passing techniques in programming. Each addressing mode is explained with examples, highlighting their usage and significance in accessing operands and managing data in memory.

Uploaded by

kumardoddagoudar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views38 pages

COA CSE 2009 Module-2 Part-1

The document discusses various addressing modes used in computer organization and architecture, including immediate, register, absolute, indirect, index, and relative modes. It also covers stack operations, subroutines, and parameter passing techniques in programming. Each addressing mode is explained with examples, highlighting their usage and significance in accessing operands and managing data in memory.

Uploaded by

kumardoddagoudar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 38

PRESIDENCY UNIVERISTY, BENGALURU, School of Engineering

Computer Organization and Architecture

CSE 2009

Module-2: Instruction Set Architecture and Memory Unit

Saturday, March 1, 202 1


5
Addressing modes
• The different ways in which the location of an operand is specified
in an instruction are referred to as addressing modes.
• We can access an operand by specifying the name of the register
or the address of the memory location where the operand is
located.

Saturday, March 1, 202


5 2
Different types of addressing modes
• Immediate mode
• Register mode
• Absolute mode (Direct mode)
• Indirect mode
• Index mode
• Base with index
• Base with index & offset
• Relative mode
• Auto-increment mode
• Auto-decrement mode

Saturday, March 1, 2025


3
Immediate mode:
• The operand is given explicitly in the instruction.
e.g. MOV 200immediate,R0
• The immediate mode is only used to specify the value of a source
operand. Using a subscript to denote the immediate mode is not
appropriate in assembly languages.
• A common convention is to use the sharp sign (#) in front of the
value to indicate that this value is to be used as an immediate
operand.
Hence we write the instruction above in the form
MOV #200,R0
add #6,R1

Saturday, March 1, 202


5 4
Register Mode:
The operand is the contents of a processor
register, the name(address) of the
register is given in the instruction.
e.g. MOV R1,R2
The instruction copies the contents of
register R1 to register R2.

Saturday, March 1, 2025


5
Absolute mode (Direct mode):
The operand is in a memory location; the
address of this location is given explicitly in the
instruction
The instruction uses two modes.
E.g. MOV LOCA,R2
ADD A,B

Saturday, March 1, 202


5 6
Indirect mode:
• In this addressing mode, the instruction does not give the operand or its address
explicitly. instead it provides information from which the memory address of the
operand can be determined. we refer to this address as the effective address(EA) of
the operand.

• To execute the add instruction in the figure(A) the processor uses the value B, which is
in the register R1, as the effective address of the operand. the value read is desired
operand, which the processor adds to the contents or register R0.

Saturday, March 1, 202


5 7
Saturday, March 1, 202
5 8
• Indirect addressing through a memory location is also possible as shown
in the figure(b). In this case processor first reads the contents of memory
location A, then requests a second read operation using the value B as an
address to obtain the operand.

• The register or memory location that contains the address of an


operand is called a pointer.

Saturday, March 1, 202


5 9
Indexing and arrays
• So far we discussed register mode, absolute mode,
immediate mode & indirect mode.
• These are best suited when we are dealing with
constants, variables & pointers.
• But these are not the efficient when we are dealing with
arrays and lists.

Saturday, March 1, 2025


10
Index mode :
• In this mode, effective address of the operand is
generated by adding a constant value to the
contents of a register.
• The register used in this mode is called index register
which may be a special purpose register or any one of
the general purpose register.
• We indicate the index mode symbolically as
X(Ri)
X denotes the constant value in the instruction,
Ri is name of the register involved.
Effective address of the operand is given by
EA = X+[Ri]

Saturday, March 1, 202


5 11
Saturday, March 1, 202 12
5
Saturday, March 1, 202 13
5
• Figure illustrates two ways of using the index mode.
• In figure A the index register R1, contains the address
of a memory location and the value X defines an
offset(also called displacement)
• In figure B, the constant X corresponds to a memory
address, and the contents of the index register define
the offset to the operand.

Saturday, March 1, 202


5 14
Base with Index Mode
• In this addressing mode Effective Address is the sum of two
registers.
Syntax:
(Ri,Rj)
Effective Address:
EA= [Ri]+[Rj]
The first register is called Index Register.
The second register is called Base Register.

Saturday, March 1, 202


5 15
Base with Index and Offset
• Another variation uses 2 registers and a constant .
• In this addressing mode effective address is the sum of
the constant(X) and the contents of the two registers.
Syntax:
X(Ri,Rj)

EA=X+[Ri]+[Rj]
this way is more useful in accessing multiple components
inside each item ( Ex: multi dimensional arrays)

Saturday, March 1, 202


5 16
Relative Addressing:
• In index addressing mode, we used one of the GPR.
• Instead of GPR, if we use program counter (PC), then it is known as relative
addressing mode.
• EA=[PC]+X
The effective address is determined by the index mode using the program
counter in the place of the general purpose register.

Saturday, March 1, 202


5 17
Additional Modes
• Many computers provide two additional modes:
1) Autoincrement Mode
2) Autodecrement Mode
Autoincrement mode:
• The effective address of an operand is contents of register specified in
the instruction. After accessing the operand, the contents of the register
are automatically incremented to point to the next item in the list.
(Ri)+

Saturday, March 1, 202


5 18
Autodecrement mode:
• The contents of a register specified in the instruction are first
automatically decremented and are then used as the
effective address of the operand.
• Thus we write
-(Ri)

Saturday, March 1, 202


5 19
STACK
• A stack is a list of data elements.
• Elements can be added or removed at one end of the list
only, called as TOP of the STACK, and the other end is
called the bottom.
• It referred to as a pushdown stack or last –in first –
out(LIFO).

Saturday, March 1, 202


5 20
PUSH:
• Placing a new item on the stack.
POP:
• Removing the top item from the stack.

• STACK POINTER(SP)- A processor register to keep track of the


address of the element of the stack at the top at any given time.

Saturday, March 1, 202


5 21
Saturday, March 1, 202 22
5
• If we assume a byte addressable memory with 32-bit word length the push
operation can be implemented as

Subtract #4,SP
Move NEWITEM,(SP)

These two instructions move the word from location NEWITEM onto the top of
the STACK decrementing the stack pointer before the move.

Saturday, March 1, 202


5 23
The POP operation can be implemented
as
Move (SP), ITEM
Add #4,SP
These two instructions move the top value
from the stack into the location ITEM and
then increment the stack pointer by 4

Saturday, March 1, 2025


24
Saturday, March 1, 202 25
5
• If the processor has the autoincrement and autodecrement addressing
modes the push operation can be performed by the single instruction
MOVE NEWITEM, -(SP)
And pop operation can be performed by
MOVE (SP)+, ITEM

Saturday, March 1, 202


5 26
• To prevent either pushing an item on a full stack or popping
an item off an empty stack the single instruction push and pop
operations can be replaced by the instruction sequences shown in
the figure.

Saturday, March 1, 202


5 27
SAFE PUSH

Saturday, March 1, 202


5 28
SAFEPOP

Saturday, March 1, 202


5 29
SUBROUTINES
• A subroutine is a group of instructions, performs a particular subtask
which is executed number of times. It is written separately.

• The processor executes this subroutine by transferring the program


control to the subroutine program.

• After completion of subroutine program execution, the program


control is returned back to the main program.

Saturday, March 1, 202


5 30
Saturday, March 1, 202 31
5
CALL Instruction:

The call instruction performs the following operations

• Store the contents of the Program counter(PC) in the link register.

• Branch to the target address specified by the instruction.

RETURN Instruction:

• Loads the program counter(PC) with the contents of link register


and branch to that address.

Saturday, March 1, 202


5 32
Subroutine Nesting
• When one subroutine calls another subroutine to complete a
particular task, the operation is called NESTING.

Calling program SUB1 SUB2


1 1 1
2 2 2
3 3 3
CALL SUB1 CALL SUB2 4
5 5 5
6 RET
RET
Saturday, March 1, 202
5 33
• In this case, the return address(RA) of the second call is also

stored in the link register, destroying its previous contents.

Saturday, March 1, 202


5 34
Parameter Passing
• When calling a subroutine, a program must provide to the subroutine the
parameters.

• This exchange of information between a calling program and a subroutine is


referred to as parameters passing.

• Parameters passing may be accomplished in several ways.

• The parameters may be placed in registers or in memory locations, where they can
be accessed by subroutine

Saturday, March 1, 202


5 35
Passing Parameters Through
Registers.
• Passing parameters through registers is straight forward and

efficient.

• Figure shows how the program for adding a list of numbers can be

implemented as subroutine.

Saturday, March 1, 202


5 36
Saturday, March 1, 202
5 37
• If many parameters are involved, there may not be

enough general-purpose registers available for

passing them to the subroutine.

Saturday, March 1, 202


5 38

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy