开发者

I have question about stack

I have assignment to calculate GCD of two no. by using stack frame & I write code for this -

.text 

GCD:
     push ebp
     mov ebp,esp

1:   cmp ebx,eax
     je  3f

      ja 2f

      sub ebx,eax
      jmp 1b

2:    sub eax,ebx
      jmp 1b

3:    leave
   开发者_如何转开发   ret

I got the answer of this code but i have question without taking memory location like [ebp+8] how program run or how this program execute ?


Using the __fastcall calling convention you can ask for parameters to be passed in registers. That should make even your function prologue (push ebp etc) and epilogue (leave) redundant, unless you create stack-based variables to use later.

Visual C++ has one implementation of __fastcall, but GCC also handles it. See this document for information about the calling convention.

Just a note though - if the assignment asks for you to use the stack frame, you'll need to use the __cdecl or __stdcall calling conventions to get the parameters to calculated the GCD from.


Well, your function actually takes its arguments in eax and ebx, rather than using arguments pushed onto the stack. If this isn't what you want, put these two instructions after the mov ebp, esp:

mov eax, [ebp + 8]
mov ebx, [ebp + 12]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