0% found this document useful (0 votes)
15 views40 pages

COA CSE 2009 Module-2 Part-1

The document discusses various addressing modes in computer architecture, which specify how operands are accessed in instructions. It covers different types of addressing modes such as immediate, register, absolute, indirect, index, and others, along with their functionalities and examples. Additionally, it explains stack operations, subroutines, and parameter passing in programming, highlighting the importance of these concepts in efficient data handling and execution flow.

Uploaded by

hajeera.nk
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)
15 views40 pages

COA CSE 2009 Module-2 Part-1

The document discusses various addressing modes in computer architecture, which specify how operands are accessed in instructions. It covers different types of addressing modes such as immediate, register, absolute, indirect, index, and others, along with their functionalities and examples. Additionally, it explains stack operations, subroutines, and parameter passing in programming, highlighting the importance of these concepts in efficient data handling and execution flow.

Uploaded by

hajeera.nk
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/ 40

PRESIDENCY UNIVERISTY, BENGALURU, School of Engineering

Computer Organization and Architecture

CSE 2009

Module-2: Instruction Set Architecture and Memory Unit

Saturday, February 15, 1


2025
Addressing Modes
• The different ways in which the operand is
specified in an instruction are addressing mode.

Saturday, February 15, 2025


2
Instruction cycle and PC
• The control unit of computer is designed to go
through an instruction cycle that is divided into 3
major phases:
• 1.Fetch the instruction
• 2.Decode
• 3.Execute
• PC is register that keeps track of the instructions in
the program stored in memory.PC holds the address of
the instruction to be executed next and is incremented
each time an instruction is fetched from memory.

Saturday, February 15, 2025


3
Addressing modes
• Programmers use some data which may be a constant, local
variable, global variable, pointers, arrays, etc
• That means, data is stored in different ways using different data
structures in different locations.
• 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, February 15,


2025 4
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, February 15, 2025


5
Immediate mode:
• The operand is given explicitly in the instruction.
e.g. MOV 200immediate,R0
• The instruction places the value 200 in the register 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 hash 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

• Ex: A=B+6 mov B,R1


add #6,R1
mov R1, A
Saturday, February 15,
2025 6
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, February 15, 2025


7
Memory

200 OPCODE MODE


201
ADDRESS=500
202 NEXT INSTRUCTION

399
450
400
700

500 800
600
900
800
300

Saturday, February 15, 2025 8


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
Processor registers are used as temporary
storage locations where the data in a register
are accessed using register mode.

Saturday, February 15,


2025 9
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.

• The effective address of an operand is the contents of register or memory location


whose address appears in the instruction.

• OR

• The actual address of the operand is called as effective address

• 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, February 15,


2025 10
Saturday, February 15,
2025 11
• 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, February 15,


2025 12
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, February 15, 2025


13
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, February 15,


2025 14
Saturday, February 15, 15
2025
Saturday, February 15, 16
2025
• 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) from this address to
the location where the operand is found.
• An alternative use is illustrated in figure B. Here, the
constant X corresponds to a memory address, and the
contents of the index register define the offset to the
operand.
• In either case, the effective address is the sum of the
two values, one is given explicitly in instruction and
the other is stored in a register.

Saturday, February 15,


2025 17
Base with Index Mode
• Index addressing mode just we discussed is an most basic form.
• Several variations of this is also available.
• A second register may be used to contain the offset address
X(instead of writing directly)
• 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, February 15,


2025 18
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, February 15,


2025 19
Relative Addressing:
• In index addressing mode, we used one of the GPR.
• Instead of GPR, if we use another special purpose register called program
counter (PC), then it is known as relative addressing mode.
• Then X(PC) can be used to address a memory location that is X bytes away
from the location pointed by the program counter.
EA=[PC]+X
The effective address is determined by the index mode using the program
counter in the place of the general purpose register.
Its common use is to specify the target address in branch instructions. An
instruction such as
Branch>0 Loop
Causes program execution to go to the branch target location identified by
the name LOOP if the branch condition is satisfied. this location can be
computed by specifying it as an offset from the current value of the
program counter.
Since the branch target may be either before or after the branch instruction,
the offset is given as a signed number.

Saturday, February 15,


2025 20
Additional Modes
• So far we have discussed the six basic addressing modes- register, absolute,
immediate, index, indirect and relative.
• Many computers provide two additional modes:
1) Autoincrement Mode
2) Autodecrement Mode
Autoincrement mode:
• It is generally used to increment the content of register(i.e.,data) or array
pointer
• 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)+
• We denote autoincrement mode by putting the specified register in
parentheses, to show that contents of register are used as the effective
address.

Saturday, February 15,


2025 21
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.
• We denote the autodecrement mode by putting the specified
register in parentheses, preceded by a minus sign to indicate
that the contents of the register are to be decremented before
being used as the effective address. Thus we write
-(Ri)

Saturday, February 15,


2025 22
STACK
• Data operated on by a program can be organized in a
variety of ways.
• Now, we consider the important data structure known as
STACK.
• 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
TOP of the STACK, and the other end is called the bottom.
• The structure sometimes referred to as a pushdown stack
or last –in first –out(LIFO). That is the last data item placed
on the stack is the first one removed when retrieval begins.

Saturday, February 15,


2025 23
PUSH:
• Placing a new item on the stack.
POP:
• Removing the top item from the stack.

• Assume that the first element is placed in location bottom, and


when new elements are pushed onto the stack, they are placed
in successively lower address locations. We use a stack that
grows in the direction of decreasing memory addresses in our
discussion, because this is common practice.
• The figure shows a stack of data items in the memory of a
computer, it contains numerical values, with 43 at the bottom
and -28 at the top.
• A processor 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(SP).

Saturday, February 15,


2025 24
Saturday, February 15, 25
2025
• 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.
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 so that it points to the new
top element. The figure shows the effect of the each of these operations on
the stack.

Saturday, February 15,


2025 26
Saturday, February 15, 27
2025
• 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
• When a stack used in a program, it is usually allocated a fixed amount of
space in the memory .
• In this case we must avoid pushing an item onto the stack when
the stack has reached its maximum size.
• Also, we must avoid attempting to POP an item off an empty stack, which
could result from a programming error.

Saturday, February 15,


2025 28
• Suppose that a stack runs from location 2000(bottom) .

• The stack pointer is loaded initially with the address value 2004.
recall that SP is decremented by 4 before new item pushed on the
stack. Hence an initial value of 2004 means that the first item
pushed onto the stack will be at location 2000.

• 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, February 15,


2025 29
SAFE PUSH

Saturday, February 15,


2025 30
SAFEPOP

Saturday, February 15,


2025 31
SUBROUTINES
• In a given program, it is often necessary to perform a particular
subtask many times.

• 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, February 15,


2025 32
Saturday, February 15, 33
2025
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, February 15,


2025 34
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, February 15,
2025 35
• In this case, the return address(RA) of the second call is also

stored in the link register, destroying its previous contents.

• Hence it is essential to save the contents of the link register in

some other location before calling another subroutine, otherwise

the return address of the first subroutine will be lost.

Saturday, February 15,


2025 36
Parameter Passing
• When calling a subroutine, a program must provide to the subroutine the
parameters , that is operands or their addresses, to be used in the computation.

• Later the subroutine returns other parameters, in this case the results of the
computation.

• 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.

• Alternatively, the parameters may be placed on the processor stack.

Saturday, February 15,


2025 37
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, February 15,


2025 38
Saturday, February 15,
2025 39
• If many parameters are involved, there may not be

enough general-purpose registers available for

passing them to the subroutine.

Saturday, February 15,


2025 40

You might also like