PASS 1
PASS 2
00:000 000000   # SOFTWARE LIBRARY ROUTINES FOR THE UNIVERSAL MACHINE.
00:000 000000   
00:000 000000   # Copyright Tom Jennings 1999-2002, tomj@wps.com
00:000 000000   
00:000 000000   # MRU 2 JULY 2001
00:000 000000   # 25 JAN 2001
00:000 000000   
00:000 000000   # NOTE! THIS PRELIMINARY CODE IS NOT OPTIMALLY CODED!
00:000 000000   
00:000 000000   
00:000 000000   RETURN	EQ	0		# place-holder for return addresses
00:000 000000   POINTER EQ	0		# place-holder for runtime pointers
00:000 000000   VAR	EQ	0		# place-holder for runtime variables
00:000 000000   
00:000 000000   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00:000 000000   # STANDARD JUMP TABLE LOCATION.
00:000 000000   
00:000 000000   	track 0
00:000 000000   	sector 0
00:000 000000   
00:000 225400   start:	jump test		# program entry
00:001 220001   ttyo:	jump ttyo		# (simulated)
00:002 220002   ttyi:	jump ttyi		# (simulated)
00:003 221015   ttyow:	jump ttyowx		# print packed chars
00:004 221000   ttyos:	jump ttyosx		# print string
00:005 221411   ttyod:	jump ttyodx		# print decimal
00:006 222000   ttyoo:	jump ttyoox		# print octal
00:007 220436   multUS:	jump multUx		# mult unsigned single
00:010 220400   multUD:	jump multUDx		# mult unsigned double
00:011 220061   m10:	jump m10x		# single mult by 10
00:012 000000   
00:012 000000   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00:012 000000   	track 0
00:024 000024   	sector 20
00:024 000000   
00:024 000000   ttchar:	VAR			# ttyxx argument
00:025 000000   ttarg:	VAR			# ttyxx argument
00:026 000000   ttopt:	VAR			# ttyxx options
00:027 000000   zschar:	VAR			# zero-suppress
00:030 000000   errno:	VAR			# subr status
00:031 000000   Mper:	VAR			# multiplier
00:032 000000   Mcand:	VAR			# multiplicand or LSW
00:033 000000   Mcandh:	VAR			# multiplicand MSW
00:034 000000   Mtest:	VAR			# mult. routine
00:035 000000   MQ:	VAR			# quotient or LSW
00:036 000000   MQh:	VAR			# quotient MSW
00:037 000000   
00:037 777777   minus1:	-1			# constant
00:040 777772   minus6:	-6			# constant
00:041 000000   
00:041 000066   digtbl:	'0			# table of digits
00:042 000067   	'1
00:043 000063   	'2
00:044 000041   	'3
00:045 000052   	'4
00:046 000060   	'5
00:047 000065   	'6
00:050 000047   	'7
00:051 000046   	'8
00:052 000070   	'9
00:053 000003   	'A
00:054 000031   	'B
00:055 000016   	'C
00:056 000011   	'D
00:057 000001   	'E
00:060 000015   	'F
00:061 000000   
00:061 000000   # ---------------------------------------------------------------
00:061 000000   
00:061 000000   # Unsigned single-precision fixed multiply Mcand by 10.
00:061 000000   
00:061 310072   m10x:	sta m10r
00:062 270032   	ldm Mcand
00:063 200000   	or 0		# clear carry
00:064 070000   	rlc		# times two,
00:065 320032   	sto Mcand	# save that,
00:066 070000   	rlc
00:067 070000   	rlc		# times eight,
00:070 240032   	addm Mcand	# times ten,
00:071 320032   	sto Mcand
00:072 220000   m10r:	jump RETURN
00:073 000000   
01:073 000001   	track 1
01:000 000000   	sector 0
01:000 000000   
01:000 000000   # Unsigned double-precision multiply Mcand by Mper
01:000 000000   # leaving the result in MQ (ls word) and MQh
01:000 000000   # (ms word). Destroys Mcand and Mper. Sets errno
01:000 000000   # if overflow out of MS digit.
01:000 310434   multUDx: sta mdlr
01:001 170000   	and 0
01:002 320035   	sto MQ
01:003 320036   	sto MQh		# initialize
01:004 210001   	ld 1
01:005 000000   
01:005 320034   mdl1:	sto Mtest	# m'per digit tester
01:006 250031   	andm Mper	# test m'per digit
01:007 040000   	snz
01:010 220422   	jump mdl2	# add in Mcand if 1
01:011 270032   	ldm Mcand	# Mcand lo
01:012 240035   	addm MQ		# + MQ lo
01:013 320035   	sto MQ		# = MQ lo
01:014 270033   	ldm Mcandh	# Mcand hi
01:015 230036   	adcm MQh	# + MQ hi + carry
01:016 320036   	sto MQh		# = MQ hi
01:017 000000   
01:017 210000   	ld 0
01:020 230030   	adcm errno	# remember overflow error
01:021 320030   	sto errno
01:022 000000   
01:022 270032   mdl2:	ldm Mcand
01:023 200000   	or 0		# clear carry
01:024 070000   	rlc		# shift multiplicand
01:025 320032   	sto Mcand	# Mcand * 2
01:026 270033   	ldm Mcandh	# double precision
01:027 230033   	adcm Mcandh	# 
01:030 000000   
01:030 270034   	ldm Mtest
01:031 200000   	or 0		# clear carry
01:032 070000   	rlc
01:033 040000   	snz		# if no more bits
01:034 220000   mdlr:	jump RETURN	# done.
01:035 220405   	jump mdl1
01:036 000000   
01:036 000000   
01:036 000000   # Unsigned single-precision multiply Mcand by Mper
01:036 000000   # leaving the result in MQ.  Destroys Mcand.
01:036 000000   # Sets errno if overflow out of MS digit.
01:036 310464   multUx: sta mslr
01:037 170000   	and 0
01:040 320035   	sto MQ
01:041 210001   	ld 1
01:042 000000   
01:042 320034   msl1:	sto Mtest	# m'per digit tester
01:043 250031   	andm Mper	# test m'per digit
01:044 040000   	snz
01:045 220454   	jump msl2	# add in Mcand if 1
01:046 270032   	ldm Mcand	# Mcand
01:047 240035   	addm MQ		# + MQ 
01:050 320035   	sto MQ		# = MQ
01:051 000000   
01:051 210000   	ld 0
01:052 230030   	adcm errno	# remember overflow error
01:053 320030   	sto errno
01:054 000000   
01:054 270032   msl2:	ldm Mcand
01:055 200000   	or 0		# clear carry
01:056 070000   	rlc		# shift multiplicand
01:057 320032   	sto Mcand	# Mcand * 2
01:060 000000   
01:060 270034   	ldm Mtest
01:061 200000   	or 0		# clear carry
01:062 070000   	rlc
01:063 040000   	snz		# if no more bits
01:064 220000   mslr:	jump RETURN	# done.
01:065 220442   	jump msl1
01:066 000000   
01:066 000000   # -------------------------------------------------
01:066 000000   
02:066 000002   	track 2
02:000 000000   	sector 0
02:000 000000   
02:000 000000   # Output a string of packed characters.
02:000 000000   #
02:000 311010   ttyosx:	sta ttysr
02:001 270024   	ldm ttchar		# ptr to string
02:002 000000   
02:002 311003   tts0:	sta tts1		# set string pointer
02:003 270000   tts1:	ldm POINTER		# load text word,
02:004 320024   	sto ttchar
02:005 301007   	lda C+2
02:006 221015   	jump ttyowx		# output one word,
02:007 040000   	snz
02:010 220000   ttysr:	jump RETURN		# exit if end of string
02:011 271003   	ldm tts1
02:012 160001   	add 1			# advance string ptr,
02:013 221002   	jump tts0
02:014 000000   
02:014 000000   # -----------------------------------------------------
02:015 000015   	sector 13		# OPTIMUM 64x5
02:015 311027   ttyowx:	sta ttwr
02:016 270024   	ldm ttchar
02:017 321047   	sto ttwv1		# optimum storage
02:020 211024   	ld ttw1			# reset table ptr,
02:021 000000   
02:021 311023   ttw0:	sta ttwj2
02:022 270024   	ldm ttchar		# A=char,
02:023 220000   ttwj2:	jump POINTER		# jump into table,
02:024 221036   ttw1:	jump ttw3		# LS char,
02:025 221030   	jump ttw2		# 2nd char,
02:026 221030   	jump ttw2		# 3rd char,
02:027 220000   ttwr:	jump RETURN		# return
02:030 000000   
02:030 000000   # Shift right one character, output it.
02:030 100000   ttw2:	sr 0
02:031 100000   	sr 0
02:032 100000   	sr 0
02:033 100000   	sr 0
02:034 100000   	sr 0
02:035 100000   	sr 0
02:036 000000   # Output the LS character, advance the pointer to
02:036 000000   # the next character in the word in ttchar.
02:036 320024   ttw3:	sto ttchar
02:037 301041   	lda C+2
02:040 220001   	jump ttyo		# output a char,
02:041 040000   	snz			# if it was a NULL,
02:042 221027   	jump ttwr		# exit
02:043 271023   	ldm ttwj2		# current table ptr,
02:044 160001   	add 1			# increment,
02:045 221021   	jump ttw0		# loop.
02:046 000000   
02:047 000047   	sector 39		# OPTIMUM 64x5
02:047 000000   ttwv1:	VAR
02:050 000000   
02:050 000000   # -----------------------------------------------------
02:050 000000   
02:050 000000   
02:050 000000   # -----------------------------------------------------
02:050 000000   
03:050 000003   	track 3
03:000 000000   	sector 0
03:000 000000   
03:000 000000   # Output TTARG as a decimal number. Leading zero's are
03:000 000000   # handled according to ZSFLAG: 
03:000 000000   #    '0'   displayed as 0
03:000 000000   #    ' '   displayed as space
03:000 000000   #    0     suppressed.
03:000 000000   # Modifies TTARG, TTCHAR.
03:000 000000   
03:000 474540   ttddk1:	-100000			# table of divisors
03:001 754360   	-10000
03:002 776030   	-1000
03:003 777634   	-100
03:004 777766   	-10
03:005 000000   	0			# end of table marker
03:006 000000   ttzchr:	0			# zero-suppress character
03:007 000000   ttddr:	RETURN			# return address
03:010 000000   ttddr2:	RETURN			# subr return address
03:011 000000   
03:011 321407   ttyodx:	sto ttddr		# save return addr,
03:012 270027   	ldm zschar
03:013 321406   	sto ttzchr		# copy of zero-supp char
03:014 211463   	ld ttdd7		# ptr to decade char output
03:015 321410   	sto ttddr2		# inside loop
03:016 211400   	ld ttddk1		# init ptr to divisors
03:017 000000   
03:017 311421   ttdd0:	sta ttdd1		# top of outer loop,
03:020 311436   	sta ttdd4		# set ptr to current divisor
03:021 270000   ttdd1:	ldm POINTER		# check for end of table
03:022 200000   	or 0			# marked with 0
03:023 030000   	sz
03:024 221432   	jump ttdd2		# jump if more decades,
03:025 000000   
03:025 000000   # Remainder is less than 10; output directly.
03:025 000000   
03:025 271407   	ldm ttddr		# set return from routine
03:026 321410   	sto ttddr2
03:027 270025   	ldm ttarg		# get remainder
03:030 320024   	sto ttchar
03:031 221444   	jump ttdd5		# go output
03:032 000000   
03:032 000000   # Determine quotient/digit by repeated subtraction of
03:032 000000   # the decade divisor.
03:032 000000   
03:032 270037   ttdd2:	ldm minus1		# seed to enter loop
03:033 000000   
03:033 160001   ttdd3:	add 1
03:034 320024   	sto ttchar		# next try
03:035 270025   	ldm ttarg		# the remainder,
03:036 240000   ttdd4:	addm POINTER		# subtract decade,
03:037 050000   	sc
03:040 221444   	jump ttdd5		# until underflow,
03:041 320025   	sto ttarg		# repeat
03:042 270024   	ldm ttchar
03:043 221433   	jump ttdd3		# until it does.
03:044 000000   
03:044 000000   # Underflow -- TTCHAR is number of decades.
03:044 000000   # Output the value in TTARG as a decimal character,
03:044 000000   # but suppressing leading zeroes as indicated. This returns
03:044 000000   # according to previously-set ttddr2.
03:044 000000   
03:044 270024   ttdd5:	ldm ttchar		# decimal value,
03:045 200000   	or 0			# (test it)
03:046 271406   	ldm ttzchr		# output left-fill char
03:047 040000   	snz
03:050 221460   	jump ttdd6a		# if leading zero
03:051 210066   	ld '0			# non-zero value,
03:052 321406   	sto ttzchr		# clear zero-suppress
03:053 270024   	ldm ttchar
03:054 210041   	ld digtbl		# ptr to decimal characters,
03:055 240024   	addm ttchar		# index it,
03:056 311457   	sta ttdd6
03:057 270000   ttdd6:	ldm POINTER		# fetch the character,
03:060 320024   ttdd6a:	sto ttchar
03:061 271410   	ldm ttddr2		# where we return to...
03:062 220001   	jump ttyo		# output character
03:063 000000   
03:063 271421   ttdd7:	ldm ttdd1		# ... here during loop.
03:064 160001   	add 1			# advance divisor table ptr
03:065 221417   	jump ttdd0		# loop.
03:066 000000   
03:066 000000   
04:066 000004   	track 4
04:000 000000   	sector 0
04:000 000000   
04:000 000000   
04:000 000000   # Output ttarg as an octal number.
04:000 312023   ttyoox:	sta ttoor
04:001 270040   	ldm minus6		# oct digits in word,
04:002 320026   	sto ttopt
04:003 270025   	ldm ttarg		# get passed value,
04:004 070000   ttoo1:	rlc			# shift MSB into Cy,
04:005 070000   	rlc			# rotate MS octal digit
04:006 320025   	sto ttarg		# because carry gets lost
04:007 070000   	rlc			# to LS bits
04:010 070000   	rlc
04:011 170007   	and 7
04:012 160041   	add digtbl		# ptr into digit table,
04:013 312014   	sta ttoo2
04:014 270000   ttoo2:	ldm POINTER		# load digit
04:015 320024   	sto ttchar		# setup for call ttyo
04:016 212020   	ld ttoo3
04:017 220001   	jump ttyo		# print digit,
04:020 270026   ttoo3:	ldm ttopt
04:021 160001   	add 1
04:022 040000   	snz			# exit after 6 digits
04:023 220000   ttoor:	jump RETURN
04:024 320026   	sto ttopt
04:025 270025   	ldm ttarg
04:026 070000   	rlc
04:027 222004   	jump ttoo1
04:030 000000   
04:030 000000   
04:030 000000   
04:030 000000   # ----------------------------------------------------------------
04:030 000000   # END of library, start of test code.
04:030 000000   
04:030 000000   
12:030 000012   	track 10
12:000 000000   	sector 0
12:000 000000   
12:000 000000   t1:	text / TIMES /
12:001 062004           4, 16, 6
12:002 050134           28, 1, 5
12:003 000004           4, 0
12:003 000000   t2:	text / IS /
12:004 050604           4, 6, 5
12:005 000004           4, 0
12:005 000000   t3:	text 4, 8, 2
12:006 021004           4, 8, 2
12:007 000000           0
12:007 000000   t4:	text /, OCTAL /
12:010 300454           44, 4, 24
12:011 032016           14, 16, 3
12:012 000422           18, 4, 0
12:012 000000   t5:	text / OVERFLOW!/, 4, 8
12:013 363004           4, 24, 30
12:014 151201           1, 10, 13
12:015 233022           18, 24, 19
12:016 100455           45, 4, 8
12:017 000000           0
12:017 000021   n:	17
12:020 000003   m:	3
12:021 777766   i:	-10
12:022 000000   
12:022 000000   tx1:	text /OK, SO HOW DOES THIS GO? IT IS PROBABLY/, 2, 8, /STILL VERY, VERY SLOW./, 2, 8
12:023 541730           24, 15, 44
12:024 300504           4, 5, 24
12:025 302404           4, 20, 24
12:026 110423           19, 4, 9
12:027 050130           24, 1, 5
12:030 242004           4, 16, 20
12:031 040506           6, 5, 4
12:032 713032           26, 24, 57
12:033 200604           4, 6, 16
12:034 050604           4, 6, 5
12:035 122604           4, 22, 10
12:036 033130           24, 25, 3
12:037 252231           25, 18, 21
12:040 051002           2, 8, 5
12:041 220620           16, 6, 18
12:042 360422           18, 4, 30
12:043 251201           1, 10, 21
12:044 360454           44, 4, 30
12:045 251201           1, 10, 21
12:046 220504           4, 5, 18
12:047 742330           24, 19, 60
12:050 001002           2, 8, 0
12:050 000000   
13:050 000013   	track 11
13:000 000000   	sector 0
13:000 000000   
13:000 000000   # test code
13:000 000000   
13:000 275017   test:	ldm n
13:001 320032   	sto mcand		# multiply this
13:002 320025   	sto ttarg
13:003 170000   	and 0
13:004 320030   	sto errno
13:005 320027   	sto zschar		# suppress leading 0's
13:006 305410   	lda C+2
13:007 221411   	jump ttyodx		# print m'cand
13:010 000000   
13:010 215000   test2:	ld t1
13:011 320024   	sto ttchar
13:012 305414   	lda C+2
13:013 221000   	jump ttyosx		# print " times "
13:014 000000   
13:014 275020   	ldm m
13:015 320031   	sto mper		# by this
13:016 320025   	sto ttarg
13:017 305421   	lda C+2
13:020 221411   	jump ttyodx		# print m'per
13:021 000000   
13:021 215003   	ld t2
13:022 320024   	sto ttchar
13:023 305425   	lda C+2			# "equals"
13:024 221000   	jump ttyosx
13:025 000000   
13:025 305427   	lda C+2
13:026 220400   	jump multUDx		# multiply
13:027 000000   
13:027 270030   	ldm errno		# check for o'flow
13:030 200000   	or 0
13:031 040000   	snz
13:032 225437   	jump mzzz1
13:033 000000   
13:033 215012   	ld t5			# OVERFLOW ERROR!
13:034 320024   	sto ttchar
13:035 305462   	lda done
13:036 221000   	jump ttyosx
13:037 000000   
13:037 270035   mzzz1:	ldm MQ
13:040 320025   	sto ttarg
13:041 305443   	lda C+2
13:042 221411   	jump ttyodx		# print m'per
13:043 000000   
13:043 000000   
13:043 215007   	ld t4
13:044 320024   	sto ttchar		# print "octal"
13:045 305447   	lda C+2
13:046 221000   	jump ttyosx
13:047 000000   
13:047 270035   	ldm MQ
13:050 320025   	sto ttarg
13:051 305453   	lda C+2
13:052 222000   	jump ttyoox		# print octal
13:053 000000   
13:053 215005   	ld t3
13:054 320024   	sto ttchar		# print CR, LF
13:055 305457   	lda C+2
13:056 221000   	jump ttyosx
13:057 000000   
13:057 275017   	ldm n
13:060 160021   	add 17
13:061 060000   	snc
13:062 010001   done:	halt 1
13:063 325017   	sto n
13:064 225410   	jump test2
13:065 000000   
13:065 000000   
13:065 000000   
13:065 000013   	track 11
13:000 000000   	sector 0
13:000 000000   
13:000 000000   
13:000 215022   tex:	ld tx1
13:001 320024   	sto ttchar
13:002 215404   	ld tex2
13:003 221000   	jump ttyosx
13:004 010000   tex2:	halt 0
13:005 000000   
13:005 000000   
13:005 000000   # ---------------------------------------------------------------
13:005 000000   

