Assembly Language for Beginners

(Jeff_L) #1

1.12. POINTERS


Now the global variables’ values are loaded into registers ready for passing toprintf()(via the stack):


Figure 1.28:OllyDbg: global variables’ values are passed intoprintf()

Local variables example


Let’s rework our example slightly:


Listing 1.101: now thesumandproductvariables are local

void main()
{
int sum, product; // now variables are local in this function


f1(123, 456, &sum, &product);
printf ("sum=%d, product=%d\n", sum, product);
};


f1()code will not change. Only the code ofmain()will do:


Listing 1.102: Optimizing MSVC 2010 (/Ob0)

_product$ = -8 ; size = 4
_sum$ = -4 ; size = 4
_main PROC
; Line 10
sub esp, 8
; Line 13
lea eax, DWORD PTR _product$[esp+8]
push eax
lea ecx, DWORD PTR _sum$[esp+12]
push ecx
push 456 ; 000001c8H
push 123 ; 0000007bH
call _f1
; Line 14
mov edx, DWORD PTR _product$[esp+24]
mov eax, DWORD PTR _sum$[esp+24]
push edx
push eax
push OFFSET $SG2803
call DWORD PTR impprintf
; Line 15
xor eax, eax
add esp, 36

Free download pdf