0% found this document useful (0 votes)
1 views25 pages

Module 2

The document covers various addressing modes in computer organization, including Register Mode, Absolute Mode, Immediate Mode, Indirect Mode, and Indexing. It also discusses assembly language syntax, assembler directives, and basic input/output operations, as well as data structures like stacks and queues. Additionally, it explains memory-mapped I/O and the operations associated with stacks, such as push and pop.

Uploaded by

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

Module 2

The document covers various addressing modes in computer organization, including Register Mode, Absolute Mode, Immediate Mode, Indirect Mode, and Indexing. It also discusses assembly language syntax, assembler directives, and basic input/output operations, as well as data structures like stacks and queues. Additionally, it explains memory-mapped I/O and the operations associated with stacks, such as push and pop.

Uploaded by

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

COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

MODULE 2

2.1 ADDRESSING MODES


• The different ways in which the location of an operand is specified in an instruction are
referred toas
Addressing Modes (Table 2.1).

.IN
C
N
SY
U

IMPLEMENTATION OF VARIABLE AND CONSTANTS


• A variable is represented by allocating a memory-location to hold itsvalue.
VT

• Thus, the value can be changed as needed using appropriateinstructions.


• There are 2 accessing modes to access thevariables:
1) RegisterMode
2) AbsoluteMode

1. Register Mode
• The operand is the contents of aregister.
• The name (or address) of the register is given in theinstruction.
• Registers are used as temporary storage locations where the data in a register
areaccessed.
• For example, theinstruction
MoveR1,R2 ;Copy content of register R1 into register R2

2. Absolute (Direct) Mode

Dept. of ECE, ATMECE, Mysuru Page 1


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

• The operand is in amemory-location.


• The address of memory-location is given explicitly in theinstruction.
• The absolute mode can represent global variables in theprogram.
• For example, theinstruction
MoveLOC,R2 ;Copy content of memory-location LOC into
registerR2.

3. Immediate Mode
• The operand is given explicitly in theinstruction.
• For example, theinstruction
Move#200,R0 ;Place the value 200 in registerR0.
• Clearly, the immediate mode is only used to specify the value of asource-operand.

4. INDIRECTION AND POINTERS


• Instruction does not give the operand or its addressexplicitly.

.IN
• Instead, the instruction provides information from which the new address of the
operand can be determined.
• This address is called Effective Address (EA) of theoperand.
C
Indirect Mode
• The EA of the operand is the contents of a register(ormemory-location).
N
• The register (or memory-location) that contains the address of an operand is called
aPointer.
SY

• We denote the indirectionby


→ name of the register or
→ new address given in the instruction.
U

E.g: Add (R1),R0;The operand is in memory. Register R1 gives the effective-


address (B) of the operand. The data is read from location B
VT

and added to contents of registerR0.

Dept. of ECE, ATMECE, Mysuru Page 2


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

• To execute the Add instruction in fig 2.11 (a), the processor uses the value which is
in register R1, as the EA of theoperand.
• It requests a read operation from the memory to read the contents of location B.
The value read is the desired operand, which the processor adds to the contents of
registerR0.
• Indirect addressing through a memory-location is also possible as shown in fig
2.11(b). In this case, the processor first reads the contents of memory-location A,
then requests a second read operation using the value B as an address to obtain
theoperand.

Program Explanation
.IN
C
• In above program, Register R2 is used as a pointer to the numbers in the list, and
the operands are accessed indirectly throughR2.
N
• The initialization-section of the program loads the counter-value n from memory-
location N into R1 and uses the immediate addressing-mode to place the address
SY

value NUM1, which is the address of the first number in the list, into R2. Then it
clears R0 to0.
• ThefirsttwoinstructionsintheloopimplementtheunspecifiedinstructionblockstartingatLOO
U

P.
• The first time through the loop, the instruction Add (R2), R0 fetches the operand at
VT

location NUM1 and adds it to R0.


• The second Add instruction adds 4 to the contents of the pointer R2, so that it will
contain the address value NUM2 when the above instruction is executed in the second
pass through theloop.

5. INDEXING AND ARRAYS


• A different kind of flexibility for accessing operands is useful in dealing with lists
andarrays.
Index mode
• The operation is indicated asX(Ri)
where X=the constant value which defines an offset(also called a
displacement).
Ri=the name of the index register which contains address of a new
location.
Dept. of ECE, ATMECE, Mysuru Page 3
COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

• The effective-address of the operand is given by EA=X+[Ri]


