What's the difference between 'push' and 'pushq' in at&t assembly

user6090272 picture user6090272 · Jan 14, 2018 · Viewed 12.5k times · Source

I've recently started my quest of obtaining a greater understanding as to how my computer works. My question is in regards to the differences between push and pushq.

I'm aware that push writes a value to the stack and my assumption is that pushq does the something similar. The fact the q is there makes me think that there should be a subtle difference but I can't seem to make sense of the difference.

I stated to ponder this question while debugging the file /lib/udev/iphone-set-info using gdb with the command 'layout asm'.

the code in question is :

pushq  $0x0
push   %r9

I understand that $0x0 is hexadecimal for NULL and that %r9 is one of the general registers. Does this just mean that Null us written to the stack with register %r9 written above it?

Answer

Keltar Helviett picture Keltar Helviett · Jan 22, 2018

I'm not sure what assembly language you're using, but that's true for GAS(GNU Assembler) that uses AT&T syntax too: GAS assembly instructions are generally suffixed with the letters "b", "s", "w", "l", "q" or "t" to determine what size operand is being manipulated.

  • b = byte (8 bit)
  • s = short (16 bit integer) or single (32-bit floating point)
  • w = word (16 bit)
  • l = long (32 bit integer or 64-bit floating point)
  • q = quad (64 bit)
  • t = ten bytes (80-bit floating point)

If the suffix is not specified, and there are no memory operands for the instruction, GAS infers the operand size from the size of the destination register operand (the final operand).

pushq $0x0 just pushes 8 zero bytes to stack. Then push %r9 defines that %r9 is 64 bit register and pushes it's value to stack.

The interesting fact about the stack that it grows down, so null bytes will have higher addresses than the value of %r9, so here may be misunderstanding, because actually value of %r9 is below the null bytes.