SYMBOLS
    MSLR=000464      308=000464    TTOPT=000026       22=000026    TTDD0=001417 
     783=001417    TTDD1=001421      785=001421      TEX=005400     2816=005400 
   TTDD2=001432      794=001432    TTDD3=001433      795=001433    TTDD4=001436 
     798=001436    TTDD5=001444      804=001444   MCANDH=000033       27=000033 
   TTDD6=001457      815=001457    TTDD7=001463      819=001463     TTS0=001002 
     514=001002     TTS1=001003      515=001003       MQ=000035       29=000035 
    MDL1=000405      261=000405     MDL2=000422      274=000422     TTW0=001021 
     529=001021     TTW1=001024      532=001024     TTW2=001030      536=001030 
    TTW3=001036      542=001036    START=000000        0=000000  POINTER=000000 
       0=000000   TTDDR2=001410      776=001410     M10R=000072       58=000072 
   TTDDR=001407      775=001407    MTEST=000034       28=000034     M10X=000061 
      49=000061    MZZZ1=005437     2847=005437    TTWJ2=001023      531=001023 
  TTDDK1=001400      768=001400    TTYOD=000005        5=000005   TTYOOX=002000 
    1024=002000     MDLR=000434      284=000434  MULTUDX=000400      256=000400 
  RETURN=000000        0=000000     TTWR=001027      535=001027   MINUS1=000037 
      31=000037    TTYOO=000006        6=000006   TTYOSX=001000      512=001000 
  DIGTBL=000041       33=000041    TTOO1=002004     1028=002004    TTOO2=002014 
    1036=002014   TTYODX=001411      777=001411   MINUS6=000040       32=000040 
   TTOO3=002020     1040=002020    TTYOS=000004        4=000004      VAR=000000 
       0=000000    TTYOW=000003        3=000003    TTWV1=001047      551=001047 
  TTYOWX=001015      525=001015   TTCHAR=000024       20=000024    TTYSR=001010 
     520=001010     DONE=005462     2866=005462        I=005021     2577=005021 
   TTARG=000025       21=000025    ERRNO=000030       24=000030        M=005020 
    2576=005020        N=005017     2575=005017      MQH=000036       30=000036 
   MCAND=000032       26=000032       T1=005000     2560=005000    TTOOR=002023 
    1043=002023   TTZCHR=001406      774=001406       T2=005003     2563=005003 
    MSL1=000442      290=000442       T3=005005     2565=005005   MULTUD=000010 
       8=000010     MSL2=000454      300=000454       T4=005007     2567=005007 
      T5=005012     2570=005012   ZSCHAR=000027       23=000027     TEST=005400 
    2816=005400      TX1=005022     2578=005022     MPER=000031       25=000031 
    TEX2=005404     2820=005404   MULTUS=000007        7=000007     TTYI=000002 
       2=000002   TTDD6A=001460      816=001460   MULTUX=000436      286=000436 
   TEST2=005410     2824=005410     TTYO=000001        1=000001      M10=000011 
       9=000011 