0% found this document useful (0 votes)
3 views91 pages

Addressing Modes in Computer Architecture

The document discusses various addressing modes used in computer architecture, including immediate, register, absolute, indirect, index, relative, autoincrement, and autodecrement modes. It also covers assembly language instructions, shift and rotate operations, and basic arithmetic and logic operations. Additionally, it introduces assembler directives for translating source programs into object programs.

Uploaded by

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

Addressing Modes in Computer Architecture

The document discusses various addressing modes used in computer architecture, including immediate, register, absolute, indirect, index, relative, autoincrement, and autodecrement modes. It also covers assembly language instructions, shift and rotate operations, and basic arithmetic and logic operations. Additionally, it introduces assembler directives for translating source programs into object programs.

Uploaded by

s9charan.2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

BANGALORE INSTITUTE OF TECHNOLOGY

Computer Organization and


Architecture
BEC306C
Course Handling Faculty: Gahan A V

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Module -2

Machine Instructions
and Programs – Part 2

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Addressing Modes

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

• A Program operates on data that resides in computer memory

• This data can be organized in a variety of ways

• Programmers use organization called “Data Structures” to represent data in computations

• List
• Linked List
• Arrays
• Set of data elements stored under the same name
• Queues
• Linear data structure or more abstractly a sequential collection

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Addressing Modes
⚫ The way in which the location of an operand is specified
in an instruction is called as addressing mode.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Immediate mode
 The operand is given explicitly in the instruction.
Move 200immediate, R0
 Places the value 200 in register R0
 Immediate mode is only used to specify the value of source operand
 Using subscript to denote immediate node is not applicable to ASML
 A common convention is to use #
Move #200,R0

Eg: A=B+6 Move B,R1


Add #6,R1
Move R1,A

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Register mode
 The operand is the contents of a processor register; the name
(address) of the register is given in the instruction.

 Move R1,R2

 Add R0,R1

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Absolute mode (Direct mode)


 The operand is in a memory location; the address of this memory
location is given explicitly in the instruction.
 Move LOC,R1

 Add A,R0

 Above instructions uses two modes: Direct mode and register mode
 EX2:Add NUM1,R0- DIRECT MODE.
 (Contents imn memory loc NUM1 added with contents of R0 and result is
stored in R0)
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
BANGALORE INSTITUTE OF TECHNOLOGY

Indirect mode
 The instruction does not give the operand or its address explicitly. Instead
it provides information from which the memory address of an operand can
be determined
 “We refer this address as the effective address(EA)”
 The effective address of the operand is the contents of a register or
memory location whose address appears in the instruction.
 We denote indirect by placing the name of the register or memory address
in the instruction in parentheses ‘( )’
 Move (R0),R1
 Add (LOC),R2

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Index mode and arrays


 This type of addressing provides different kind of flexibility for
accessing operands
 Useful in dealing with list and arrays

 Index Mode: The effective address of the operand is generated by


adding a constant value to the contents of a register.

 We indicate the Index mode symbolically as X(Ri)

 EA = X + [Ri]
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
BANGALORE INSTITUTE OF TECHNOLOGY

X(Ri)

 X denotes the constant value contained in instruction

 Ri name of the register

 Register may be special register or a general register. In either case it is


referred as Index register.

 The contents of the index register are not changed in the process of
generating the effective address

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 The value X defines an offset (also called a displacement) from this


address to the location where the operand is found.

⚫ Add 20(R0),R1

⚫ Add 1000(R1),R2

 The constant X may be given either as an explicit number or as a


symbolic name representing a numerical value.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Add 20(R1),R2 Add 1000(R1),R2

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Consider a simple example involving a list of test scores for


students taking a given course.

 A four-word memory block comprises a record that stores the


relevant information for each student.(32 bit length word)

 Each record consists of the student's identification number


(ID), followed by the scores the student earned on three tests.

 There are n students in the class. Compute the sum of all


score obtained on each tests & store in SUM1, SUM2, SUM3

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Several variations of the basic form provide very efficient access to


memory operands
 Base with Index mode
 A second register may be used to contain the offset X
 The effective address is the sum of the contents of registers specified in the
instruction.
 (Ri,Rj): EA = [Ri]+[Rj]
