Page 1 of 1

no pusha or similar instruction in AMD64?

Posted: Thu Jun 12, 2008 9:58 am
by hippykin
Hello, i am now working on my interrupt handlers and currently i am pushing all the registers onto the stack and popping them all of before iret'ing however in IA-32 there are the popa and pusha instructions which do all this i imagine that they are faster and i am wondering if there is a similar pair of instructions in AMD64.
I have read the AMD manuals all i can gather from there is that the popa and pusha op-codes have been reassigned. Does anyone know of a equivalent pair of instructions that exist in AMD64 (long mode)?
thanks

Posted: Thu Jun 12, 2008 10:05 am
by AJ
Unfortunately, there's not an equivalent. I use the following macros suggested by the NASM manual:

Code: Select all

%macro  multipush 1-* 

  %rep  %0 
        push    %1 
  %rotate 1 
  %endrep 

%endmacro

%macro  multipop 1-* 

  %rep %0 
  %rotate -1 
        pop     %1 
  %endrep 

%endmacro
With these, you can provide the registers to push and pop in the same order, which makes things a bit easier to remember.

Cheers,
Adam

Posted: Sat Jun 14, 2008 1:48 pm
by hippykin
thank you AJ, i got interrupts working today (they would have worked first time if i had known that NASM wasn't cleaver enough to automatically use the long mode iret op-code, i had to manually specify iretq in the end)

Posted: Sat Jun 14, 2008 4:04 pm
by AJ
hippykin wrote:thank you AJ, i got interrupts working today (they would have worked first time if i had known that NASM wasn't cleaver enough to automatically use the long mode iret op-code, i had to manually specify iretq in the end)
#-o

Yup - that one got me first time too!

Cheers,
Adam

Re: no pusha or similar instruction in AMD64?

Posted: Tue Jan 20, 2015 1:06 pm
by jackman
I like the solution, but I'd like to know if (E)SP needs any special handling? I refer to the Intel opcode reference http://www.intel.com/content/dam/www/pu ... 325383.pdf, page 4-274.

The PUSHA instruction saves the SP to a temporary variable and then puts it on the stack. Is it sufficient to just push SP first? Thanks.

Re: no pusha or similar instruction in AMD64?

Posted: Tue Jan 20, 2015 1:35 pm
by Combuster
There's actually no need to push/pop RSP specifically in long mode. An interrupt already does that for you in all cases, and any properly paired push/pop to RSP will only add or subtract 8 from it since pushes and pops implicitly use RSP.