如何翻译 NASM“推字节” 到气体语法?

发布于 2024-07-16 14:26:56 字数 169 浏览 5 评论 0原文

我正在将 NASM 源“移植”到 GAS,并发现以下代码行:

push byte 0
push byte 37

GAS 不允许“push byte”或“pushb”。

我应该如何将上面的代码翻译成GAS语法?

谢谢

I'm "porting" a NASM source to GAS and I found the following lines of code:

push byte 0
push byte 37

GAS doesn't allow "push byte" or "pushb".

How should I translate the above code to GAS syntax?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鲜血染红嫁衣 2024-07-23 14:26:56

pushb 已从 GAS 中删除。 您应该能够使用 push 命令来获得相同的效果。 更多信息请参见此处

pushb was removed from GAS. You should be able to use the push command to get the same effect. A little more information is here.

情域 2024-07-23 14:26:56

1) NASM 2.11 64 位中的 push byte 编译为与 push 相同,但如果推送的内容更大,它会拒绝编译比一个字节:

push 0x0000
push 0x01
push 0x0001
push 0x10

与以下相同:

push byte 0x0000
push byte 0x01
push byte 0x0001
push byte 0x10

但以下失败:

push byte 0x0100
push byte 0x1000
push byte 0x01000000
push byte 0x10000000

所有这些都编译为指令的 6a XX 形式。

2) NASM 和 GAS 根据操作数大小自动决定使用哪种形式:

GAS 2.25:

push $0x0000
push $0x01
push $0x0001
push $0x10
push $0x0100
push $0x1000
push $0x01000000
push $0x10000000

编译为与 NASM 相同:

push 0x0000
push 0x01
push 0x0001
push 0x10
push 0x0100
push 0x1000
push 0x01000000
push 0x10000000

Objdump:

   0:   6a 00                   pushq  $0x0
   2:   6a 01                   pushq  $0x1
   4:   6a 01                   pushq  $0x1
   6:   6a 10                   pushq  $0x10
   8:   68 00 01 00 00          pushq  $0x100
   d:   68 00 10 00 00          pushq  $0x1000
  12:   68 00 00 00 01          pushq  $0x1000000
  17:   68 00 00 00 10          pushq  $0x10000000

所以只需在 GAS 中push与NASM中的push byte相同,但没有错误检查。

3) GAS 中确实存在的修饰符是 w,如下所示:

pushw $0

编译为:

0:   66 6a 00                pushw  $0x0

即添加 0x66 前缀用于切换 16 位操作。

NASM 的等价是:

push word 0

4)mov 的区别在于我们无法控制任意的入栈大小:它们都是将固定数量的入栈。

我们可以控制指令编码的唯一参数是是否包含 0x66 前缀。

其余的由段描述符决定。 请参阅Intel 64 和 IA-32 架构软件开发人员手册 - 第 2 卷指令集参考 - 325383-056US 2015 年 9 月

1) push byte in NASM 2.11 64 bit compiles to the same as just push, except that it refuses to compile if the thing pushed is larger than a byte:

push 0x0000
push 0x01
push 0x0001
push 0x10

Is the same as:

push byte 0x0000
push byte 0x01
push byte 0x0001
push byte 0x10

But the following fail:

push byte 0x0100
push byte 0x1000
push byte 0x01000000
push byte 0x10000000

All of those compile to the 6a XX form of the instruction.

2) NASM and GAS automatically decide what form to use based on the operand size:

The GAS 2.25:

push $0x0000
push $0x01
push $0x0001
push $0x10
push $0x0100
push $0x1000
push $0x01000000
push $0x10000000

Compiles to the same as the NASM:

push 0x0000
push 0x01
push 0x0001
push 0x10
push 0x0100
push 0x1000
push 0x01000000
push 0x10000000

Objdump:

   0:   6a 00                   pushq  $0x0
   2:   6a 01                   pushq  $0x1
   4:   6a 01                   pushq  $0x1
   6:   6a 10                   pushq  $0x10
   8:   68 00 01 00 00          pushq  $0x100
   d:   68 00 10 00 00          pushq  $0x1000
  12:   68 00 00 00 01          pushq  $0x1000000
  17:   68 00 00 00 10          pushq  $0x10000000

So just push in GAS is the same as push byte in NASM, but without the error checking.

3) The modifier that does exist in GAS is w as in:

pushw $0

which compiles to:

0:   66 6a 00                pushw  $0x0

i.e., adds the 0x66 prefix to toggle 16 bit operation.

NASM's equivalent is:

push word 0

4) The difference from mov is that we cannot control arbitrary push sizes: they are all push fixed amounts to the stack.

The only parameter we can control on the instruction encoding is to include the 0x66 prefix or not.

The rest is determined by the segment descriptor. See the Intel 64 and IA-32 Architectures Software Developer’s Manual - Volume 2 Instruction Set Reference - 325383-056US September 2015.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文