x86 Assembly Passing Parameters by Reference

别说谁变了你拦得住时间么 提交于 2020-01-24 20:34:11

问题


Below is my code for assembly language. I can pass by a stack parameter value using "push [edi]" but I cannot seem to pass by reference using "push OFFSET [edi]". What's the correct syntax to pass something by reference in this case?

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

回答1:


the index register edi holds a pointer to your data. [edi] dereferences this pointer (similar to C's * operator). So, if push [edi] pushes the data pointed to by edi onto the stack, to push the edi itself onto the stack, you need to... push edi =).




回答2:


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]


来源:https://stackoverflow.com/questions/28786154/x86-assembly-passing-parameters-by-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!