linux - 为什么在 x64 程序集中将复制变量地址移动到寄存器?

标签 linux assembly x86-64 att

我使用 AT&T 语法在 x64 汇编中编写了一个程序,但我不明白为什么 mov 运算符将地址变量复制到寄存器中。这是我的代码:

        .globl main

        .text
main:
    mov    $a, %rax

    mov     $format, %rdi           # set 1st parameter (format)
    mov     %rax, %rsi              # set 2nd parameter (current_number)
    mov     $0, %rax                # because printf is varargs

    sub     $8, %rsp                # align stack pointer
    call    printf                  # printf(format, sum/count)
    add     $8, %rsp                # restore stack pointer

    ret

        .data
a:      .quad   123
format: .asciz  "%d\n"

程序输出 6295616 而不是 123。请帮助我理解我做错了什么。

最佳答案

因为您已经用美元符号表示您想要立即模式。删除它以获得绝对模式。

关于linux - 为什么在 x64 程序集中将复制变量地址移动到寄存器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21007274/

相关文章:

linux - Linux 上的 SetPriorityClass 等价物

linux - 具有多个 screen session 的 Shell 脚本不执行任何操作

assembly - 在 C64/Assembly 中更改没有颜色内存的文本颜色

c - posix_memalign 与 mmap 有何不同

linux - 截断的核心转储有什么用?

linux - (13)Permission denied : access to/cgi-bin/test. cgi denied

linux - 执行脚本的多个实例 - GNU Parallel

image - 在asm中翻转图像中的第一个像素

assembly - x86 多字节 NOP 和指令前缀

linux - NASM 调用标签未被调用