• The contents of the index-register are not changed in the process of generating the
effective- address.
• The constant X may be giveneither
→ as an explicit number or
→ as a symbolic-name representing a numerical value.

.IN
• Fig(a) illustrates two ways of using the Index mode. In fig(a), the index register,
R1, contains the address of a memory-location, and the value X defines an offset(also
C
called a displacement) from this address to the location where the operand isfound.
• To find EA of
N
operand: Eg:
Add 20(R1),R2
SY

EA=>1000+20=1020
• An alternative use is illustrated in fig(b). Here, the constant X corresponds to a
memory address, and the contents of the index register define the offset to the
U

operand. In either case, the effective-address is the sum of two values; one is given
explicitly in the instruction, and the other is stored in aregister.
VT

Dept. of ECE, ATMECE, Mysuru Page 4


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

Base with Index Mode


• Another version of the Index mode uses 2 registers which can
be denotedas (Ri,Rj)
• Here, a second register may be used to contain the offsetX.
• The second register is usually called the baseregister.
• The effective-address of the operand is given byEA=[Ri]+[Rj]
• This form of indexed addressing provides more flexibility in accessing
operands because both components of the effective-address can
bechanged.
Base with Index & Offset Mode
• Another version of the Index mode uses 2 registers plus a constant, which
can be denoted as X(Ri,Rj)
• The effective-address of the operand is given byEA=X+[Ri]+[Rj]
• This added flexibility is useful in accessing multiple components inside each item in
a record, where the beginning of an item is specified by the (Ri, Rj) part of the

.IN
addressing-mode. In other words, this mode implements a 3-dimensionalarray.

6. RELATIVE MODE
• This is similar to index-mode with onedifference:
C
The effective-address is determined using the PC in place of the general
purpose register Ri.
N
• The operation is indicated asX(PC).
SY

• X(PC) denotes an effective-address of the operand which is X locations above or


below the current contents ofPC.
• Since the addressed-location is identified "relative" to the PC, the name Relative
mode is associated with this type ofaddressing.
U

• This mode is used commonly in conditional branchinstructions.


• An instruction suchas
VT

Branch >0 LOOP ;Causes program execution to go to the


branchtargetlocationidentified by name LOOP if
branch condition issatisfied.

7. ADDITIONAL ADDRESSING MODES


1) Auto IncrementMode
 Effective-address of operand is contents of a register specified in the instruction
(Fig:2.16).
 After accessing the operand, the contents of this register are automatically
incremented to point to the next item in alist.
 Implicitly, the increment amount is1.
 This mode is denotedas
(Ri)+ ;whereRi=pointer-register.

Dept. of ECE, ATMECE, Mysuru Page 5


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

2) Auto DecrementMode
 The contents of a register specified in the instruction are first automatically
decremented and are then used as the effective-address of theoperand.
 This mode is denotedas
-(Ri) ;whereRi=pointer-register.
 These 2 modes can be used together to implement an important data structure
called astack.

2.2. ASSEMBLY LANGUAGE


.IN
C
• We generally use symbolic-names to write aprogram.
• A complete set of symbolic-names and rules for their use constitute an
N
AssemblyLanguage.
• The set of rules for using the mnemonics in the specification of complete instructions
SY

and programs is called the Syntax of thelanguage.


• Programs written in an assembly language can be automatically translated into a
sequence of machine instructions by a program called anAssembler.
U

• The user program in its original alphanumeric text formal is called a Source
Program, and the assembled machine language program is called an
VT

ObjectProgram.
For example:
MOVE R0,SUM;The term MOVE represents OP code for operation performed
by instruction.
ADD#5,R3 ;Adds number 5 to contents of register R3 & puts the result back
intoregisterR3.

ASSEMBLER DIRECTIVES
• Directives are the assembler commands to the assembler concerning the program
beingassembled.
• These commands are not translated into machine opcode in theobject-program.

Dept. of ECE, ATMECE, Mysuru Page 6


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

• EQU informs the assembler about the value of an identifier (Figure:2.18).

.IN
Ex: SUM EQU 200 ;Informs assembler that the name SUM should be replaced by
the value 200.
• ORIGIN tells the assembler about the starting-address of memory-area to place the
C
datablock.
Ex: ORIGIN 204 ;Instructs assembler to initiate data-block at memory-locations
N
starting from 204.
• DATAWORD directive tells the assembler to load a value into thelocation.
SY

