Problems with FreeBSD assembly
David Jackson
djackson452 at gmail.com
Thu Nov 12 15:38:33 UTC 2009
Charlie Kester wrote:
> On Wed 11 Nov 2009 at 17:32:41 PST Charlie Kester wrote:
>
> One more thing:
>
>> Notice that the system call number (or any other dword) should also be
>> pushed onto the stack before the int 80h.
>
> The reason for this is given at the top of the page:
>
> although the kernel is accessed using int 80h, it is assumed the
> program will call a function that issues int 80h, rather than issuing
> int 80h directly.
>
> So the extra dword pushed onto the stack takes the place of the return
> address from the function the kernel expects to have been called.
> And since you're not actually using as a return address, it doesn't
> matter what value it actually has. The kernel doesn't use it for
> anything; it just expects it to be there in a properly arranged stack
> frame.
>
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe at freebsd.org"
The push eax is what made it work. So that was the problem. Stdin and
stdout do not need to opened before they are used, as in C. Thank you
everyone for your help on this, that solved it.
Here is the code that works:
section .data
hello db 'Hello, World!', 0xa
hbytes equ $ - hello
section .text
global _start
_start:
push dword hbytes
push dword hello
push dword 1
mov eax,0x4
push eax
int 0x80
add esp,16
push dword 0
mov eax,0x1
push eax
int 0x80
More information about the freebsd-questions
mailing list