问题
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