0

I have the following basic assembly program to call a function that sets the return value as 22 and then exits:

.globl _start
_start:
    call update_value
    mov $1, %rax
    int $0x80

update_value:
    mov $22, %rbx
    ret

Without using the call, ret instructions, how would this be done? I think conceptually it translates to:

# call update_value
push <return_address>
jmp update_value

# ret
pop
jmp <return_address>

But how would this actually be done in valid assembly?

David542
  • 104,438
  • 178
  • 489
  • 842
  • 2
    FYI since you asked on another recent question, I found those duplicates as early hits for a google search on `site:stackoverflow.com emulate call ret`. Google personalizes results so IDK if they'd all be on the first page for you. They mostly happen to be 32-bit code, but my answer on one of those questions shows x86-64 code. Either way, same instructions, just use any call-clobbered register (other than the return value) to pop the return address. – Peter Cordes Aug 29 '20 at 01:06
  • 1
    Also, the return-value register for normal functions is EAX / RAX, not RBX. And [What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?](https://stackoverflow.com/q/46087730) - don't, it's a bad habit. `mov $231, %eax` / `syscall` with the exit status in EDI. – Peter Cordes Aug 29 '20 at 01:31

0 Answers0