Strange behaviour in assembly language program
Daniela
dgw at liwest.at
Tue Mar 2 21:29:25 PST 2004
On Tuesday 02 March 2004 21:19, jan.muenther at 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.
More information about the freebsd-questions
mailing list