
Midas assembler=part 1

dsm|			|Dummy symbols
dsm+nds+nds|	dsp,	|Argument pointers
dsp+ndp+ndp+lpa-1|	pd1,	|Public pushdown list
pd1+1|		rqs,	|Repeat character storage
rqs++nrc+lpb-1|	pd2,	|Second public pushdown list
pd2+1|		rce,	|Read character endcheck
rce+1|		tvn,	|Transfer vector origins
tvn+ntv|		cor,	|Constant origins
cor+ncn+ncn+ncn|	vor,	|Variables origins
vor+nvo+nvo|	org,	|Block origin
org+1|		loc,	|Location counter and punch buffer
loc+113|		flx,	|Input character storage
flx+nfw|		ftp,	|Title punch constants
ftp+200|		crl,	|Constant relocation data
crl+ncr|		dsv,	|Argument character storage
dsv+nac+ncc-1|	con,	|Constant list
con+1|		mai,	|Macro storage and index
enm|		low,	|Symbol table end and index

20|

|Start over entry

	tac
	trn so1
	clc
sov,	xx

so1,	ldx (-4

so2,	cyl
	llr one
	trn .+2
	llr mze
	slx tit
	tix so2
	cyl
	com
	trn .+2
	tsx res
	lda inp
	trn .+3
	lda rlp
	sto inp
	llr npa
	tplr np2
	lda pss
	tze ps1
	tra ps4

|Load symbol table

ls,	tac
	llr (4000
	ana
	tze .+2
	tsx res
	tsx rbk
	tsx rbk

ls1,	tsx gwd
	slr sym l
	sto tsm l
	tsx gwd
	slr sym r
	sto tsm r
	tze ls2
	tsx gwd
	sto tvl
	lda tsm l
	trn ls3
	cyl
	trn ls3
	lda tvl		|macro
	add mai
	add (-mai
	sto tvl
ls3,	tsx qq5
	tra ls1

ls2,	tsx rbk

ls4,	tsx gwd
	alr
	ado mai
	axr
	slx 0
	tra ls4

gwd,	sxa gwx
gw2,	ldx t1
	tix gw1
	tsx rbk
	tra gw2

gw1,	sxa t1
	ado gwg
gwg,	lda
	llr (-opr
	anl
gwx,	tra .

rbk,	sxa rbx
	init rbs, loc
	sxa gwg
	r3c
	trn ps3
	r3c+cyl-opr
	alr+xro-opr
	add mon
	sto t1

rbl,	ado rbs
	r3c
rbs,	sto
	lad
	alr
	tix rbl
	r3c+lad-opr
rbx,	tze .
	clc
	alr+hlt-opr
	tra rbk+1

|Restore

res,	sxa rey
	clc
	sto low
	load mai, sto mai
	ldx (dsm-ist-1

re3,	stz sym l
	load tsm l, trn
	llr (-opr
	xac
	add (-nis-nis+1
	tze re4
	trn re2
	lax ist-2
	sto tsm l
	ana
	sto sym l
re4,	tix .+1
re2,	lax ist
	sto tsm r
	ana
	sto sym r
	lax ist+1
	sto tvl
	sxa t0
	tsx vsm
	ldx t0
	tix .+1
	tix re3
rey,	tra .

|Set and reset terminators and indicators

sts,	llx 0
	slr ct
	llx 1
	slr tt
	load bt, tsx ilf
	slr qt
	trx 2

rst,	ldx (rr
	sxa rsx
	load ct, tra c
	load tt, tra tab
	load bt, tra b
	load qt, tra q
	load lt, tra lp
	load rt, tsx ilf
	load bs, tra rsw
	tra rsw+2

rsw,	ldx (rr
	sxa rsx
	stz wrd
	stz amn
	stz asa l
	stz asa r
	stz rlc
	clc
	sto nsm
	move one, def
	move mon, syl
	load psn, lac
	tra rsp+2

rsp,	ldx (rr
	sxa rsx
	stz fct
	stz fcr
	clc
	sto fci
	load fcn, opr
	tra rss+2

rss,	ldx (rr
	sxa rsx
	stz num
	stz dnm
	stz nmr
	stz sym l
	stz sym r
	stz fsm
	stz chc
	move mon, let
	slr liu
rsx,	tra .

|Read and write characters for macro definitions

rr,	tsx rch
cfr,	lda lch
	tsx sqz
	cyl
	add cas
	axo
	lax dtb
	sto cfn
	trn cf1
	add (slr
	trn ich
	add (slr
	trn cf2
	lda mdi		|letters and numbers
	tze cf0
	tsx wch-1
	tsx csk
cf0,	lda cfn
	tra ln

cf2,	lda mdi		|ignored characters
	tze rr
	tsx wch-1
	tsx csk
	tra rr

cf1,	lda mdi		|delimiter
	tze cfx
	lda chc
	tze cfm
	tsx es
	tze cfg
	lax low-1
	llr (opr
	ana
	add (-add
	tze .+2
	tra cfg
	lda num
	add (-tra-dfn
	tze cfd
	add (dfn-ter
	tze cft
	add (ter-ir
	tze cf3
	add (ir-ipe
	tze cf4
cfg,	ldx dsk
	tra cfa

cfb,	tix .+1		|search for dummy symbol
	llr sym l
	lax dsm l
	lpd
	tze cff
cfa,	tix cfb
cf9,	xx		|tra cfm or tsx ilf

cff,	llr sym r	|identify dummy symbol
	lax dsm r
	lpd
	tze .+2
	tra cfa
	load cf9, tra cfm
	xac
	shr
	add (2
cf5,	sto t
	tsx csu
	lda (444444
	tsx wch
	tsx csk
	lda t
	tsx str		|rite dsn
	tsx wch
	tsx csk

cfm,	lda mdi
	add mon
	tze .+2
	tra csx-3
	lda lch
	add (-444004
	tze csc
	add cas
	add (444004-040405	|1
	tze .+3
	tsx wch-1
	tsx csk
	ldx (tra rsw

csx,	sxa csy
	move wc1, wf1	|save indices
	lxr
	lax
	sto wf2
	move wcc, wf3
csy,	tra .

csu,	sxa csv
	move wf1, wc1	|restore indices
	lxr
	lda wf2
	stx
	move wf3, wcc
csv,	tra .

csc,	move lch, t	|upper case
	tsx csx
	tsx rch
	add (-040404	|1
	tze csd
csl,	lda t
	tsx wch
	tsx csk
	tsx csx
	tsx rsw+1
	tra cfr

csd,	tsx rch
	add (-444404
	tze rsw
	tra csl

cfd,	ado mdi		|define
	tra cfm

cft,	lda mdi		|terminate
	add mon
	sto mdi
	tze te5
	tra cfm

csk,	sxa csm
	add low
	add (trn+low-2
	trn csm
	tsx gc
	ldx wc1
	sxa gkg
	xcc
	lad
	axr+com-opr
	add gcs
	sto gks
	tra gke

gkg,	lax
gks,	stx
gke,	tix gkg
	lcc
	add mai
	alr
	add wf1
	sto wf1
	lac
	add wc1
	sto wc1
csm,	tra .

cf3,	add mon
	load cf9, tsx ilf
cf4,	com
	move2 sym, api
	tra cf5

cfx,	clc
cfn,	xx

|Garbage collector

gc,	sxa gcx
	init gcs, mai
	sxa gcg

gc1,	ldx gcg
	xcc+lro-opr
	slr t0
	slr t1
	add mai
	trn gcd
	xcc
	add gcs
	add (-stx
	sto t3
	lax 3		|word count
	sto t2
	ldx low
	tra gcb

gcl,	aux (2
	lax low-1	|search symbol table
	lcd
	tze gca
gcb,	tix gcl

	ldx sbp
	aux (-rce
	llr (17777

gcq,	lax rce		|search pushdown list
	anc
	add t1
	add one
	trn gc3
gck,	tix gcq

	lda rc8
	anc
	add t1
	trn gc4
gc5,	lda t2
	add gcg
	sto gcg
	ldx t0
	tix gc1
	lda t2		|set up copy
	com
	axr+com-opr
	add gcs
	sto gcs
	tra gce

gc3,	add t2
	trn gck
	lda t3		|alter pushdown entry
	adx rce
	stx rce
	stz t0
	tra gck

gc4,	add t2
	trn gc5
	lda t3
	add rc8
	sto rc8
	stz t0
	tra gc5

gcg,	lax		|move macro
gcs,	stx
gce,	tix gcg
	tra gc1

gca,	lax low-3	|check symtab entry
	trn gcb
	cyl
	trn gcb
	stz t0
	lda t3
	adx low-1
	stx low-1
	tra gcb

gcd,	ldx gcs		|end of macros
	xcc
	add mai
	trn sce
	llr mai
	sxa mai
gcx,	tra .

|Dispatch table

i=llr	trr=add

dtb,	i	i	|blank tape
	i	i	|nu
	17	17	|e
	8	i	|8
	i	i	|nu
bt,	xx	i	||
	13	13	|a
	3	i	|3
	tra pls	tra pls	|space
qt,	xx	tra qt	|=:
	35	tra us	|s
four,	4	i	|4
	23	tra ui	|i
	tra pls	tra rr	|+/
	37	tra uu	|u
	2	i	|2
	trr	trr	|c. s.
	tra rl	rt,xx	|.)
	16	16	|d
	5	i	|5
	34	34	|r
	1	tra rr	|1
	24	24	|j
svn,	7	i	|7
thirty,	30	30	|n
ct,	xx	lt,xx	|,(
twenty,	20	20	|f
	6	tra rr	|6
	15	15	|c
	tra min	tra min	|-_
	25	25	|k
	i	i	|nu

	36	36	|t
	i	i	|nu
	44	44	|z
	i	i	|backsp
	26	26	|l
tt,	xx	tra tt	|tab
	41	41	|w
	i	i	|nu
	22	22	|h
crt,	tra tt	tra crt	|car ret
	43	43	|y
	i	i	|nu
	32	32	|p
	i	i	|nu
	33	33	|q
	i	i	|nu
	31	31	|o
	trr	trr	|stop
	14	14	|b
	i	i	|nu
twone,	21	21	|g
	i	i	|nu
	9	tra rr	|
	i	i	|nu
	27	27	|m
	tra rr	tra rr	|upper
	42	tra ux	|x
	i	i	|nu
forty,	40	40	|v
	tra rr	tra rr	|lc
	0	i	|0
	tsx se	tsx se	|argument

|Storage word termination characters (tab and carr ret)

tab,	lda syl
	add one
	add chc
	tze rsw
	tsx evl
	trn ust

tb3,	move mon, pci

tb4,	ado ts
	sto tbc
	lro
	lda pss
	tze tb5
	lda wrd
ts,	xx		|sto loc+
	tsx rck
	trn irw
tb5,	lda rli
	tze tb7
	lda rlm
	anl
	cyr
	cyr
	sto rlm
	trn srw
	lac
	add rlw
	sto rlw

tbn,	ado aml
	ado loc
	llr (77
	ana
	tze t9
	tra bs

tb7,	lac
	trn rci
	tra tbn

pub,	sxa bs		|dump punch buffer
t9,	move rli, syl
	move loc, wrd
	tra pun

tbc,	0

srw,	lac
	add rlw
srt,	xx		|sto loc
	stz rlw
	ado ts
	sto srt
	tra tbn

|Relocation check subroutine.

rck,	sxa rcy
	ldx rlc
	tix .+1
	tix rci
rcr,	ldx rlc
	llx rct
	cla
rcy,	tra .

rci,	clc+lro-opr
	stz rlc
	tra rcy

mze,	-0
rct,	0
	525252

|Location assignment termination character (|).

b1,	move rli, syl
	lda pss
	llr (trn
	tze b3
	tra usb

b,	lda syl
	add one
	add chc
	tze itc
	tsx evl
	lda wrd
	com
	amz
	llr (-17777
	orc
	sto wrd
	stz asm r
	lda nsm
	trn ba2
	move2 asa, asm
	move amn, aml

ba2,	lda def
	tze b1

ba1,	tsx rck
	cry
	trn irb
	move rlc, syl

b5,	llr loc
	lcc
	add wrd
	tze .+2
	tra pun
	lda rli
	com
	add syl
	tze bs

|Punch binary block.

pun,	lda pss
	tze bnp
	lda pch
	tze bnp
	lda tbc
	com
	add rli
	add (sto loc
	tze bnp
	llr loc
	lcc
	sto loc
	lda rli
	tze pu1
	ldx srt
	lda rlw
	stx 0

pu1,	p6s
	lda rim
	llr (lda loc+1
	trn .+2
	load pu2, lda org
	slr pu3
	ado loc
	p6b+com-opr
	p6s+alr-opr
	stz t1

pur,	lda rim
	com
	trn pu2
	lda org
	punch
	ado org

pu2,	xx		|lda loc+
	punch
pu3,	xx
	add t1
	sto t1
	ado pu2
	sto pu3
	com
	add (lda-sto+trn
	add tbc
	trn pur
	lda rim
	trn puc
	lda t1
	com
	punch
puc,	p6s
	p6s

|Form origin for next block

bnp,	lda wrd
	llr (417777
	anl

b3,	slr loc
	stz rlw
	lda syl
	sto rli
	tze .+4
	add (slr-1
	lad
	alo
	slr org
	lda rli
	add (sto loc
	sto ts
	sto srt
	sto tbc
	load rlm, opr
bs,	xx

|Multiply subroutine

mpy,	sxa mpx
	ldx twone
	sto t1
	cla

mp1,	ill
	trn mpa
	ill
mp2,	tix mp1
	cyr
mpx,	tra .

mpa,	ill
	add t1
	tra mp2

|Syllable separation characters

uu,	lda (ora-ana
ui,	add (ana-lpd
us,	add (lpd-tsx-mpy
ux,	add (tsx mpy
	sto t
	lda chc
	tze ilf
	tsx tsy
	lda t
	sto fcn
	move twenty, fci
	add (-add
	trn rss
	stz fci
	tra rss

pls,	lda (lac-lcc
min,	add (lcc
	sto t
	llr chc
	ial
	tze pm1
	tsx evl
	move t, psn
	tra rsp

pm1,	slr psn
	tra rr

|Evaluate product

evl,	sxa evx
	move psn, psa
	slr psb
	tsx tsy
psn,	xx		|product sign: lac or lcc
	add wrd
	sto wrd
psa,	xx
	add amn
	sto amn
	llr fcr
psb,	xx
	add rlc
	sto rlc
	llr pss
	lcc
	add def
	add one
evx,	tra .

|Terminate syllable subroutine

tsy,	sxa tsz
	lda chc
	tze fcn-1
	lda let
	trn es2
	tsx es
	tze tsu
	xac
	sto t2
	lax low-1
	trn esm
	move2 sym, api
	tsx rss+1
	ldx t2
	lax low-1
	add (-add+1
	trn mac
	clc
	trx low+1

esm,	add (-add
	trn tsj
	lda liu
	tze mdv

es1,	ldx t2
	lax low
	tsx erk

es2,	lda nmr
	llr fcr
	sto fcr
	lda fci
	trn ts2
	ldx fci
	lda nmr
	tze tk1
	tix irx
	ial
	tze .+2
	tra irx		|product relocation error
	lda fct
	tra tk3

tk1,	lac
	tze tk4
	tix irx
	llr num
tk3,	tsx mpy
tk4,	sto fcr

ts2,	stz syl
	lda num
	llr fct
fcn,	xx		|factor combination operator
	sto fct
	alr
tsz,	tra .

tsu,	lda liu		|undefined symbol
	trn tsn
	llr pss
	tplr tsn
	ado vct		|variable
	add mon
	sto tvl
	lda sym l
	add (opr
	sto tsm l
	lda sym r
	add (add
	sto tsm r
	tsx vsm

tsn,	move2 sym, lus
	stz def
	stz num
	stz nmr
	tra es2

tsj,	lax low
	trn es1
	cyl
	trn tsn
	tra es1

erk,	llr (opr
	ana-10
	trn .+3
erx,	sto nmr
	trx

	add (-trn
	com
	tra erx

|Relative address syllable (.)

rl,	lda chc
	tze rl1
	move dnm, num
	tra rr

rl1,	move loc, num
	move rli, nmr
	ado chc
	tra rr

|Evaluate symbol (logarithmic search)

es,	sxa esx
	load t2, 6000
	stz num
	ldx low
	aux one

elp,	lda (-opr
ea,	llx low-1	|llr symbol
	anc
	add sym l
	tze eqt
	trn edn

eup,	load e1, xad
	llr t2
	lac+shr-opr
	sto t2
	add mon
	trn esx
	add one
e1,	xx		|xad or xcd
	axr+com-opr
	add low
	com
	trn eup
	xac
	trn elp

edn,	llr (xcd
	tra eup+1

eqt,	llx low
	lda (-opr
	anc
	add sym r
	tze eq2
	trn edn
	tra eup

eq2,	lax low		|sym r
	llx low+1
	slr num
	llx low-1	|sym l
esx,	tra .

|Process alphabetic or numeric character

ln,	add (-12
	trn n
	stz let
	lda cas
	trn ln1
	stz liu

ln1,	ado chc
	add (-4
	tze ln2
	add (trn 4-7
	trn rr
ln4,	llr sym r
	lal
	cyl
	lad
	cyl
	cyl
	cyl
	add cfn
	sto sym r
	lda chc
	add (trn-4
	trn rr
	lda fsm
	cyr
	add lch
	sto fsm
	tra rr

ln2,	move sym r, sym l
	stz sym r
	tra ln4

n,	llr num
	lal
	cyl+lro-opr
	cyl
n1,	xx		|lad or opr
	add cfn
	sto num
	llr dnm
	lal
	cyl+lro-opr
	cyl
	lad
	add cfn
	sto dnm
	ado cfn
	tra ln1

|Parameter assignment routine (equal sign).

q,	lda syl
	tze ipa
	lda let
	trn ipa
	lda liu
	tze ipa
	move2 sym, tsm
	tsx sts
	tsx ilf
	tra qq
	move cas, tvl
	tra rsw

qq,	tsx evl
	trn usq
	lda def
qq9,	tze rst

q1,	tsx rck
	trn irq
	lac
	trn qq1
	add tvl
	cyr
	cyr
	tra qq2

qq1,	llr (opr
	ana
qq2,	move tsm r, sym r
	lad
	sto tsm r
	lda tsm l
	sto sym l
	add (trn
	sto tsm l
	llr wrd

qq4,	slr tvl		|define or redefine symbol
	ldx qq9
qq5,	sxa vsx
	tsx es
	tze vsm+1
	aux (5
	tra vs3

|Address tag routine.

c,	lda loc
	trn rsw
	sto tvl
	tsx ck
	tra rsw
	trn mdt
	tra rsw

|Tag check and define

ck,	sxa ckz
	aux one
	sxa cky
	lda syl
	tze ckp
	lda let		|monos
	trn ckp
	tsx es
	tze ckd
	lax low-1	|sym l
	trn ck1
ckk,	clc
cky,	tra .		|mdt

ck1,	add (-add
	trn ckk		|vari
	lax low+1
	sto wrd
	lax low
	tsx erk
	sto rlc
	tra ckt

ckp,	tsx evl		|polys
	tze usk
	lda def
ckz,	tze .		|polys, not mdt
ckt,	lda wrd
	com
	add tvl
	tze ckr
ckm,	lda syl		|mdt
	trn ckk
	stz sym l
	stz sym r	|kill symbol field in error print
	tra ckk

ckr,	lda rlc		|check reloc
	com
	add rli
	tze .+2
	tra ckm
	lda syl
	tze ckz
ckw,	stz aml
	move2 sym, asm
	cla
	tra cky

ckd,	lda rli		|define tag
	cyr
	add sym r
	sto tsm r
	lda sym l
	add (trn
	sto tsm l
	tsx vsm
	tra ckw

|Enter new symbol and value in symbol table

vsm,	sxa vsx
	lda low
	add (-3
	sto low
	add (low-1
	com
	add mai
	trn .+2
	tsx gc
	ldx low
	aux (3

vs1,	tix vs2
	ldx (3
vs3,	llr tsm l	|symbol with flag bits in tsm
	slx low-6
	llr tsm r
	slx low-5
	llr tvl
	slx low-4
vsx,	tra .

vs2,	aux (2
	lda (-opr
	llx low-3	|symbol
	anc
	add sym l	|no flag bits
	tze vs4
	trn vs3
vs5,	slx low-6
	llx low-2
	slx low-5
	llx low-1
	slx low-4
	tra vs1

vs4,	lda (-opr
	llx low-2
	anc
	add sym r
	trn vs3
	llx low-3
	tra vs5

|Conditionals

if1,	lda mon
if0,	sto npa
	tsx rch
	add (-char lv
	tze ifv
	tsx ilf

ifv,	tsx rch
	llr (tze ift
	add (-char lz
	tze iv1
	llr (trn ift
	add (char lz-char lp
	tze iv1
	tsx ilf

iv1,	slr ivs
	tsx svs
	tsx sts
	tra iv2
	tra iv2
	llr (tra iv3

ivx,	slr bt
	move rqz, ifx
	tra rsw

iv3,	move rqw, ifx
iv2,	tsx evl
	lda def
	tze usi
	lda wrd
	com+lro-opr
	amz
ivs,	xx

iff,	llr one
ift,	lda npa
	lpd+com-opr
	sto npa
	tsx uns
	tra svx
	tsx rss+1
	ado chc
	lda npa
	sto num
ifx,	xx		|tra cfr or rr

start
o