Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Aug 2001 01:01:39 +0100
From:      Steve Roome <stephen_roome@yahoo.com>
To:        freebsd-hackers@freebsd.org
Subject:   function calls/rets in assembly
Message-ID:  <20010824010139.E365@dylan.home>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010824010139.E365>