Addressing Modes
Addressing Modes
Assembly language
Register Addressing Mode:
• With the Register Addressing mode the operand to be
accessed is specified as residing in an internal register of the
8086.
•
• Example: MOV AX , BX
•
• This stands for move the contents of BX (the source operand)
to AX (the destination operand).Both the source and the
destination operands have been specified as the contents of
internal registers of the 8086.
Immediate Addressing Mode:
• If a source operand is part of the instruction instead of the contents of a
register or memory location, it represents what is called the immediate
operand and is accessed using immediate addressing mode. Typically
immediate operand represents constant data.
• Immediate operands can be either a byte or word of data.
• Example: MOV AX , 5
num1: dw 5
num2: dw 10
num3: dw 15
num4: dw 0
Indirect Addressing Mode:
We have done very elementary data access till now. Assume
that the numbers we had were 100 and not just three. This
way of adding them will cost us 200 instructions. There must
be some method to do a task repeatedly on data placed in
consecutive memory cells. The key to this is the need for some
register that can hold the address of data. So that we can
change the address to access some other cell of memory using
the same instruction. In direct addressing mode the memory
cell accessed was fixed inside the instruction. There is another
method in which the address can be placed in a register so
that it can be changed. For the following example we will take
10 instead of 100 numbers but the algorithm is extensible to
continue……
• There are four registers in iAPX88 architecture that can hold address
of data and they are BX, BP, SI, and DI. For the current example, we
will use the BX register and we will take just three numbers and
extend the concept with more numbers in later examples.
Example:
mov bx, num1 ; point bx to first number
mov ax, [bx] ; load first number in ax
add bx, 2 ; advance bx to second number
add ax, [bx] ; add second number to ax
add bx, 2 ; advance bx to third number
add ax, [bx] ; add third number to ax
add bx, 2 ; advance bx to result
mov [bx], ax ; add sum at num1+6
num1: dw 5, 10, 15 , 0
Example to add TEN number:
mov bx, num1 ; point bx to first number
mov cx, 10 ; load count of number in cx
mov ax, 0 ; initialize sum to zero
l1: ; lable
add ax, [bx] ; add number to ax
add bx, 2 ; advance bx to next number
sub cx, 1 ; number to be added reduced
jnz l1 ; if number remain add next
mov [total], ax ; write back sum in memory
num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
total: dw 0
Zero flag:
The Zero flag is set if the last mathematical or logical instruction has
produced a zero in its destination.
Register+Offset/Base relative Addressing: