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

next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday 02 March 2004 21:19, jan.muenther@nruns.com wrote:
> 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.

In this situation, I can only use a single-byte instruction to push 4 bytes, 
everything else costs me too much space. The only one I know of, is PUSHA, 
but it pushes too many bytes.




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