首页 > 解决方案 > 在汇编 x86-64 AT&T 中写入内存位置

问题描述

我正在尝试将数据从一个内存位置移动到另一个内存位置,然后打印结果。但我得到的只是一些垃圾价值,我不知道为什么。相关代码如下:

.bss 
code: .skip 1000000

.data 
smth: .asciz "somerandomtext"
format_str: .asciz "Contents of code:\n%s"

.text
main:
pushq %rbp
movq %rsp, %rbp

movq $smth , %rdi    # move address of smth in rdi
movq $code , %rax    # move address of code in rax
movq %rdi , (%rax)   # move contents of rdi to address stored in rax ??

movq $0 , %rax
movq $code , %rsi
movq $format_str , %rdi
call printf

movq %rbp, %rsp
popq %rbp

我知道我选择的寄存器并不理想,我在做其他事情时遇到了这个问题。

标签: assemblyx86-64att

解决方案


推荐阅读