推64位英特尔OSX [英] push on 64bit intel osx

查看:147
本文介绍了推64位英特尔OSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想如下堆栈推64位地址,

I want to push 64 bit address on stack as below,

__asm("pushq $0x1122334455667788");

但我得到的编译错误,我只能在下列方式推,

But I get compilation error and I can only push in following way,

__asm("pushq $0x11223344");

有人可以帮助我了解我的错误?

Can someone help me understand my mistake?

我是新来组装,所以请原谅我,如果我的问题听起来很愚蠢。

I am new to assembly, so please excuse me if my question sounds stupid.

推荐答案

X86-64有一些有趣的怪癖,这是不是就算你熟悉的32位x86 ...

x86-64 has some interesting quirks, which aren't obvious even if you're familiar with 32-bit x86...


  1. 大多数指令只能取32位立即值,如果在64位环境中使用该符号扩展到64位。 (指令编码门店只有32位。)

  1. Most instructions can only take a 32-bit immediate value, which is sign-extended to 64 bits if used in a 64-bit context. (The instruction encoding stores only 32 bits.)

这意味着你可以在范围内使用 pushq 为immedate值为0x0 - 为0x7FFFFFFF (即正符号32位值这是符号扩展0位)或 0xffffffff80000000 - 0xffffffffffffffff )(即负签署了符号扩展与1位)的32位值。但你不能使用的值超出这个范围(因为他们不能重新$ P $的指令编码psented)。

This means that you can use pushq for immedate values in the range 0x0 - 0x7fffffff (i.e. positive signed 32-bit values which are sign-extended with 0 bits) or 0xffffffff80000000 - 0xffffffffffffffff) (i.e. negative signed 32-bit values which are sign-extended with 1 bits). But you cannot use values outside this range (as they cannot be represented in the instruction encoding).

MOV 是一个特殊情况:有这需要一个完整的64位立即数的编码。因此,丹尼尔的回答(这可能是你最好的选择)。

mov is a special case: there is an encoding which takes a full 64-bit immediate operand. Hence Daniel's answer (which is probably your best bet).

如果您的真正的不想腐败的寄存器,可以使用较小的值的倍数推。然而,推动两个32位值的明显的事情是行不通的。在64位世界中,将与64位运算工作(根据上述第1点,如果它是一个立即数)或16位操作数,但不32位操作数(甚至 pushl%eax中无效)。所以,你能做的最好的是4个16位推:

If you really don't want to corrupt a register, you could use multiple pushes of smaller values. However, the obvious thing of pushing two 32-bit values won't work. In the 64-bit world, push will work with a 64 bit operand (subject to point 1 above, if it's an immediate constant), or a 16 bit operand, but not a 32 bit operand (even pushl %eax is not valid). So the best you can do is 4 16-bit pushes:

PUSHW $ 0x1122; PUSHW $ 0x3344; PUSHW $ 0x5566; PUSHW $ 0x7788

这篇关于推64位英特尔OSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