Name: Umar Ali Roll#: 522 Class#: 5 Semester Submitted To: Sir Farhatullah Week: 05 Subject: Microprocessor and Assembly Language
Name: Umar Ali Roll#: 522 Class#: 5 Semester Submitted To: Sir Farhatullah Week: 05 Subject: Microprocessor and Assembly Language
Roll# : 522
1) Immediate Mode:
2) Index Mode:
The address of the operand is obtained by adding to the contents of the general
register (called index register) a constant value. The number of the index register and
the constant value are included in the instruction code. Index Mode is used to access
an array whose elements are in successive memory locations. The content of the
instruction code, represents the starting address of the array and the value of the index
register, and the index value of the current element. By incrementing or decrementing
index register different element of the array can be accessed.
3) Indirect Mode:
The effective address of the operand is the contents of a register or main memory
location, location whose address appears in the instruction. Indirection is noted by
placing the name of the register or the memory address given in the instruction in
parentheses. The register or memory location that contains the address of the operand
is a pointer. When an execution takes place in such mode, instruction may be told to
go to a specific address. Once it's there, instead of finding an operand, it finds an
address where the operand is located.
NOTE:
Two memory accesses are required in order to obtain the value of the operand (fetch
operand address and fetch operand value).
(address A is embedded in the instruction code and (A) is the operand address =
pointer variable)
Example: (SPIM)
beta: .word 2000
lw $11, beta # load word (32 -bit quantity) at address beta into register
$11
# address of the word is embedded in the instruction code
# (register $11 will receive value 2000)
5) Register Mode
The name (the number) of the CPU register is embedded in the instruction. The
register contains the value of the operand. The number of bits used to specify the
register depends on the total number of registers from the processor set.
Example (SPIM)
add $14,$14,$13 # add contents of register $13 plus contents of
# register $14 and save the result in register $14
6) Displacement Mode
Similar to index mode, except instead of a index register a base register will be used.
Base register contains a pointer to a memory location. An integer (constant) is also
referred to as a displacement. The address of the operand is obtained by adding the
contents of the base register plus the constant. The difference between index mode
and displacement mode is in the number of bits used to represent the constant. When
the constant is represented a number of bits to access the memory, then we have index
mode. Index mode is more appropriate for array accessing; displacement mode is
more appropriate for structure (records) accessing.
Example: SPIM/SAL - Accessing fields in structures
.data
student: .word 10000 #field code
.ascii "Smith" #field name
.byte # field test
.byte 80,80,90,100 # fields hw1,hw2,hw3,hw4
.text
__start:
la $3, student # load address of the structure in $3
# $3 base register
add $17,$0,90 # value 90 in register $17
# displacement of field "test" is 9 bytes
#
sb $17, 9($3) # store contents of register $17 in field "test"
# displacement addressing mode
done
7) Autoincrement /Autodecrement Mode
A special case of indirect register mode. The register whose number is included in the
instruction code, contains the address of the operand. Autoincrement Mode = after
operand addressing , the contents of the register is incremented. Decrement Mode =
before operand addressing, the contents of the register is decrement.