Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

problem with my first code on Assembly on Unix using "as"

here is the code

from the book programing from the ground up .

When executing the .o file that is compiled and linked .

I get an Error of Segmentaltion Fault and when i use echo $? i get the returned value as 139 .

[code]
.section .data
.section .text
.globl _start
_start:
movl $1, %eax # this is the linux kernel command
# number (system call) for exiting
# a program
movl $0, %ebx # this is the status number we will
# return to the operating system.
# Change this around and it will
# return different things to
# echo $?
int $0x80 # this wakes up the kernel to run
# the exit command
[/code]

if someone could let me know why us it giving a segmentation fault plus i am using a Unix sun solaris Express and the book is intended for Linux . hope that isnt one of problem dosnt seem so to me anyways .

Thanks
Karan

Comments

  • HackmanCHackmanC Member Posts: 441
    Quote ... "When executing the .o file that is compiled and linked".

    [b]Are you absolutely sure you linked the resulting "as" *.out file?[/b]

    as -o myprg.out myprg.asm
    ld -s -o myprg myprg.out

    Your posted code works on linux.

    [red]Good luck![/red]
    [blue]Hackman[/blue]
  • conte0conte0 Member Posts: 1
    : here is the code
    :
    : from the book programing from the ground up .
    :
    : When executing the .o file that is compiled and linked .
    :
    : I get an Error of Segmentaltion Fault and when i use echo $? i get
    : the returned value as 139 .
    :
    : [code]:
    : .section .data
    : .section .text
    : .globl _start
    : _start:
    : movl $1, %eax # this is the linux kernel command
    : # number (system call) for exiting
    : # a program
    : movl $0, %ebx # this is the status number we will
    : # return to the operating system.
    : # Change this around and it will
    : # return different things to
    : # echo $?
    : int $0x80 # this wakes up the kernel to run
    : # the exit command
    : [/code]:
    :
    : if someone could let me know why us it giving a segmentation fault
    : plus i am using a Unix sun solaris Express and the book is intended
    : for Linux . hope that isnt one of problem dosnt seem so to me
    : anyways .
    :
    : Thanks
    : Karan
    :

    hello,
    the interrupt 0x80 is the linux gateway for system call, on solaris you must call syscall (or sysenter)
Sign In or Register to comment.