From owner-freebsd-questions@FreeBSD.ORG Tue Mar 2 21:29:24 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 EFF2816A4CE for ; Tue, 2 Mar 2004 21:29:24 -0800 (PST) Received: from lilzmailso01.liwest.at (lilzmailso01.liwest.at [212.33.55.23]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8C1D943D1F for ; Tue, 2 Mar 2004 21:29:24 -0800 (PST) (envelope-from dgw@liwest.at) Received: from cm58-27.liwest.at ([212.33.58.27]) by lilzmailso01.liwest.at with esmtp (Exim 4.24) id 1AyOwc-00047m-BC; Wed, 03 Mar 2004 06:29:22 +0100 From: Daniela To: jan.muenther@nruns.com Date: Wed, 3 Mar 2004 06:23:28 +0000 User-Agent: KMail/1.5.3 References: <200403022110.50014.dgw@liwest.at> <20040302211919.GA10074@ergo.nruns.com> In-Reply-To: <20040302211919.GA10074@ergo.nruns.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200403030623.28794.dgw@liwest.at> 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 05:29:25 -0000 On Tuesday 02 March 2004 21:19, jan.muenther@nruns.com wrote: > 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. In this situation, I can only use a single-byte instruction to push 4 bytes, everything else costs me too much space. The only one I know of, is PUSHA, but it pushes too many bytes.