1
在64位Linux计算机上再次使用汇编语言修改,尽管这应该没有什么区别。程序集或程序退出值ADD指令的误解
我会复制我的程序,并通过它讲我的方式。目前我没有得到我期望的答案。在这里,我们去:
global _start
section .data
v1 dq 151 ; first variable points to memory location containing "151d"
v2 dq 310 ; uint64_t v2 = 310d
sum dq 0
section .text
_start:
mov rax, 9 ; rax now contains 9
add [v1], rax ; v1 now points to a memory location containing 151 + 9 = 160
mov rax, [v2] ; rax contains the value 310
add rax, 10 ; rax contains the value 310 + 10 = 320
add rax, [v1] ; rax contains the value 320 + 160 = 480
mov [sum], rax ; sum now points to a memory location containing the value 480
mov eax, 1 ; system call to "exit"=1
mov ebx, [sum] ; return value of program is 480
int 0x080 ; call the system interrupt to terminate program
然后运行我的程序,我这样做:
./main.exec; echo $?
输出是:
224
不是480?我猜测我误解了add
的工作原理,或者误解了如何将退出代码返回给操作系统。我正确吗?
建议:HTTP://www.csee.umbc通过与GDB代码的一步。 EDU /〜cpatel2 /链接/ 310/NASM/gdb_help.shtml。我想你会看到你的代码工作正常......但480> 256.和480-256 = 224 :) – paulsm4
@ paulsm4可能应该学习gdb! – user3728501