⚫ Move (R0,R1),R2
⚫ Add (R1,R2),R0

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Base with Index and Offset mode


 The effective address is the sum of the constant X and the contents of
registers specified in the instruction.

 X(Ri,Rj): EA = [Ri]+[Rj]+X

⚫ Move 20(R0,R1),R2
⚫ Add 1000(R1,R2),R0

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Relative mode
 The effective address is determined by the Index mode using the
program counter in place of the general-purpose register Ri.
X(PC)
 EA = [PC] + X

 note that X is a signed number

 X bytes away from the location presently pointed by the program counter

 This location is computed by specifying it as an offset from the current value of PC.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Autoincrement mode
 The effective address of the operand is the contents of a register specified in the
instruction.
 After accessing the operand, the contents of this register are automatically
incremented to point to the next item in a list.

(Ri)+
EA = [Ri];
Increment Ri
 The increment is 1 for byte-sized operands, 2 for 16-bit operands, and 4 for
32-bit operands.
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
BANGALORE INSTITUTE OF TECHNOLOGY

Addressing Modes..

Add (R2),R0
Add (R2)+, R0 Add #4, R2

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

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.
-(Ri)
Decrement Ri;
EA = [Ri]
⚫ The decrement is 1 for byte-sized operands, 2 for 16- bit operands, and 4 for
32-bit operands.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Assembly Language

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Machine instructions are represented by patterns of 0s and 1s.


 Awkward to deal with when discussing or preparing programs.
 We use symbolic names
 Assembly language – A complete set of symbolic names and rules for their
use

 So far, we have used normal words such as Move, Add, Increment and
Branch
 When writing programs for specific computer such word are normally
replace by acronyms called “mnemonics” such as MOV, ADD, INC and
BR
 Similarly we use notation R3 to refer register 3 and LOC refer to
memory location
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
BANGALORE INSTITUTE OF TECHNOLOGY

 Register R1 and R2 of a computer contain the values 1200 and 4600. What is the EA of
the memory operand in each of the following

a) Load 20(R1), R5

EA = 20 + [R1] = 20 + 1200

b) Store R5, 30(R1,R2)

EA = 30 + [R1] +[R2] = 30 +1200 + 4600

c) Add –(R2), R5

EA = 4596

d) Subtract (R1)+, R5

EA = 1200

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Additional Instructions

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 There are many applications that require the bits of an operand to be


shifted right or left with some specified number of bit positions

 Shift Instructions
 Logical Shift
 Arithmetic Shift
 Rotate Instructions

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Logical Shifts
 Logical shift
 Logical shift left (LShiftL)
 Logical shift right (LShiftR)

 These instructions shift an operand over a number of bit positions


specified in a count operand contained in the instruction.
 General form
LShiftL count, dst

LShiftR count, dst


 The count operand may be an immediate operand, or it may be contained in a
processor register.
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Arithmetic Shifts
• The arithmetic left shift is exactly same as the logical shift

• In arithmetic right shift the sign bit must be repeated to fill in the vacated
position
• Retains the sign of the number

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

NOTE: In a study of 2’s complement binary representation reveals that, Shifting a


number one bit position to the left is equivalent to multiplying it by 2; Shifting it to
right by 1 bit is equivalent to dividing it by 2

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Rotate Operations
 In the shift operations, the bits shifted out of the operand are lost,
except for the last bit shifted out which is retained in the Carry flag C.
 To preserve all bits, a set of rotate instructions can be used.
 They move the bits that are shifted out of one end of the operand
back into the other end.
 Rotate without carry
 Rotate with carry

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Multiplication and Division


 Multiply Ri, Rj
Rj ← [Ri] х [Rj]

 Divide Ri, Rj
Rj ← [Ri] / [Rj]

Quotient is in Rj, remainder may be


placed in R(j+1)

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Logic Instructions
 Logic operations such as AND, OR, and NOT, applied to
individual bits, are the basic building blocks of digital
circuits.
 Bitwise logic instructions
 Not dst
 And src,dst
 Or src,dst

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 To find negative (2’s complement) of a number


Not R0
Add #1,R0
 Many computers have a single instruction for this

Negate R0

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Assembler Directives

In addition to providing a mechanism for representing instructions &


modes in a program, the assembly language allows the programmer to
specify other information needed to translate the source program into the
object program

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 SUM EQU 200

 This statement does not denote an instruction that will be executed when the
