Pushing imm32 ends up in pushing imm64? [duplicate]

扶醉桌前 提交于 2019-12-08 08:48:05

问题


From the intel instruction reference:

68 id PUSH imm32

It means pushing dword-sized immediates is valid in 64-bit program.

So I wrote the following program:

section .text
    global _start

_start:
    call _foo

    mov rax, 60
    syscall

_foo:
    push word 0xFFFF      ;ok
    pop ax                ;ok
    push dword 0xFFFFFFFF ; warning: signed dword value exceeds bounds
    pop rax
    call _bar
    ret

_bar:
    ret

Why did I get this warning? From the intel reference:

The operand size (16, 32, or 64 bits) determines the amount by which the stack pointer is decremented (2, 4 or 8). If the source operand is an immediate of size less than the operand size, a sign-extended value is pushed on the stack.

In my case the operand size is 32 bits. It's not less than operand size. So I expected everything was going to be okay. But, when executing the program after push dword 0xFFFFFFFF the 64-bit sign extension of it was pushed actually.

Also it's not clear why do we have push imm32 instruction in 64-bit mode. If we try to

pop eax ;instruction not supported in 64-bit mode

So even if we could push 32-bit into the stack, we cannot pop it into 32-bit register.

来源:https://stackoverflow.com/questions/48705762/pushing-imm32-ends-up-in-pushing-imm64

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