This code is really simple and I am getting a seg fault on my x86_64 linux system. It is bothering me a lot. Just getting started with asm so please have patience!
Assembled with NASM
nasm -f elf64 test.asm
linked with
ld -o test test.o
SECTION .text
GLOBAL _start
_start:
; print name
mov eax,4 ; sys_write
mov ebx,1 ; stdout
mov ecx,name ; start address of name
mov edx,1 ; length
int 80H ; syscall
; exit program
mov eax,1 ; sys_exit
mov ebx,0 ; success
int 80H ; sys_call
SECTION .data
name DB 'R'
My machine: Gentoo x86_64 nomultilib! I compiled my own kernel without IA32 emulation. I should have stated that my system is a 64 bit only system. Would this attribute to the errors I am receiving?
$ uname -a
Linux rcepeda 4.4.1-2-ARCH #1 SMP PREEMPT Wed Feb 3 13:12:33 UTC 2016 x86_64 GNU/Linux
Solution
use 64 bit registers and 64bit linux dispatcher
use syscall (not int 80H).
Thank you Nate and Michael
SECTION .text
GLOBAL _start
_start:
; print name
mov rax,1 ; sys_write
mov rdi,1 ; stdout
mov rsi,name ; start address of name
mov rdx,7 ; length
syscall
; exit program
mov rax,60 ; sys_exit
mov rdi,0 ; success
syscall
SECTION .data
name DB "Rafael",10
.
rafael@rcepeda ~/asm $ ./a.out
Rafael
uname -a
? – YOUR
instead ofHello world
, that's all. But otherwise it's real code. – Nate Eldredgeint 0x80
mechanism. – Michael Petchuname -a
returns. It would be helpful to show that in your question – Michael Petch