A variable containing the address of another variable is called a pointer.
|
|
add ax, [pointer] |
add ax, SWORD PTR [pointer] |
.data
array SWORD 10, 20, 30, 40
pointer DWORD array
.code
mov ecx, LENGTHOF array
mov eax, 0
L1: add ax, [pointer]
add pointer, 2
loop L1
call WriteInt
|
.data
array SWORD 10, 20, 30, 40
pointer DWORD array
.code
mov ecx, LENGTHOF array
mov eax, 0
L1: add ax, SWORD PTR [pointer]
add pointer, 2
loop L1
call WriteInt
|
| Output | Output |
[pointer] gives the contents of the variable pointer.
mov esi, pointer”, [esi] dereferences the offset from the variable pointer and obtains the contents of memory.
add ax, [esi] |
add al, [esi] |
.data
array SWORD 10, 20, 30, 40
pointer DWORD array
.code
mov ecx, LENGTHOF array
mov eax, 0
mov esi, pointer
L1: add ax, [esi]
add esi, 2
loop L1
call WriteInt
|
.data
array SWORD 0102h, 0304h, 0506h
pointer DWORD OFFSET array
.code
mov ecx, 6
mov eax, 0
mov esi, pointer
L1: add al, [esi]
inc esi
loop L1
call WriteHex
|
| Output | Output |