On Wed 11 Nov 2009 at 11:43:21 PST David Jackson wrote:
I am having great difficulty running a very simple assembler program on FreeBSD on x86 in my efforts to learn some assembly programming on FreeBSD. I have tried to compile the following with nasm, however i get nothing in response when I attempt to run this program:


      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
      int 0x80
      add esp,12

      push    dword 0
      mov eax,0x1
      int 0x80

nasm -f elf -o hello1s.o hello1.s
ld -s -o hello1s hello1s.o

./hello1s prints nothing.

What is wrong here? It should print "hello world".  Thanks in advance
for   your help, it is greatly appreciated.

http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86.html

You've seen this part of the handbook, yes?

In particular:

http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86-system-calls.html

Calling your attention to the example code shown just before section 11.3.2, which shows how to open a file:

open:
    push    dword mode
    push    dword flags
    push    dword path
    mov eax, 5
    push    eax     ; Or any other dword
    int 80h
    add esp, byte 16

Notice that the system call number (or any other dword) should also be
pushed onto the stack before the int 80h.

So try this:

        push    dword hbytes
        push    dword hello
        push    dword 1                 ; stdout
        mov     eax,0x4
        push    eax                             ; or any other dword
        int     0x80
        add     esp,16                  ; don't forget to account for the extra 
dword!
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to