From owner-freebsd-hackers@FreeBSD.ORG Fri Mar 5 15:32:15 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1DF4616A4CE for ; Fri, 5 Mar 2004 15:32:15 -0800 (PST) Received: from ozlabs.org (ozlabs.org [203.10.76.45]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8DF5A43D1D for ; Fri, 5 Mar 2004 15:32:14 -0800 (PST) (envelope-from grog@lemis.com) Received: from blackwater.lemis.com (blackwater.lemis.com [192.109.197.80]) by ozlabs.org (Postfix) with ESMTP id C280B2BD53 for ; Sat, 6 Mar 2004 10:32:11 +1100 (EST) Received: by blackwater.lemis.com (Postfix, from userid 1004) id ADF575121C; Sat, 6 Mar 2004 10:02:09 +1030 (CST) Date: Sat, 6 Mar 2004 10:02:09 +1030 From: Greg 'groggy' Lehey To: Chungwei Hsiung Message-ID: <20040305233209.GO67801@wantadilla.lemis.com> References: <4048CA38.6040203@yahoo.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qjSZefE6w0iW6XmQ" Content-Disposition: inline In-Reply-To: <4048CA38.6040203@yahoo.com> User-Agent: Mutt/1.4.1i Organization: The FreeBSD Project Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-418-838-708 WWW-Home-Page: http://www.FreeBSD.org/ X-PGP-Fingerprint: 9A1B 8202 BCCE B846 F92F 09AC 22E6 F290 507A 4223 cc: freebsd-hackers@freebsd.org Subject: Strange instructions in compiler output (was: A simple question) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Mar 2004 23:32:15 -0000 --qjSZefE6w0iW6XmQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Friday, 5 March 2004 at 13:43:04 -0500, Chungwei Hsiung wrote: > Hello.. > I am super new to this list, and I have a simple question that I don't > know why it does that. I have a simple test program. I compile it, and > gdb to disassemble main. I got the following.. > > 0x80481f8
: push %ebp > 0x80481f9 : mov %esp,%ebp > 0x80481fb : sub $0x8,%esp > 0x80481fe : and $0xfffffff0,%esp > 0x8048201 : mov $0x0,%eax > 0x8048206 : sub %eax,%esp > 0x8048208 : movl $0x804a6ce,0xfffffff8(%ebp) > 0x804820f : movl $0x0,0xfffffffc(%ebp) > 0x8048216 : sub $0x4,%esp > 0x8048219 : push $0x0 > 0x804821b : lea 0xfffffff8(%ebp),%eax > 0x804821e : push %eax > 0x804821f : pushl 0xfffffff8(%ebp) > 0x8048222 : call 0x804823c > 0x8048227 : add $0x10,%esp > 0x804822a : mov $0x0,%eax > 0x804822f : leave > 0x8048230 : ret > > I don't know if at line 5, we move zero to %eax. why do we need to sub > %eax, %esp? why do we need to substract 0 from the stack pointer?? > Any help is really appreciated. This is probably because you didn't optimize the output. You'd be surprised how many redundant instructions the compiler puts in under these circumstances. Try optimizing and see what the code looks like. If this *was* done with optimization, let's see the source code. Greg -- Note: I discard all HTML mail unseen. Finger grog@FreeBSD.org for PGP public key. See complete headers for address and phone numbers. --qjSZefE6w0iW6XmQ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (FreeBSD) iD8DBQFASQ35IubykFB6QiMRArLTAJ9/Bo6t3DihnbzsYo6amWfgJjSBtwCgqQT2 OPwq60Xv3oG52vithVRE++Q= =qAQs -----END PGP SIGNATURE----- --qjSZefE6w0iW6XmQ--