object program is run, in fact it will not appear in the object program

 “It simply informs the assembler that SUM should be replaced by 200”

 Such statements are called assembler directive

 This are used by the assembler while it translates source program to object
program.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Assembler Directives..
 To produce an object program, an assembler
has to know
 How to interpret the names
 Where to place the instructions in the memory
 Where to place the data operands in the memory

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Assembler Directives..
 EQU (equate) - informs the assembler that the variable name
should be replaced by the value specified.
 In this case, SUM should be replaced by the value 200 wherever it
appears in the program
 ORIGIN - tells the assembler program where in the memory to
place the data block that follows.
 In this case, the location specified has the address 204

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Assembler Directives..
⚫ DATAWORD - informs the assembler that the data
value specified is to be placed in the memory word
⚫ In this case, the data value 100 is to be placed in the memory word
at address 204.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Assembler Directives..
 RESERVE - declares that a memory block of specified bytes is to be
reserved for data
⚫ In this case, a memory block of 400 bytes is to be reserved for data, and that
the name NUM1 is to be associated with address 208.
 END - tells the assembler that this is the end of the source program
text.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Most assembly languages require statements in a source program to be


written in the form
Label Operation Operand(s) Comment
 The Label is an optional name associated with the memory address
 Address of machine instructions
 Addresses of data items
 The Operation field contains the OP-code mnemonic of the desired
instruction or assembler directive.
 The Operand field contains addressing information for accessing
one or more operands, depending on the type of instruction.
 The Comment field is ignored by the assembler program.
 Used for documentation purposes
 Makes the program easier to understand.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 A source program written in an assembly language must be


assembled into a machine language object program before it can
be executed.
⚫ This is done by the assembler program
 Assembler replaces all symbols denoting operations and
addressing modes with the binary codes used in machine
instructions, and replaces all names and labels with their actual
values.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Number Notation
 It is often convenient to use the familiar decimal notation.
⚫ ADD #93,R1
 These values are stored in the computer as binary numbers.
 In some situations, it is more convenient to specify
the binary patterns directly.
⚫ ADD #%01011101,R1
 Binary numbers can be written more compactly as
hexadecimal, or hex, numbers
 ADD #$5D,R1

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Basic Input/Output
Operations

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

I/O
 The data on which the instructions operate are not necessarily already
stored in memory.
 Data need to be transferred between processor and outside world

(disk, keyboard, etc.)


 I/O operations are essential, the way they are performed can have a

significant effect on the performance of the computer.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Consider a task that reads in character input from a keyboard and


produces character output on a display screen.

 A simple way of performing such I/O tasks is to use a method


known as program-controlled I/O

 Rate of data transfer from keyboard to a computer is limited by the typing


speed of the user
 The rate of output transfers from the computer to the display is much
higher.
 However, this is still much slower than the speed of a processor that can
execute many millions of instructions per second
 The difference in speed between the processor and I/O devices creates the
need for mechanisms to synchronize the transfer of data b/w them

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

A solution to this problem is as follows:

 On output, the processor sends the first character and then waits for a signal
from the display that the character has been received. Later the processor sends
the second character & so on.

 Input is sent from the keyboard in a similar way.

 Processor waits for a signal indicating that a character key has been pressed, then the
processor proceeds to read that code.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Program-Controlled I/O Example..

Bus
By default:
SIN = 0
SOUT = 1

Processor
DATAIN DATAOUT
SIN = 1; if character
is present in DATAIN
SIN SOUT

SOUT = 1; display K eyboard Display


is ready to receive
character
Figure 2.19 Bus connection for processor, keyboard, and display.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

READWAIT Branch to READWAIT if SIN = 0


Input from DATAIN to R1

WRITEWAIT Branch to WRITEWAIT if SOUT=0 • SIN = 0; ReadWait


• SIN=1; Read
Output from R1 to DATAOUT
• SOUT=0; WriteWait
• SOUT=1; Write

SIN=1 DATAIN R1 DATAOUT SOUT=1

KEYBOARD PROCESSOR MONITOR

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

• Contents of keyboard character buffer DATAIN can be transferred to register


R1 in the processor by instruction

MoveByte DATAIN,R1
INSTATUS
• From R1 to DATAOUT
b1 b2 b3 b4 b5
MoveByte R1, DATAOUT
SIN
• Testbit #3,INSTATUS

