[EMAIL PROTECTED] said this stuff:

> > .text
> > .global _start
> > _start:
> >         pushl   $8
> >         pushl   $0
> >         movl    $1, %eax
> >         int     $0x80
> 
> With this suggestion, it always returns 0 instead of 1.
> Shouldn't pushl place 4 bytes on the stack? It translates into the
> instruction 0x6A (pushes only one byte).

32-bit, 80386-based processors cannot push one byte onto the stack; they
can push only in 2- or 4-byte increments (word or double-word).  While
instruction 0x6a pushes an immediate one-byte value, this is only to
save instruction space.  The number is in fact pushed as a 32-bit
("sign-extended") value.

        6a 08

should have the same effect as

        68 08 00 00 00


On freebsd, using a native binary format, the above sample should return
8.  It works properly on any system that i've checked.  I'd be
interested in seeing your compiled binary if yours doesn't.

> BTW, when I assemble it with as(1), there is always an extra
> instruction after my code, and it's a different one each time (and
> it's always one that effectively does nothing). Who ordered that? Is
> it because of alignment constraints in the ELF file?

Each section must be aligned on a 4-byte boundary (this is not specific
to ELF).  This can be duplicated by adding

        .align 4

as the last instruction.  Because the text section is intended for
executable code, as(1) offers non-operation instructions (which should
be unnecessary in any situation where a programmer doesn't know what
he's getting himself into).  Newer versions of gnu as(1) seem to pad
this with zeros, which you can duplicate with:

        .align 4, 0


ari


_______________________________________________
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to