1

I have a question about a CALL function in a assembly code. Is it right when I execute a CALL function in assembly that the instruction is pushed onto the stack? When is the instruction popped back when I CALL a function?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
p0sx
  • 65
  • 1
  • 1
  • 3
  • 1
    `CALL` is not a function, it's a single instruction for the [CPU](http://en.wikipedia.org/wiki/Central_processing_unit) to execute. Depending on the architecture (x86, PPC, ARM, ...) and calling convention things are implemented differently. Please consult the manual for the hardware you're programming, or give us more information here. – Jens Jun 06 '15 at 12:17
  • Possible duplicate of [how do procedure calls work in assembler?](http://stackoverflow.com/questions/1251060/how-do-procedure-calls-work-in-assembler), http://stackoverflow.com/questions/33685146/x86-does-call-instruction-always-push-the-address-pointed-by-eip-to-stack – Cody Gray - on strike Dec 30 '16 at 06:54

2 Answers2

4

This answer assumes Intel x86 architecture.

Is is right when I execute a CALL function in assembly that instruction is pushed onto the stack ?

No. What is pushed onto the stack is the value of the instruction pointer, which at that time points to the instruction following the CALL instruction.

When is the instruction popped back when I CALL a function ?

Typically when you execute a RET instruction.

For more information refer to the x86 calling conventions, and Intel's x86 instruction manual.

Jens
  • 8,423
  • 9
  • 58
  • 78
Michael
  • 57,169
  • 9
  • 80
  • 125
  • This depends on the architecture and the calling convention used for the function call. PPC, for example, does not push anything. – Jens Jun 06 '15 at 12:19
  • True, but I assumed x86 since the question was tagged with `esp`. – Michael Jun 06 '15 at 12:20
  • There doesn't seem to be a definition for the `esp` tag. Op should be more specific. – Jens Jun 06 '15 at 12:25
1

On x86 and x86/64bit call push into stack address of next instruction.

For example:

call after_hello
db 'hello', 0xa
after_hello:

In this moment of top of the stack you have address of this string - it is a nice trick. Probably in this moment you never use use ret for jump to first instruction after call.