Etki
Etki

Reputation: 2144

x86 ASM: how return to different code segment is implemented?

I'm getting acquainted with PCASM book, and i don't understand one thing (which may be just my misunderstanding, i'm still new to low-level programming). It is told that c calling convention is something like

So far so good, but examples tell that return code is simply four bytes on the stack. That allows to jump anywhere on current code segment, but what if subroutine has to return to another segment? If code segment has to be pushed on the stack the same way as return address, how should one refer to arguments in subroutine (because they will have different offset on near and far return)?

Upvotes: 0

Views: 405

Answers (1)

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137398

The retf instruction performs a "long return" which includes a segment and offset.

Upvotes: 3

Related Questions