Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The return address in the assembly code

Tags:

x86

assembly

call

The assembly code goes like this:

  call next
next:
  popl %eax

I thought after call next, the return address will be pushed onto the stack, right? But in the above code, what's the return address?

like image 205
Alcott Avatar asked Apr 18 '26 20:04

Alcott


2 Answers

After that code executes %eax will have the address of label "next"

  1. the call branches to the target which happens to be the next sequential instruction and pushes the return address, which is always the address of the next sequential instruction
  2. the popl will pop the return address from the stack onto %eax register

The net effect is %eax points to label "next"

like image 126
amdn Avatar answered Apr 21 '26 19:04

amdn


It's the address of the instruction immediately following the call instruction. See your CPU documentation on how call works.

like image 41
Alexey Frunze Avatar answered Apr 21 '26 20:04

Alexey Frunze