Procedures: X86 Assembly Language Programming For The PC
Procedures: X86 Assembly Language Programming For The PC
Procedures
Syntax:
.data
vector1 dw action1
vector2 dd action2
.code
start:
…
…
;Intrasegment Direct
call action1
…
…
;Intrasegment Indirect
call vector1
…
…
;Intersegment Direct
call action2
…
…
;Intersegment Indirect
call vector2
…
…
end start
1. in registers
2. in memory variables
3. on the stack
.data
var1 dw ?
var2 dw ?
.code
start:
…
…
;Pass by Value
push var1
push var2
call action1
…
…
;Pass by Reference
push offset var1
push offset var2
call action2
…
…
end start
EXAMPLE:
main:
push offset var1
push offset var2
call clear
.
EXAMPLE:
stack_frame struc Stack:
saved_bp dw ?
caller_ip dw ? [bp+6] offset Var1
var2_ptr dw ? [bp+4] offset Var2
var1_ptr dw ? [bp+2] caller ip
stack_frame ends [bp] saved bp
[bp-2] saved bx
clear proc near
push bp
mov bp,sp
push bx
mov bx,[bp].var2_ptr
mov word ptr [bx],0
mov bx,[bp].var1_ptr
mov word ptr [bx],0
pop bx
pop bp
ret 4
clear endp
F0010
F000E [BP+6]
F000C [BP+4]
F0008 [BP+2]
F0006 [BP]
F0004 [BP-2]
F0002 [BP-4]
F0000
{ .
return a - b; .
} mov ax,4
push ax
mov ax,3
push ax
call _sub
add sp,4
mov total2,ax
.
.