0% found this document useful (0 votes)
33 views

COA Mod2

The document discusses different addressing modes used in computer instructions. It describes the following addressing modes: 1. Immediate - The operand value is specified explicitly in the instruction. 2. Register - The operand is in a processor register. 3. Absolute/Direct - The operand is in a specific memory location given by its address in the instruction. 4. Indirect - The operand address is contained in a register or memory location. 5. Indexed - The operand address is the sum of a register and constant offset value. 6. Relative - The operand address is the sum of the program counter and a constant offset. 7. Auto-increment and auto-decrement

Uploaded by

Boban Mathews
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

COA Mod2

The document discusses different addressing modes used in computer instructions. It describes the following addressing modes: 1. Immediate - The operand value is specified explicitly in the instruction. 2. Register - The operand is in a processor register. 3. Absolute/Direct - The operand is in a specific memory location given by its address in the instruction. 4. Indirect - The operand address is contained in a register or memory location. 5. Indexed - The operand address is the sum of a register and constant offset value. 6. Relative - The operand address is the sum of the program counter and a constant offset. 7. Auto-increment and auto-decrement

Uploaded by

Boban Mathews
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Addressing modes

Definition:-
the way in which operand is specified in instruction
is called addressing mode.

Types of addressing modes


•Implementation of variables and constants
•Indirection and pointer
•Indexing and array
•Relative addressing
•Additional modes
ADDRESSING MODES
 The instruction set of a computer typically
provides a number of such method, called
addressing modes.
 Types of addressing modes:-
Name Assembler syntax Addressing function
Immediate # value Operand=value
Register Ri EA=Ri
Absolute(Direct) LOC EA=LOC
Indirect (Ri) , (LOC) EA=[Ri] ,EA=[LOC]
Index X(Ri) EA=[Ri]+X
Base with Index (Ri,Rj) EA=[Ri]+[Rj]
Base with Index and X(Ri,Rj) EA=[Ri]+[Rj]+X
offset
Relative X(PC) EA=[PC]+X
Auto increment (Ri+) EA=[Ri] ;Increment Ri
Auto decrement -(Ri) Decrement Ri
EA=[Ri];
IMPLEMENTATION OF VARIABLES AND
CONSTATNTS
 A variable is represented by allocating a register or
a memory location to hold its value.
 Two addressing modes to access variables:-
1) Register mode:-The operand is the contents of a
processor register .
 Operand is held in register named in address file
EA = R
 Limited number of registers
 Very small address field needed
 Shorter instructions
 Faster instruction fetch
 Move LOC,R1
Absolute(Direct) addressing mode
•The operand is in a memory location.
• The address of this location is given
explicitly in the instruction .
•It is also called Direct mode.
•Declaration such as
Integer A,B
 Here compiler allocates the address the
variables A and B
 Above instruction is an example for both
Addressing modes.
 Address and data constants can be represented in
assembly level language using Immediate mode
 Immediate mode:- The operand is given explicitly
in the instruction.
 Example – Move 200 immediate, R0
 The common convention is to be used the sharp
