x86程序集通过引用传递参数

时间:2015-02-28 19:54:08

标签: assembly x86 pass-by-reference

下面是我的汇编语言代码。我可以使用“push [edi]”传递堆栈参数值,但我似乎无法使用“push OFFSET [edi]”通过引用传递。在这种情况下,通过引用传递内容的正确语法是什么?

sortList        PROC
;Parameter memory addresses:
;numbers    @ [ebp+8]
;list       @ [ebp+12]

;Used to access stack parameters
push        ebp
mov         ebp, esp

;Sets up the array
mov         edi, [ebp+12]               ;Puts in the address of the list array
mov         ecx, [ebp+8]                ;Sets up the loop counter for the array

;Testing swapNumber function
push        [edi]                           ;array 1 pushed will be ebp+12
add         edi, 4
push        [edi]                           ;array 2 pushed will be ebp+8
call        swapNumber

pop         ebp
ret         8
sortList        ENDP

2 个答案:

答案 0 :(得分:0)

索引寄存器edi包含指向数据的指针。 [edi]取消引用此指针(类似于C的*运算符)。因此,如果push [edi]edi指向的数据推送到堆栈上,要将edi本身推送到堆栈,则需要... push edi =)。

答案 1 :(得分:0)

mov edi,8 ; edi = 8
push edi ; we push to the stack the value '8'
push [edi]; we push to the stack the value in the address memory:8
;in your case i'm pretty sure that you mean push edi instead of push [edi]