Ex: N DATAWORD 100 ;Informs the assembler to load data 100 into the memory-
location N(204).
• RESERVE directive is used to reserve a block ofmemory.
Ex: NUM1 RESERVE 400 ;declares a memory-block of 400 bytes is to be reserved
U

for data.
VT

• END directive tells the assembler that this is the end of the source-programtext.
• RETURN directive identifies the point at which execution of the program should
beterminated.
• Anystatementthatmakesinstructionsordatabeingplacedinamemory-
locationmaybegivena
label. The label(say N or NUM1) is assigned a value equal to the address of
that location.

GENERAL FORMAT OF A STATEMENT


• Most assembly languages require statements in a source program to be written in
theform:
Label Operation Operands Comment

1) Label is an optional name associated with the memory-address where the

Dept. of ECE, ATMECE, Mysuru Page 7


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

machine language instruction produced from the statement will beloaded.


2) Operation Field contains the OP-code mnemonic of the desired instruction
orassembler.
3) Operand Field contains addressing information for accessing one or more
operands, depending on the type ofinstruction.
4) Comment Field is used for documentation purposes to make program easier
tounderstand.
ASSEMBLY AND EXECUTION OF PRGRAMS
• Programs written in an assembly language are automatically translated into a
sequence of machine instructions by theAssembler.
• AssemblerProgram
→ replaces all symbols denoting operations & addressing-modes with
binary-codes used in machine instructions.
→ replaces all names and labels with their actual values.
→ assigns addresses to instructions & data blocks, starting at address given in
ORIGIN directive

.IN
→ inserts constants that may be given in DATAWORD directives.
→ reserves memory-space as requested by RESERVE directives.
• Two Pass Assembler has 2passes:
C
1. First Pass: Work out all the addresses oflabels.
 As the assembler scans through a source-program, it keeps track of all names
N
of numerical- values that correspond to them in asymbol-table.
2. Second Pass: Generate machine code, substituting values for thelabels.
SY

 When a name appears a second time in the source-program, it is replaced


with its value from thetable.
• The assembler stores the object-program on a magnetic-disk. The object-program
U

must be loaded into the memory of the computer before it is executed. For this, a
Loader Program isused.
VT

• Debugger Program is used to help the user find the programmingerrors.


• Debugger program enables theuser
→ to stop execution of the object-program at some points of
interest &
→ to examine the contents of various processor-registers and
memory-location.

2.3. BASIC INPUT/OUTPUT OPERATIONS


• Consider the problem of moving a character-code from the keyboard to the
processor (Figure:2.19). For this transfer, buffer-register DATAIN & a status
control flags(SIN) areused.
• When a key is pressed, the corresponding ASCII code is stored in a DATAIN
register associated with thekeyboard.

Dept. of ECE, ATMECE, Mysuru Page 8


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

 SIN=1 When a character is typed in the keyboard. This informs the


processor that a valid character is inDATAIN.
 SIN=0 When the character is transferred to theprocessor.
• An analogous process takes place when characters are transferred from the
processor to thedisplay. For this transfer, buffer-register DATAOUT & a status
control flag SOUT areused.
 SOUT=1 When the display is ready to receive acharacter.
 SOUT=0 When the character is being transferred toDATAOUT.
• The buffer registers DATAIN and DATAOUT and the status flags SIN and SOUT are
part of circuitry commonly known as a deviceinterface.

.IN
C
N
SY
U
VT

MEMORY-MAPPED I/O
• Some address values are used to refer to peripheral device buffer-registers such as
DATAIN & 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 orStore.
• For example, contents of the keyboard character buffer DATAIN can be transferred
to register R1 in the processor by theinstruction
Dept. of ECE, ATMECE, Mysuru Page 9
COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

MoveByte DATAIN,R1
• The MoveByte operation code signifies that the operand size is abyte.
• The Testbitinstruction tests the state of one bit in the destination, where the bit
position to be tested is indicated by the firstoperand.

2.4 STACKS & QUEUES


STACK
• A stack is a special type of data structure where elements are inserted from one
end and elements are deleted from the same end. This end is called the top of the
stack (Figure:2.14).
• The various operations performed onstack:
1) Insert: An element is inserted from top end. Insertion operation is called
pushoperation.
2) Delete: An element is deleted from top end. Deletion operation is called
popoperation.

.IN
• 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).
• If we assume a byte-addressable memory with a 32-bit wordlength,
C
1) The push operation can be implementedas
Subtract #4, SP
N
Move NEWITEM,(SP)
2) The pop operation can be implementedas
SY

