COA Mod2
COA Mod2
Definition:-
the way in which operand is specified in instruction
is called addressing mode.
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
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
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.
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