Professional Documents
Culture Documents
7 Assembly07 Complex
7 Assembly07 Complex
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
««««
comment @
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
The standard Intel notation for addressing memory can look very daunting
to a beginner but it is in fact very compact and simple enough to use
once you know how it works. It is usually referred to as the "complex"
addressing modes. If you understand it properly you can write very compact
and fast code using the technique.
Base address
The starting address in memory
Index
A 32 bit register which is the variable for changing the address
Scale
The data size being worked on, it can be 1, 2, 4 or 8
Displacement
An optional additional offset to change the address by.
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
«««« @
; -----------------------------------------------------------------
; include files that have MASM format prototypes for function calls
; -----------------------------------------------------------------
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
; ------------------------------------------------
; Library files that have definitions for function
; exports and tested reliable prebuilt code.
; ------------------------------------------------
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
; --------------------------
; initialise 10 DWORD values
; --------------------------
itm0 dd 0
itm1 dd 1
itm2 dd 2
itm3 dd 3
itm4 dd 4
itm5 dd 5
itm6 dd 6
itm7 dd 7
itm8 dd 8
itm9 dd 9
; ---------------------------------
; put their addresses into an array
; ---------------------------------
array dd itm0,itm1,itm2,itm3,itm4
dd itm5,itm6,itm7,itm8,itm9
exit
;
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
««««
main proc
push ebx
push esi
push edi
label2:
mov edi, [ebx+esi*4]
print str$(edi)
print chr$(13,10)
add esi, 1 ; each array member is accessed by changing the INDEX
sub cnt, 1
jnz label2
pop edi
pop esi
pop ebx
ret
main endp
;
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
««««