From owner-freebsd-questions@FreeBSD.ORG Tue Mar 2 16:53:01 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 79CC316A4CE for ; Tue, 2 Mar 2004 16:53:01 -0800 (PST) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.176]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0FC2E43D2F for ; Tue, 2 Mar 2004 16:53:01 -0800 (PST) (envelope-from jan.muenther@nruns.com) Received: from [212.227.126.179] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1AyKdA-00018j-00; Wed, 03 Mar 2004 01:53:00 +0100 Received: from [212.202.45.200] (helo=ergo.nruns.com) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1AyKdA-0000wB-00; Wed, 03 Mar 2004 01:53:00 +0100 Received: by ergo.nruns.com (Postfix, from userid 1001) id AC47F7E; Tue, 2 Mar 2004 22:19:19 +0100 (CET) Date: Tue, 2 Mar 2004 22:19:19 +0100 From: jan.muenther@nruns.com To: Daniela Message-ID: <20040302211919.GA10074@ergo.nruns.com> References: <200403022110.50014.dgw@liwest.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200403022110.50014.dgw@liwest.at> User-Agent: Mutt/1.4i X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:9a8a46f2b40f7808f7699def63624ac2 cc: questions@freebsd.org Subject: Re: Strange behaviour in assembly language program X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Mar 2004 00:53:01 -0000 Howdy, > Here it is: > > .text > .global _start > _start: > pushl $0 > movl $1, %eax > int $0x80 > > I looked everywhere (Developer's handbook, Google, ...) to find the solution, > but all resources I consulted tell me this is the right way to do it. > This program, however, always exits with 1 regardless of the value I push. > > Please, can someone tell me that I made a really stupid error? I'm already > pulling my hair out. I sympathize. This has actually cost me quite some nerves as well, before through some debugging and experimentation I found the answer: The kernel expects the first argument 4 bytes below of the current stack pointer, which means you have to put the int 80h call on its own label to get it right. I usually use nasm (hate AT&T syntax, sorry), should translate easily, something like: _start: push 0 mov eax, 1 call syscall syscall: int 80h ret should do the job. Greetings, J.