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

与世无争的帅哥 提交于 2019-12-23 07:46:30

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/48251829/whats-the-difference-between-push-and-pushq-in-att-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!