From owner-freebsd-hackers Thu Aug 23 17: 1:47 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from blueyonder.co.uk (pcow024o.blueyonder.co.uk [195.188.53.126]) by hub.freebsd.org (Postfix) with ESMTP id 1FF0E37B405 for ; Thu, 23 Aug 2001 17:01:42 -0700 (PDT) (envelope-from steve@mail.yahoo.com) Received: from mail.yahoo.com ([62.30.71.217]) by blueyonder.co.uk with Microsoft SMTPSVC(5.5.1877.687.68); Fri, 24 Aug 2001 01:01:51 +0100 Received: (from steve@localhost) by mail.yahoo.com (8.11.3/8.11.3) id f7O01ds00868 for freebsd-hackers@freebsd.org; Fri, 24 Aug 2001 01:01:39 +0100 (BST) (envelope-from steve) Date: Fri, 24 Aug 2001 01:01:39 +0100 From: Steve Roome To: freebsd-hackers@freebsd.org Subject: function calls/rets in assembly Message-ID: <20010824010139.E365@dylan.home> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, I'm having some problems with (what ought to be) fairly straightforward assembly, mainly I think, with how FreeBSD (4.3, but does that matter ?) does function calls (which don't work for me!) How exactly should functions work in assembly, afaict, the following C : void printasint(int p) { printf ("print this %d\n", (int)p);} should become : printasint: ## set up stack frame ## is this necessary, it was in the mailing lists ?? ## popl %ebp ## mov %ebp, %edx ## okay, so these two lines shouldn't be necessary either popl %eax pushl %eax ## as they don't do anything (do they, am I missing something??) pushl $.LC0 call printf ## but where do I figure out where to "ret" to ?? ret .endofprintasint: .size printasint,.endofprintasint - printasint Unfortunately, my code dies horribly, with illegal insruction, or somesuch, so I assume I'm returning to never never land, rather than where I was called from (but I'm not really sure how function calls are supposed to be handled, because the stuff that gcc -S comes out with is mad.. e.g. my functions start addl $12, %esp subl $-8, %esp Which if I change to : addl $12, %esp causes a segfault.. (is that obvious, it doesn't seem to be ?) Last time I did any large amount of assembly it was on the ARM, 10 years ago, so please excuse my ignorance, I'm trying !!! Tia, Steve Roome To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message