Testbit instruction tests the state of one bit in the destination location, where
bit position to be tested is indicated by the first operand

Let us assume that bit b3 in registers INSTATUS and OUTSTATUS


corresponds to SIN and SOUT, respectively
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
BANGALORE INSTITUTE OF TECHNOLOGY

 The read operation may be implemented by the machine instruction


sequence
• SIN = 0; Wait
READWAIT Testbit #3, INSTATUS • SIN=1; Read
Branch=0 READWAIT
MoveByte DATAIN, R1 • SOUT=0; Wait
• SOUT=1; Write
 The write operation may be implemented as

WRITEWAIT Testbit #3, OUTSTATUS


Branch=0 WRITEWAIT
MoveByte R1,DATAOUT

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

CR  Carriage return; A control character


used to reset device’s position to the
beginning of a line of text

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Assumption – the initial state of SIN is 0 and the


initial state of SOUT is 1.
 Any drawback of this mechanism in terms of

efficiency?
 Two wait loops→processor execution time is
wasted
 Alternate solution?
 Interrupt

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Stacks and Queues

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Stacks
 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.
⚫ One end is called the top of the stack, and the other end is called the
bottom.
 The structure is sometimes referred to as a pushdown stack.
 Last-In-First-Out (LIFO) stack - the last data item placed on the stack is the
first one removed when retrieval begins.
 The terms push and pop are used to describe placing a new item on the
stack and removing the top item from the stack, respectively.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

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

 Stack pointer (SP) - A register used to keep track of the address of


the element of the stack that is at the top at any given time.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Assuming 32-bit word length, the PUSH operation will


decrement the stack pointer by 4 and copies the source into
the stack.
 Can be implemented as  SP

1500
Subtract #4,SP
Move NEWITEM,(SP)
 Or using autodecrement mode as STACK

Move NEWITEM,-(SP)

2000

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Assuming 32-bit word length, the POP operation will copy the
content from the stack to the destination and increment the stack
pointer by 4.
 SP
 Can be implemented as
Move (SP),ITEM
Add #4,SP STACK

 Or using autoincrement mode as


Move (SP)+,ITEM 2000

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 Stack is usually allocated a fixed amount of space in the


memory.
 We must avoid pushing an item on a full stack and popping
an item from an empty stack.
⚫ Could result from a programming error.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

1500

STACK

2000

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

⚫ The Compare instruction


Compare src,dst performs
the operation
[dst] -
[src]
and sets the condition code flags according to the result.
⚫ It does not change the value of either operand.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Queues
 A queue is a list of data elements that works on first-in-first-
out (FIFO) basis.
 Data are stored in and retrieved from a queue on a first-in-
first-out (FIFO) basis.
 If we assume that the queue grows in the direction of increasing
addresses in the memory, new data are added at the back (high-
address end) and retrieved from the front (low-address end) of
the queue.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Differences between Stacks


a nd Queues
Stacks Queues
One end of the stack is Both ends of a queue move
fixed (the bottom), while the to higher addresses as
other end rises and falls as data are added at the back
data are pushed and and removed from the
popped. front.
A single pointer is needed Two pointers are needed to
to point to the top of the keep track of the two ends
stack at any given time. of the queue.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

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.
 For example, a subroutine may evaluate the sine function or sort a list of
values into increasing or decreasing order.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 To save space, only one copy of the instructions of the subroutine is placed
in the 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 named a Call
instruction.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

 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 by
executing a Return instruction.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Parameter Passing
 Parameter passing - The exchange of information
between a calling program and a subroutine.
 When calling a subroutine, a program must provide to the

subroutine the parameters, that is, the operands or their


addresses, to be used in the computation.
 Later, the subroutine returns other parameters, in this

case, the results of the computation.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BANGALORE INSTITUTE OF TECHNOLOGY

Parameter Passing..
⚫ Figure 2.25 shows how the program in Figure
2.16 for adding a list of numbers can be implemented
as a subroutine, with the parameters passed through
registers.
 The size of the list, n, contained in memory location N, and
the address, NUM1, of the first number, are passed through
registers R1 and R2.
 The sum computed by the subroutine is passed back to the
calling program through register R0.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

You might also like