Given is the assembly program of Intel 8086 Processor which adds the numbers in array:
.model small
.stack 100h
.data
array dw 1,2,3,1,2
sum dw ?,", is the sum!$"
.code
main proc
mov ax,@data
mov ds,ax
mov di,0
repeat:
mov ax,[array+di]
add sum,ax
add di,2 ; Increment di with 2 since array is of 2 bytes
cmp di,9
jbe repeat ; jump if di<=9
add sum,30h ; Convert to ASCII
mov ah,09h
mov dx,offset sum ; Printing sum
int 21h
mov ax,4c00h
int 21h
main endp
end main
Above program adds the number of array using "base + index" addressing mode.
The same operation can by performed by something like:
mov ax, array[di]
Now I have following questions here:
- What's the difference between
array[di]
and[array+di]
- Which memory addressing mode is
array[di]
? - Which one is better to use and why?