在Linux 64位汇编语言中,获取分段错误和输出并不理想。初学者。任何帮助,将不胜感激。在我和TA /教授交谈之前先在这里寻求帮助。以下是该网站的链接供参考: http://www.cs.fsu.edu/~langley/CIS4385-2014-1/Assign2-new.html
到目前为止,这是我的代码:
.text # Start of code segment
.global _start # Declaring for linker (ld)
_start:
# String to stdout
movl $len,%edx # Argument: message length
movl $msg,%ecx # Argument: pointer to message to write
movl $1,%ebx # Argument: file handle (stdout)
movl $4,%eax # System call number (sys_write)
syscall # Invokes system calls in Linux
movl $0,%ebx # Argument: exit code
movl $1,%eax # System call number (sys_exit)
syscall # Invokes system calls in Linux
.data # Start of data segment
msg:
.ascii "Hello World (64 bit version) --- this is MY NAME!\n"
.ascii "\n"
.ascii "CIS 4385 Spring 2014\n"
len = . - msg # length of string
答案 0 :(得分:3)
您将x86程序集与x86_64程序集混淆。
%edx
vs %rdx
,%ebx
vs %rdi
,...您需要了解x86_64约定。它不是从%e..
到%r..
的简单替代!
另外,如果您只是写mov $1,%rax
,那么GNU as(1)
会为您选择mov
的适当变体(在这种情况下为movq
)SYS_write
为1
。有关完整列表,请参阅/usr/include/asm/unistd_64.h
。仅供参考,这是如何使用GDB:
$ gdb -tui ./your.exe -ex 'break _start' -ex run
(gdb) layout next
(gdb) (hit Enter, Enter... until you get a desired view)
(gdb) nexti # or stepi, if you want to go into a function call
(gdb) (hit Enter, Enter, ...)