Move (SP),
ITEM Add #4, SP
• Routine for a safe pop and push operation
U
VT

Dept. of ECE, ATMECE, Mysuru Page 10


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

.IN
C
N
SY
U
VT

asfollows:

Dept. of ECE, ATMECE, Mysuru Page 11


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

QUEUE
• Data are stored in and retrieved from a queue on a FIFObasis.
• Difference between stack andqueue?
1) One end of the stack is fixed while the other end rises and falls as data are
pushed and popped.
2) In stack, a single pointer is needed to keep track of top of the stack at any
giventime.
In queue, two pointers are needed to keep track of both the front and end
for removal and insertion respectively.
3) 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 circularbuffer.

2.5. SUBROUTINES
• A subtask consisting of a set of instructions which is executed many times is called

.IN
aSubroutine.
• A Call instruction causes a branch to the subroutine (Figure:2.16).
• At the end of the subroutine, a return instruction isexecuted
C
• Program resumes execution at the instruction immediately following the subroutinecall
• The way in which a computer makes it possible to call and return from subroutines
N
is referred to as its Subroutine Linkagemethod.
• The simplest subroutine linkage method is to save the return-address in a specific
SY

location, which may be a register dedicated to this function. Such a register is called
the LinkRegister.
• When the subroutine completes its task, the Return instruction returns to the
U

calling-program by branching indirectly through thelink-register.


• The Call Instruction is a special branch instruction that performs the
VT

followingoperations:
→ 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 theoperation:
→ Branch to the address contained in the link-register.

Dept. of ECE, ATMECE, Mysuru Page 12


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

.IN
C
SUBROUTINE NESTING AND THE PROCESSOR STACK
N
• Subroutine Nesting means one subroutine calls anothersubroutine.
• In this case, the return-address of the second call is also stored in the link-register,
SY

destroying its previouscontents.


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

subroutine will belost.


• Subroutine nesting can be carried out to any depth. Eventually, the last subroutine
VT

called completes its computations and returns to the subroutine that calledit.
• 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
LIFOorder.
• 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 thisoperation.
• SP is used to point to theprocessor-stack.
• Call instruction pushes the contents of the PC onto theprocessor-stack.
Return instruction pops the return-address from the processor-stack into
the PC

Dept. of ECE, ATMECE, Mysuru Page 13


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

PARAMETER PASSING
• The exchange of information between a calling-program and a subroutine is
referred to as
Parameter Passing (Figure: 2.25).
• The parameters may be placed in registers or in memory-location, where they can
be accessed by thesubroutine.
• Alternatively, parameters may be placed on the processor-stack used for saving
thereturn-address.
• Following is a program for adding a list of numbers using subroutine with the
parameters passed throughregisters.

.IN
C
N
SY

STACK FRAME
U

• Stack Frame refers to locations that constitute a private work-space for


thesubroutine.
VT

• The work-spaceis
→ created at the time the subroutine is entered &
→ freed up when the subroutine returns control to the calling-program
(Figure: 2.26).

Dept. of ECE, ATMECE, Mysuru Page 14


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

Program for adding a list of numbers using subroutine with the parameters passed to
stack.

.IN
C
N
SY
U
VT

Dept. of ECE, ATMECE, Mysuru Page 15


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

• Fig: 2.27 show an example of a commonly used layout for information in astack-
frame.
• Frame Pointer (FP) is used to access the parameterspassed
→ to the subroutine &
→ to the local memory-variables.
• The contents of FP remains fixed throughout the execution of the subroutine, unlike
stack-pointer SP, which must always point to the current top element in thestack.
Operation on Stack Frame
• Initially SP is pointing to the address ofold TOS.
• The calling-program saves 4 parameters on the stack (Figure2.27).
• The Call instruction is now executed, pushing the return-address onto thestack.
• Now, SP points to this return-address, and the first instruction of the subroutine
isexecuted.
• Now, FP is to be initialized and its old contents have to be stored. Hence, the first 2
instructions in the subroutineare:

.IN
Move FP,-(SP)
Move SP,FP
• The FP is initialized to the value of SP i.e. both FP and SP point to the saved
C
FPaddress.
• The 3 local variables may now be pushed onto the stack. Space for local variables is
N
allocated by executing theinstruction
Subtract #12,SP
SY

• Finally, the contents of processor-registers R0 and R1 are saved in the stack. At this
point, the stack- frame has been set up as shown in the fig2.27.
• The subroutine now executes its task. When the task is completed, the subroutine
U

