assemblyx86masmmasm32addressing-mode

In MASM what is array[4]


I have a code in MASM, which contains

mov bx, 4
mov ax, array[bx] + 4

So array[4] here is the fifth element of the array or 4 bytes and then we add 4 bytes ? What will be the value of AX then?


Solution

  • The number between square brackets is an offset in the array. It is a distance measured in bytes.
    The number that comes after these square brackets is just another offset. It could have been inserted between the brackets too: mov ax, array[bx+4]. Even the address of the array itself can go between the brackets: mov ax, [array + bx + 4].

    AX will get the word value from the 9th (offset 8) and 10th (offset 9) bytes of the array.