© Thomas Kunz 2000
SCE 574
105
Corresponding Assembler Code for 80386 Processor
ädo_it proc
ä push ebp
ä mov ebp,esp
ä mov [ebp+08h],eax;a
ä mov [ebp+0ch],edx;b
ä mov [ebp+010h],ecx;c
ä; 4        (*b) = a;
ä mov eax,[ebp+0ch];b
ä mov ecx,[ebp+08h];a
ä mov [eax],ecx
ä leave
ä ret
ädo_it endp
ä
main proc
push ebp
mov ebp,esp
sub esp,018h
; 12        a = 1;
mov dword ptr  a,01h
; 13        b = 2;
mov dword ptr [ebp-04h],02h;b
; 14        do_it(a,&b,c,d,e,f,g);
push dword ptr [ebp-018h];g
push dword ptr [ebp-014h];f
push dword ptr [ebp-010h];e
push dword ptr [ebp-0ch];d
mov ecx,[ebp-08h]; c
lea edx,[ebp-04h]; b
mov eax,dword ptr  a
sub esp,0ch
call do_it
; 15        printf("a %d b %d \n",a,b);
push dword ptr [ebp-04h];b
push dword ptr  a
mov eax,offset FLAT:@STAT1
sub esp,04h
call _printfieee
add esp,028h
leave
ret
main endp
Manage
base
pointer
Note: this is code for a 386
or higher, extended registers...
LEA is load effective address
MOV BX,OFFSET b
is same as
LEA  BX,b
Local
data items
show up on
main’s stack
Allocate
space for
local var
Compiler is smart, it didn’t push
a,c and address of b, they are in
ax, dx and cx, advance the sp as
if they were pushed, called rou-
tine will push them if necessary
First
three parms
are treated
in a special
way,
calling
convention
Knows that
b is an address