【问题标题】:Why is this machine code generated for "inc qword [rsp]"?为什么会为“inc qword [rsp]”生成此机器代码?
【发布时间】:2012-09-21 06:41:42
【问题描述】:

考虑这个 x64 NASM 语法程序集:

inc qword [rax]
inc qword [rcx]
inc qword [rdx]
inc qword [rbx]
inc qword [rsp]
inc qword [rbp]
inc qword [rsi]
inc qword [rdi]

使用 nasm 组装(并与 gnu ld 链接)后,objdump -d 报告以下内容:

4000b0:       48 ff 00                incq   (%rax)
4000b3:       48 ff 01                incq   (%rcx)
4000b6:       48 ff 02                incq   (%rdx)
4000b9:       48 ff 03                incq   (%rbx)
4000bc:       48 ff 04 24             incq   (%rsp)
4000c0:       48 ff 45 00             incq   0x0(%rbp)
4000c4:       48 ff 06                incq   (%rsi)
4000c7:       48 ff 07                incq   (%rdi)

为inc qword [rbp] 生成的代码是有意义的,因为设置了 mod 字段。但是,在组装inc qword [rsp] 时,我无法弄清楚24 的来源。我一直在查看coder64 #xFF,但没有任何迹象表明应该生成 24。我显然错过了更高层次的东西。

【问题讨论】:

    标签: assembly 64-bit nasm machine-code


    【解决方案1】:

    没有 [RSP] ModR/M 字节。所以它使用 [sib] ModR/M。 sib 表示有一个sib byte,0x24 是 RSP 的 sib 字节。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-22
      • 2019-06-04
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 2019-11-28
      • 2012-01-03
      • 1970-01-01
      相关资源
      最近更新 更多