LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-27-2014, 05:00 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Rep: Reputation: 52
nasm hello world segmentation fault


I have the following code which works but gives a segmentation fault after printing the message to STDOUT, I have no idea what the problem could be.

Could someone help? (I do not know C)

Code:
[bits 64]
section .data
message:
    db      'hello, world!', 0
section .text
global _start
_start:
    mov     rax, 4
    mov     rdi, 1
    mov     rsi, message
    mov     rdx, 13
    syscall

    mov     rax, 1
    xor     rdi, rdi
    syscall
Here are the commands used:
nasm -f elf64 -o hello.o hello.asm
ld -o hello hello.o
./hello

Debian 7
gcc 4.7.2-5
yasm 1.1.0-1
nasm 2.10.01-1
linker ???

Thank you for your help.
 
Old 05-27-2014, 12:43 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Your syscall interface seems wrong. syscall requires call number in rax, args in rbx, rcx, rdx ...
 
1 members found this post helpful.
Old 06-07-2014, 04:05 AM   #3
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
Thank you for your answer but arguments go in rax, rdi, rsi, rdx, rcx, r8, r9 in that order.
 
Old 06-07-2014, 09:11 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
According to this x64 hello world example (which works), you have your syscall numbers wrong.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] HELPPPP!!! PLSSS! SEGMENTATION FAULT in NASM... josephgithin Programming 1 05-31-2011 12:18 PM
What is a segmentation fault? 144419855310001 Fedora 1 04-28-2006 07:39 AM
segmentation fault! sharath patil Debian 5 04-22-2006 04:57 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
What is segmentation fault? koyi Programming 3 08-30-2003 12:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration