Date: Wed, 11 Nov 2009 17:32:41 -0800 From: Charlie Kester <corky1951@comcast.net> To: freebsd-questions@freebsd.org Subject: Re: Problems with FreeBSD assembly Message-ID: <20091112013240.GA21567@comcast.net> In-Reply-To: <4AFB13D9.9050507@gmail.com> References: <4AFB13D9.9050507@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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!
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20091112013240.GA21567>