From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <2b03a0ad4af2c6c2f486c13e97a1b9f1@coraid.com> To: 9fans@cse.psu.edu Subject: Re: [9fans] Non-stack-based calling conventions From: Brantley Coile Date: Sat, 16 Feb 2008 18:49:59 -0500 In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Topicbox-Message-UUID: 577ec0e2-ead3-11e9-9d60-3106f5b1d025 >> Early Control Data machines, like many machines >> of the era, used the return address to fine the parameters. >> This meant that you put he parameters in the instruction >> stream right after the call to the subroutine. >> >> Here's the calling convention for your entertainment. >> >> 1) The calling program would put the parameters into memory >> locations just past the call to the subroutine. >> 2) Do a return-jump to the subroutine. This puts the return >> address in the first word of the subroutine and >> begins to execute the second word. >> 3) Parameters are accessed by using and incrementing the >> return address. >> 4) With the return address now safely stored in the first >> word of the subroutine, we can now return to the >> calling routine just by doing a indirect jump thru >> the first word of the routine. >> All this might not make sense to you so here is some code. > > In fact, your explanation made much more sense than the code. To me, of > course. The question of why would anyone devise such a weird scheme of > calling procedures remains. This was the dawn of computer time, and the machines had few registers. The basic Wheeler Jump on the EDSAC, the first operational stored program computer, consisted of loading the address of the parameters following the jump into the accumulator before jumping to the subroutine. With so few registers, it is natural to use the return address to get at both the parameters and figure out where to return. In other words, this is what we did before we figured out a better way. Don't ask about index registers. (add 1 to the instruction and execute it.)