pops the saved values of R1 and R0 back into those registers, removes the local
variables from the stack frame by executing theinstruction.
VT

Add #12, SP
• And subroutine pops saved old value of FP back into FP. At this point, SP points to
return-address, so the Return instruction can be executed, transferring control back
to thecalling-program.

Dept. of ECE, ATMECE, Mysuru Page 16


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

STACK FRAMES FOR NESTED SUBROUTINES


• Stack is very useful data structure for holding return-addresses when subroutines
arenested.
• When nested subroutines are used; the stack-frames are built up in theprocessor-

stack.
Program to illustrate stack frames for nested subroutines

.IN
C
N
SY
U
VT

The Flow of Execution is as follows:


• Main program pushes the 2 parameters param2 and param1 onto the stack and then

Dept. of ECE, ATMECE, Mysuru Page 17


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

callsSUB1.
• SUB1 has to perform an operation & send result to the main-program on the stack
(Fig:2.28&29).
• During the process, SUB1 calls the second subroutine SUB2 (in order to perform
somesubtask).
• After SUB2 executes its Return instruction; the result is stored in register R2 bySUB1.
• SUB1thencontinuesitscomputations&eventuallypassesrequiredanswerbacktomain-
programonthestack.
• When SUB1 executes return statement, the main-program stores this answers in
memory-location RESULT and continues itsexecution.

2.6 ADDITIONAL INSTRUCTIONS

LOGIC INSTRUCTIONS

.IN
• Logic operations such as AND, OR, and NOT applied to individualbits.
• These are the basic building blocks ofdigital-circuits.
• This is also useful to be able to perform logic operations is software, which is done
C
using instructions that apply these operations to all bits of a word or byte
independently and inparallel.
N
• For example, theinstruction
Not dst
SY

SHIFT AND ROTATE INSTRUCTIONS


• There are many applications that require the bits of an operand to be shifted right
U

or left some specified number of bitpositions.


• The details of how the shifts are performed depend on whether the operand is a
VT

signed number or some more general binary-codedinformation.


• For general operands, we use a logicalshift.
For a number, we use an arithmetic shift, which preserves the sign of
the number.
LOGICAL SHIFTS
• Two logical shift instructionsare
1) Shifting left (LShiftL)&
2) Shifting right(LShiftR).
• These instructions shift an operand over a number of bit positions specified in a count
operand contained in theinstruction.

Dept. of ECE, ATMECE, Mysuru Page 18


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

ROTATE OPERATIONS
.IN
• In shift operations, the bits shifted out of the operand are lost, except for the last
C
bit shifted out which is retained in the Carry-flagC.
N
• To preserve all bits, a set of rotate instructions can beused.
• They move the bits that are shifted out of one end of the operand back into the
SY

otherend.
• Two versions of both the left and right rotate instructions are
usually provided. In one version, the bits of the operand is
simplyrotated.
U

In the other version, the rotation includes the C flag.


VT

Dept. of ECE, ATMECE, Mysuru Page 19


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

.IN
C
ENCODING OF MACHINE INSTRUCTIONS
• To be executed in a processor, an instruction must be encoded in a binary-pattern.
N
Such encoded instructions are referred to as MachineInstructions.
• The instructions that use symbolic-names and acronyms are called assembly
SY

languageinstructions.
• We have seen instructions that perform operations such as add, subtract, move,
shift, rotate, and branch. These instructions may use operands of different sizes, such
U

as 32-bit and 8-bitnumbers.


• Let us examine some typical
VT

cases. Theinstruction
Add R1, R2 ;Has to specify the registers R1 and R2, in addition to the OP code.
If the processor has 16 registers, then four bits are needed to
identify each register. Additional bits are needed to indicate that the
Register addressing-mode is used for eachoperand.
The instruction
Move24(R0),R5 ;Requires 16 bits to denote the OP code and the
tworegisters,andsome bits to express that the source
operand uses the Index addressing mode and that the
index value is24.
• In all these examples, the instructions can be encoded in a 32-bit word (Fig2.39).
• The OP code for given instruction refers to type of operation that is to beperformed.
• Source and destination field refers to source and destination operandrespectively.

Dept. of ECE, ATMECE, Mysuru Page 20


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

• The "Other info" field allows us to specify the additional information that may be
needed such as an index value or an immediateoperand.
• Using multiple words, we can implement complex instructions, closely resembling
operations in high- level programming languages. The term complex instruction set
computers (CISC) refers to processors thatuse
• CISC approach results in instructions of variable length, dependent on the number
of operands and the type of addressing modesused.
• In RISC (reduced instruction set computers), any instruction occupies only oneword.
• The RISC approach introduced other restrictions such as that all manipulation of
data must be done on operands that are already inregisters.
Ex: Add R1,R2,R3
• In RISC type machine, the memory references are limited to only
Load/Storeoperations.