sign(#) in front of the value of the use as in
immediate operand.
 Move #200, R0
 Ex.: A=B+6
Move B,R1
Add #6,R1
Move R1,A
INDIRECTION AND POINTERS

 The register or memory location that contains the


address of an operand is called a pointer.
 Indirection is the ability to reference something
using a name, reference, or container instead of
the value itself.
 The most common form of indirection is the act
of manipulating a value through its memory
address.
 For example, accessing a variable through the
use of a pointer.
 Indirection and use of pointers are important and
powerful concepts in programming.
Indirect mode:-
 The effective address of the operand is the
contents of register or memory location
whose address appears in the instruction.
 Memory cell pointed to by address field
contains the address of (pointer to) the
operand.
e.g. ADD (A)
 Add contents of cell pointed to by contents
of A to accumulator
Add (R2),R1
Indirect mode:-

 The effective address of the operand is


the contents of register or memory
location whose address appears in the
instruction.
 Memory cell pointed to by address field
contains the address of (pointer to) the
operand.
 e.g. ADD (A)
 Add contents of cell pointed to by
contents of A to accumulator
 • Add (R2),R1
INDEXING and ARRAYS
 Indexing provide the different kind of
flexibility for accessing operands.
 It is useful in dealing with lists and array.
Index Mode:-
 The effective address of the operand is
generated by adding a constant value to
the contents of a register.
 The register used may be special register
provided for this purpose or general –
purpose register called index register.
 Symbolically represented as
 X(Ri)
 EA=X+[Ri]
 Where X denoted the constant value contained
in the instruction, and is a signed integer,
 And Ri is the name of the register involved.
 or (Ri,Rj) where Rj- Base Register
 Or X(Ri,Rj)
 Relative Mode:-
 The effective address is determined by the index
mode using the PC in the place of general
purpose register Ri.
 EA=X+PC
 or X(PC)
 This mode can be used to access the data
operands.
 Most common use is to specify the target
address in branch instruction.
 Branch>0 LOOP
Additional Modes
 Auto increment mode:- (Ri)+
 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.

 Auto Decrement mode:- -(Ri)


 The contents of a register specified in the instruction are
first automatically decremented.
 After that used as the effective address of the operand.
Assembly Language
 Machine understands 0’s and 1’s pattern, but
programs can’t be written using same format.
 Hence symbolic names such as Move, Add,
Increment, Branch etc., for are used to represent
each binary pattern.
 Ex.: ADD -- 1101
 When writing programs for specific computer a short
acronym is used called Mnemonic.
 Ex.: MOV,ADD,INC,BR etc.,
 Similarly to reference registers Rx notation is used.
Ex.: R3. and
 Memory locations are represented using Labels LOC.
 A complete set of symbolic names and rules for their
use constitutes a programming language.
 .
 Set of rules for mnemonics in the instructions,
programs is called Syntax
 Assembler translates assembly language to
machine language
 Assembler is a program like other programs
stored in memory.
 User entered programs through keyboard is
stored in memory or Magnetic disks.
 When assembler program is executed, it reads
the user program analyzes and generated
desired machine code
 The user program is Source program
 The assembled program is Object Program.
 Assembly language may or may not case
sensitive
Syntax of Assembly instruction
 Mnemonic - OP code(Operational code)
 Operands
 Label Mnemonic Source Operand, Destination Operand Comment

 Ex.: MOVE R0,SUM


 ADD #5,R3
 ADDI 5,R3
 MOVE #5,(R2)
 MOVEI 5,(R2)
Assembler Directives
 Instructions given to Assembler
 Does not store like instructions in
memory
 Commands used by Assembler while
translating source program to object
program.
 Ex.: LIST EQU 1000h
 SUM EQU 200
Memory arrangement for the Program
Assembly Program
Number Notations
 BCD representation
 ADD #93,R1

 Binary Representation
 ADD #%01011101,R1

 Hexadecimal Representation
 ADD #$5D,R1
BASIC INPUT/OUTPUT OPERATIONS
 Consider the problem of moving a character-code from the
keyboard to the processor
 For this transfer, buffer- register(DATAIN) & a status control
flags(SIN) are used
 Striking a key stores the corresponding character-code in an 8-
bit buffer-register (DATAIN) associated with the keyboard as
shown in Figure
 To inform the processor that a valid character is in DATAIN, SIN
is set to1
 A program monitors SIN, and when SIN is set to 1, the processor
reads the contents of DATAIN
 When the character is transferred to the processor, SIN is
automatically cleared to 0.
 If a second character is entered at the keyboard, SIN is again set
to 1 and the process repeats.
BASIC INPUT/OUTPUT OPERATIONS
 An analogous process takes place when characters are
transferred from the processor to the display. A buffer-register,
DATAOUT, and a status control flag, SOUT are used for this
transfer.
 When SOUT=1, the display is ready to receive a character.
 The transfer of a character to DATAOUT clears SOUT to 0.
 The buffer registers DATAIN and DATAOUT and the status flags
SIN and SOUT are part of circuitry commonly known as a device
interface.
BASIC INPUT/OUTPUT OPERATIONS
 Following is a program to read a line of characters and
display it
MEMORY-MAPPED I/O
 Memory address values are used to refer to
peripheral device buffer-registers such as DATAIN
and DATAOUT.
 No special instructions are needed to access the
contents of the registers; data can be transferred
between these registers and the processor using
instructions such as Move, Load or Store.
 For example, contents of the keyboard character
buffer DATAIN can be transferred to register R1 in
the processor by the instruction
MoveByte DATAIN,R1
 The MoveByte operation code signifies that the
operand size is a byte.
 The Testbit instruction tests the state of one bit in
the destination, where the bit position to be tested is
indicated by the first operand.
STACKS
 The control and information linkage between main
program and subprogram is done by stack
 A stack is a list of data elements 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 (Figure)
 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.
 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).
