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

查看:41
本文介绍了推动 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 用于 0x0 - 0x7fffffff 范围内的即时值(即正符号 32 位值,它们是用 0 位符号扩展)或 0xffffffff80000000 - 0xffffffffffffffff)(即用 1 位符号扩展的负有符号 32 位值).但是您不能使用此范围之外的值(因为它们无法在指令编码中表示).

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 位世界中,push 将使用 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天全站免登陆