.IN
C
N
SY
U
VT

Problem 1:
Write a program that can evaluate the expression A*B+C*D In a single-accumulator
processor. Assume that the processor has Load, Store, Multiply, and Add instructions
and that all values fit in the accumulator
Solution:
A program for the
expression is:
Load A
Multiply B
Store RESULT
Load C
Multiply D
Add RESULT

Dept. of ECE, ATMECE, Mysuru Page 21


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

Store RESULT

.IN
C
N
SY
U
VT

Dept. of ECE, ATMECE, Mysuru Page 22


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C

Problem 2:
Registers R1 and R2 of a computer contains the decimal values 1200 and 4600. What
is the effective- address of the memory operand in each of the following instructions?
(a) Load 20(R1),R5
(b) Move#3000,R5
(c) StoreR5,30(R1,R2)
(d) Add-(R2),R5
(e) Subtract(R1)+,R5
Solution:
(a) EA = [R1]+Offset=1200+20 = 1220
(b) EA = 3000
(c) EA = [R1]+[R2]+Offset =
1200+4600+30=5830 (d) EA = [R2]-1 =
4599
(e) EA = [R1] = 1200

.IN
Problem 3:
Registers R1 and R2 of a computer contains the decimal values 2900 and 3300. What
is the effective- address of the memory operand in each of the following instructions?
C
(a) Load
N
R1,55(R2) (b )
Move #2000,R7
SY

(c) Store95(R1,R2),R5
(d) Add(R1)+,R5
(e) Subtract‐(R2),R5
Solution:
U

a) Load R1,55(R2) This is indexed addressing mode. So EA


VT

=55+R2=55+3300=3355.
b) Move #2000,R7This is an immediate addressing mode. So, EA =2000
c) Store 95(R1,R2),R5 This is a variation of indexed addressing mode, in
which contents of 2 registers are added with the offset or index to generate EA.
So, 95+R1+R2=95+2900+3300=6255.
d) Add (R1)+,R5 This is Autoincrement mode. Contents of R1 are the EA so,
2900 is theEA.
e) Subtract -(R2),R5 This is Auto decrement mode. Here, R2 is subtracted by
4 bytes (assuming 32‐bt processor) to generate the EA, so, EA=3300‐4=3296.

Problem 5:
Both of the following statements cause the value 300 to be stored in location 1000,
but at different times.

Dept. of ECE, ATMECE, Mysuru Page 23


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C
ORIGIN 1000
DATAWORD 300
And

Move #300,1000

Explain the difference.


Solution:
The assembler directives ORIGIN and DATAWORD cause the object
program memory image constructed by the assembler to indicate
that 300 is to be placed at memory word location 1000 at the time
the program is loaded into memory prior to execution.
The Move instruction places 300 into memory word location 1000

.IN
when the instruction is executed as part of a program.

Problem 6:

C
Register R5 is used in a program to point to the top of a stack. Write a
sequence of instructions using the Index, Auto increment, and Auto
N
decrement addressing modes to perform each of the following tasks:
(a) Pop the top two items off the stack, and them, and then push the result
SY

onto thestack.
(b) Copy the fifth item from the top into registerR3.
(c) Remove the top ten items from thestack.
U

Solution:
VT

(a) Move(R5)+,R0
Add (R5)+, R0
Move R0, -(R5)
(b) Move 16(R5),R3
(c) Add #40,R5

Problem 7:
Consider the following possibilities for saving the return address of a
subroutine:
(a) In the processorregister.
(b) In a memory-location associated with the call, so that a different
location is used when the subroutine is called from differentplaces
(c) On astack.
Which of these possibilities supports subroutine nesting and which
supports subroutine recursion(that is, a subroutine that calls itself)?

Dept. of ECE, ATMECE, Mysuru Page 24


COMPUTER ORGANIZATION AND ARCHITECTURE BEC306C
Solution:
(a) Neither nesting nor recursion issupported.
(b) Nesting is supported, because different Call instructions will
save the return address at different memory-locations. Recursion is
notsupported.
(c) Both nesting and recursion are supported.

.IN
C
N
SY
U
VT

Dept. of ECE, ATMECE, Mysuru Page 25

You might also like