Function calls and returns in OIC


Suppose your multiplication code is to be used as a function, called from some other OIC code. Here's how it's done:
		.data
add_scr:	.space 1		# scratch memory used by add macro
scr:		.space 1		# scratch used by caller
		.text
		...
		add retproto, retaddr, multret, add_scr
		subz scr,scr,mult	# unconditional jump to mult
retaddr:	...			# code that follows the call to mult

retproto:	subz scr,scr,0		# not executed directly

mult:		# start of subroutine -- your multiplication code goes here.
		...
		...
multret:	.space 1	# one word of space to hold return instruction
Here, I am assuming that we have a macro assembler that will assemble the following macro:
add:		.macro a,b,c,scr
		subz scr,scr, next	# scr = 0
		subz scr,a, next	# scr = scr - a = -a
		subz scr,b, next	# scr = scr - b = -a-b
		subz c,c, next		# c = 0
		subz c,scr, next	# c = c - scr = -(-a-b) = a+b
		.endmacro
which translates the function call example code above into
		.data
add_scr		.space 1		# scratch memory used by add macro
		.text
		...
		subz add_scr,addr_scr, next
		subz addr_scr,retproto, next
		subz add_scr,retaddr, next
		subz multret,multret, next
		subz multret,addr_scr, next
		subz scr,scr,mult	# unconditional jump to mult
retaddr:	...			# code that follows the call to mult

retproto:	subz scr,scr,0		# not executed directly

mult:		# start of subroutine -- your multiplication code goes here.
		...
		...
multret:	.space 1	# one word of space to hold return instruction

[ CSE 80 | ACS home | CSE home | CSE calendar | bsy's home page ]
picture of bsy

bsy@cse.ucsd.edu, last updated Wed Oct 16 22:37:38 PDT 1996.

email bsy