[net.math] the Register Exchange pro - SPOILER

chongo@nsc.UUCP (10/11/83)

the big problem is how to get one of the output registers (X6 or X7)
out without messing up the output address register (A6 or A7).  the method
below saves the `state' of X7 in memory so that A7 can be moved over X7,
saved and thus make A7/X7 available for pumping out the other registers.

off hand i dont have a Compass manual near, so here is the quazi-C-Compass
description:

TEST.0:	BSS	0	;Start executing here
	if ( X7 < 0 ) {
		JP bit0.on
	} else {
		JP bit0.off
	}

TEST.1:	BSS	1	;Reserve a word for the RJ (return jump)
	if ( X7 < 0 ) {
		JP bit1.on
	} else {
		JP bit1.off
	}

	... and so on ...

TEST.59: BSS	1	;reserve a word for the RJ (return jump)
		if ( X7 < 0 ) {
			JP bit59.on
		} else {
			JP bit59.off
		}


bitx.off and the bitx.on routines look the same, so here is the .on set:

bit0.on:
	Circular shift X7 one bit	;setup X7 for the next test
	RJ	TEST.1			;test the next bit

bit1.on:
	Circular shift X7 one bit	;setup X7 for the next test
	RJ	TEST.2			;test the next bit

	... and so on ...

bit58.on:
	Circular shift X7 one bit	;setup X7 for the next test
	RJ	TEST.59			;test the next bit

bit59.on:
	RJ	DUMP.REG		;we have X7 in memory now


now you can put A7 in X7, send A7 to the 'A7 register save area'. 
now you have both A7 and X7 to send out all the other registers
in a normal fashion.

the last thing you need to do is to reconstruct X7.  what you do is look
at the locations:  TEST.1 ... TEST.59 and DUMP.REG.   at those locations
are the locations stored by the RJ's in the bitx.{off,on} routines.
for say bit 10 of X7, look at the instruction which was stored into
TEST.11 by the RJ instruction.  if it contains an instruction to
jump to bit10.on+1, then bit10 of X7 was a 1 (on).  if TEST.11 contains an
instruction to jump to bit10.off+1 then bit10 of X7 was a 0 (off).

by this method you can rebuild X7 and store it in the X7 register save
area.  now you have saved all the registers!

chongo /\../\

p.s. now you can, using COMPASS DUP and ECHO psuedo-commands make the above
procedure fit onto a tight bit off paper.  (sure the macro expansion is
long, but the source text need not be more than 2 pages).

p.p.s. this is how the dumpreg and restorereg common decks work by the way.