From owner-freebsd-questions@FreeBSD.ORG Thu Nov 12 01:32:45 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 43CBE1065670 for ; Thu, 12 Nov 2009 01:32:45 +0000 (UTC) (envelope-from corky1951@comcast.net) Received: from QMTA08.westchester.pa.mail.comcast.net (qmta08.westchester.pa.mail.comcast.net [76.96.62.80]) by mx1.freebsd.org (Postfix) with ESMTP id CF50E8FC18 for ; Thu, 12 Nov 2009 01:32:44 +0000 (UTC) Received: from OMTA14.westchester.pa.mail.comcast.net ([76.96.62.60]) by QMTA08.westchester.pa.mail.comcast.net with comcast id 41LC1d0021HzFnQ581Ykhd; Thu, 12 Nov 2009 01:32:44 +0000 Received: from comcast.net ([98.203.142.76]) by OMTA14.westchester.pa.mail.comcast.net with comcast id 41Yi1d00P1f6R9u3a1Yjnq; Thu, 12 Nov 2009 01:32:44 +0000 Received: by comcast.net (sSMTP sendmail emulation); Wed, 11 Nov 2009 17:32:41 -0800 Date: Wed, 11 Nov 2009 17:32:41 -0800 From: Charlie Kester To: freebsd-questions@freebsd.org Message-ID: <20091112013240.GA21567@comcast.net> Mail-Followup-To: freebsd-questions@freebsd.org References: <4AFB13D9.9050507@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <4AFB13D9.9050507@gmail.com> X-Mailer: Mutt 1.5.20 X-Composer: VIM 7.2 User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: Problems with FreeBSD assembly X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Nov 2009 01:32:45 -0000 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!