Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Mar 2004 22:19:19 +0100
From:      jan.muenther@nruns.com
To:        Daniela <dgw@liwest.at>
Cc:        questions@freebsd.org
Subject:   Re: Strange behaviour in assembly language program
Message-ID:  <20040302211919.GA10074@ergo.nruns.com>
In-Reply-To: <200403022110.50014.dgw@liwest.at>
References:  <200403022110.50014.dgw@liwest.at>

next in thread | previous in thread | raw e-mail | index | archive | help
Howdy,

> Here it is:
> 
> .text
> .global _start
> _start:
> 	pushl	$0
> 	movl	$1, %eax
> 	int	$0x80
> 
> I looked everywhere (Developer's handbook, Google, ...) to find the solution, 
> but all resources I consulted tell me this is the right way to do it.
> This program, however, always exits with 1 regardless of the value I push.
> 
> Please, can someone tell me that I made a really stupid error? I'm already 
> pulling my hair out.

I sympathize. This has actually cost me quite some nerves as well, before
through some debugging and experimentation I found the answer:

The kernel expects the first argument 4 bytes below of the current stack
pointer, which means you have to put the int 80h call on its own label to
get it right. 

I usually use nasm (hate AT&T syntax, sorry),
should translate easily, something like:

_start: 
	push 0
	mov eax, 1
	call syscall

syscall:
	int 80h
	ret

should do the job.


Greetings, J.
     




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040302211919.GA10074>