STACK
 If we assume a byte-addressable memory
with a 32-bit word length,
 The push operation can be implemented as
 Subtract #4,SP
 Move NEWITEM,(SP)
 The pop operation can be implemented as
 Move (SP),ITEM
 Add #4,SP
 Routine for a safe pop and push operation
as follows
Fig. illustrates stack of words in memory
STACKS
QUEUE
 Data are stored in and retrieved from a queue on a FIFO
basis.
 Difference between stack and queue?
 One end of the stack is fixed while the other end rises and
falls as data are pushed and popped.
 A single pointer is needed to point to the top of the stack at
any given time.
 On the other hand, both ends of a queue move to higher
addresses as data are added at the back and removed from
the front.
 So, two pointers are needed to keep track of the two does
of the queue.
 Without further control, a queue would continuously move
through the memory of a computer in the direction of
higher addresses.
 One way to limit the queue to a fixed region in memory is
to use a circular buffer.
SUBROUTINES
 A sub task consisting of a set of instructions
which is executed many times is called a
subroutine.
 The program branches to a subroutine with a
Call instruction.
 Once the subroutine is executed, the calling-
program must resume execution starting from
the instruction immediately following the Call
instructions i.e. control is to be transferred back
to the calling-program.
 This is done by executing a Return instruction
at the end of the subroutine.
 The way in which a computer makes it possible to
call and return from subroutines 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.
 When the subroutine completes its task, the Return
instruction returns to the calling- program by
branching indirectly through the link-register.
 The Call instruction is a special branch instruction
that performs the following operations:
→ Store the contents of PC into link-register.
→ Branch to the target-address specified by the
instruction.
 The Return instruction is a special branch
instruction that performs the operation:
→ Branch to the address contained in the link-
register.
Subroutine linkage using a link register
Calling Program Subroutine program
200 CALL SUB(2000) 2000 FIRST Instruction
204 NEXT Instruction .
.
Return

PC 204

Link Register 204

CALL RETURN
SUBROUTINE NESTING AND THE PROCESSOR STACK
 Subroutine nesting means one subroutine calls another
subroutine.
 In this case, the return-address 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.
 Subroutine nesting can be carried out to any depth. Eventually, the
last subroutine called completes its computations and returns to
the subroutine that called it.
 The return-address needed for this first return is the last one
generated in the nested call sequence. That is, return-addresses
are generated and used in a LIFO order.
 This suggests that the return-addresses associated with
subroutine calls should be pushed onto a stack.
 A particular register is designated as the SP(Stack Pointer) to be
used in this operation.
SUBROUTINE NESTING AND THE PROCESSOR STACK

 SP is used to point to the processor-stack.


 Call instruction pushes the contents of the PC onto
the processor-stack.
 Return instruction pops the return-address from the
processor-stack into the PC.
1.Re-entrant Subroutine

2.Recursive subroutine
PARAMETER PASSING
 The exchange of information between a calling-
