amorimluc
amorimluc

Reputation: 1719

What does this assembly code do and why is it used?

ATT syntax.

I've noticed that library routines in C often use the following snippet of assembly code:

call next
next:
popl %eax

Upvotes: 1

Views: 444

Answers (2)

Mikhail
Mikhail

Reputation: 8028

What is the value of %eax after this sequence of instructions?

call next

next: popl %eax

Whatever the address of next is

(the memory address where popl instruction is) Note: this is NOT the PC, but it is related to it

– PC is the address of the next instruction to be executed; %eax now has address of most recently executed instruction (the popl)

See

Upvotes: 1

John Brodie
John Brodie

Reputation: 6017

It gives you the current value of the program counter (PC). That is, you get the address of the current instruction that is executing.

Here's an interesting article that talks about using that snippet vs doing it with C: http://blogs.msdn.com/b/oldnewthing/archive/2004/12/16/317157.aspx

Upvotes: 2

Related Questions