Reputation: 21
Getting a segmentation fault and output is not as desired in linux 64 bit assembly language. Beginner. Any help would be appreciated. Seeking help first here before I speak to TA/professor. Here is the link to the site for reference: http://www.cs.fsu.edu/~langley/CIS4385-2014-1/Assign2-new.html
Here is my code thus far:
.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
Upvotes: 0
Views: 142
Reputation: 8033
You confused x86 assembly with x86_64 assembly.
%edx
vs %rdx
, %ebx
vs %rdi
, ... You need to read about x86_64 conventions. It isn't a simple replacement from %e..
to %r..
!mov $1,%rax
, then GNU as(1)
will choose an appropriate variant of mov
for you (movq
in this case)SYS_write
is 1
, for example. See /usr/include/asm/unistd_64.h
for the full list.FYI, this is how to use 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, ...)
Upvotes: 3