program and a subroutine is referred to as
parameter passing.
 The parameters may be placed in
 In Registers
 In memory-location, where they can be accessed
by the subroutine.
 Alternatively, parameters may be placed on the
processor-stack used for saving the return-
address
 Following example programs illustrates these
parameter passing techniques.
Passing parameters using Registers

Main Program
Move N, R1
Move #num1,R2
Call LISTADD
Move R0,Sum



Subroutine
LISTADD clear R0
LOOP ADD (R2)+,R0
Decrement R1
Branch>0 LOOP
Return
Additional Instructions
 Logical Instructions:
 Logic operations such as AND, OR, and NOT
applied to individual bits.
 These are the basic building blocks of digital-circuits.
 This is also useful to be able to perform logic
operations in software, which is done using
instructions that apply these operations to all bits of
a word or byte independently and in parallel.
 For example, the instruction
Not dst ; Complements all the bits of destination operand
Not R0
Add #1,R0 ;gives 2’s complement of R0
or
Negate R0
Logical Instructions conti….
 AND #$FF000000,R0
Compare #$5A000000,R0
Branch=0 YES

 OR #$00000000,R0
Compare #$00000001,R0
branch=1 odd
SHIFT AND ROTATE INSTRUCTIONS
 There are many applications that require the
bits of an operand to be shifted right or left by
some specified number of bit positions.

 The details of how the shifts are performed


depend on whether the operand is a signed
number or some more general binary-coded
information.

 For general operands, we use a logical shift.


 For a signed number, we use an arithmetic
shift, which preserves the sign of the number.
Shift and Rotate Instructions conti….
LOGICAL SHIFTS
 Two logical shift instructions are needed, one for
shifting left(LShiftL) and another for shifting
right(LShiftR).
 These instructions shift an operand over a number of
bit positions specified in a count operand contained in
the instruction.
Logical Shifts and rotate instructions contd..

 Arithmetic Shift Right Ashift #2,R0


Example program for Digit Packing

Move #LOC,R0
Movebyte (R0)+,R1
LShiftL #4,R1
MoveByte (R0),R2
And #$F,R2
Or R1,R2
MoveByte R2,packed
Multiplication And Division:
 Two signed integers can be multiplied or divided by
machine instructions.
 The instruction,
Multiply Ri, Rj
Rj= [Ri]*[Rj] if product is n bits
Rj+1,Rj=[Ri]*[Rj] if product is 2n bits
 Signed integer divide instruction:
Division Ri, Rj
Does Rj=[Ri]/[Rj]
Rj=Quotient
Rj+1=Remainder
IEEE-754 standard for Floating-Point Numbers
 The 32 bit representation shown in Figure is called
Single Precision/excess-127 format

 Sign bit - 1bit


 Exponent - 8 bits = Signed Exponent + Bias(127)
 Exponent value ranges from -126 to +127
 Mantissa - 23 bits
Ex1:
 Represent 1259.12510 in single precision
Soln: First convert 1259 into binary format
(1259)10=(010011101011)2
Similarly( .125)10=(0.001)2
II. Normalize the number
i.e., 10011101011.001=1.00111011001x210
now S=0; E=10+127, and M=0011101011001
E=(137)10=(10001001)2
SE M
0 10001001 0011101011001000000000000000000
Double precision number representation

 The 64 bit representation shown in Figure is called


double Precision/excess-1023 format

 Sign bit - 1bit


 Exponent - 11 bits = Signed Exponent + 1023
 Exponent value ranges from -1022 to +1023
 Mantissa - 52 bits
Ex2:
 Represent 1259.12510 in double precision.
Soln.:
I. First convert 1259 into binary format
(1259)10=(010011101011)2
Similarly( .125)10=(0.001)2
II. Normalize the number
i.e., 10011101011.001=1.00111011001x210
now S=0; E=10+1023,and =(10000001001) 2
E=(1033)10=(10000001001)2
0 10000001001 0011101011001000000000…..000000000
SE M

You might also like