masm - Whats the fundamental difference between addressing of array[di] and [array + di] in assembly? -


given assembly program of intel 8086 processor adds numbers in array:

.model small .stack 100h  .data     array dw 1,2,3,1,2     sum   dw ?,", 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 2 since array of 2 bytes      cmp di,9     jbe repeat         ; jump if di<=9      add sum,30h        ; convert ascii     mov ah,09h     mov dx,offset sum  ; printing sum     int 21h      mov ax,4c00h     int 21h main endp end  main 

above program adds number of array using "base + index" addressing mode.

the same operation can performed like:

mov ax, array[di] 

now have following questions here:

  1. what's difference between array[di] , [array+di]
  2. which memory addressing mode array[di]?
  3. which 1 better use , why?

according book the art of assembly language, array[di] , [array + di] both "indexed addresing modes", so, none better other, different syntax same thing. section 4.6.2.3 indexed addressing modes of book explains important thing the presence of constant value , index (or base) register :

the indexed addressing modes use following syntax:

            mov     al, disp[bx]             mov     al, disp[bp]             mov     al, disp[si]             mov     al, disp[di] 

the offsets generated these addressing modes sum of constant , specified register.

enter image description here

you may substitute si or di in figure above obtain [si+disp] , [di+disp] addressing modes.

we calling "constant value" variable array because variables offsets in data segment (so constant values), explained here :

variable memory location. programmer easier have value kept in variable named "var1" @ address 5a73:235b.

it important mention different assemblers may use different syntax same addressing modes, example, masm vs nasm, or nasm vs gas.

there other addressing modes change size (in bytes) , performance (in clock cycles) of instructions involved, can read here. next instruction mov , addressing modes :

enter image description here enter image description here


Comments

Post a Comment

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -