Google
 

Trailing-Edge - PDP-10 Archives - klad_sources - klad.sources/dakdas.mac
There are no other files named dakdas.mac in the archive.
SUBTTL	PDP-10 KA10 CENTRAL PROCESSOR SIMULATOR

;SAVE & RESTORE FIRST 15 ACS ON LIST

DEFINE	SAVE15<
	PUT	15
	MOVEI	15,14
	PUT	(15)
	SOJGE	15,.-1>

DEFINE	RST15<
	HRROI	15,-15
	GET	15(15)
	AOJL	15,.-1
	GET	15>

;ACCUMULATORS

		;1=TEMPORARY
SCAD=2		;SHIFT COUNT ADDER
AD=3		;ADDER
CE=4		;CONTENTS OF E
CAC=5		;CONTENTS OF AC
CAC1=6		;CONTENTS OF AC+1
IR=7		;THE INST SIMULATED
SC=10		;SHIFT CNTR IN RIGHT HALF
FE=10		;FLOAT EXP IN LEFT HALF
MA=11		;18 BIT MA WITH IDX REG, MISC BITS LEFT
PC=12		;18 BIT PC WITH IDX REG, MISC BITS LEFT
BR=13		;36 BIT PSEUDO REGISTERS
AR=14		;36 BIT PSEUDO REGISTERS
MQ=15		;36 BIT PSEUDO REGISTERS
USERAC=16	;FIRST LOC IN OBJECT PROGRAM
BOL=100

;MA SWITCHES

MT=400000	;PRINT MACHINE TIME STATES
MS=200000	;PRINT AT MEM STOP
SU=100000	;STORE IN USER LOC
EXCTF=40000
EUUOF=20000
FMEN=10000
ERR=4000
NRF1=2000
MPF2=100
EXSYNC=1000
RUN=400
DSF7=40
;INITIAL, FINAL SWITCHES

FCE=400000
FCEPSE=200000
FACINH=100000
FAC2=40000
FCCLT=20000
FCCRT=10000
SAC2=4000
SCE=2000
SACINH=1000
SARBR=400
SACZ=200
PCINH=100

;BITS 29-35 IN THE IF TABLE
;INFORM THE PROGRAM WHICH REGISTERS TO PRINT.
;THE NUMBERS HAVE THE FOLLOWING SIGNIFICANCE

;INITIAL PRINT		RESULTS
;0=C(AC)	C(E)			C(E)
;1=C(AC)		C(AC)
;2=C(AC)	C(E)	C(AC)
;3=C(AC)	C(E)	C(AC)		C(E)
;4=C(AC) C(AC+1) C(E)	C(AC) C(AC+1)
;5=C(AC) C(AC+1) C(E)	C(AC) C(AC+1) C(E)
;6=C(AC) C(AC+1) C(E)	      	C(E)
;7=C(AC) C(AC+1)	C(AC) C(AC+1)
;10=C(AC)		-
;11=C(AC)	C(E)	-
;12=C(AC) C(C(ACR)+1	C(AC) C(C(ACR)+1
;13=C(AC) C(C(ACR)	C(AC) C(C(ACR)
;14=C(AC) C(C(ACL)	C(AC) C(C(ACL)
;15=C(AC) C(E) C(C(E)	C(AC)		C(E)
;16=C(AC) C(E) C(C(E))	C(AC) C(E) C(C(E))
;17=C(AC) C(E) C(C(E)	C(AC)		C(E)
;20=DON'T PRINT
DEFINE	INDEX<
	HLRZ	IR		;INDEX REGISTER TO AR
	ANDI	17
	ADD	USERAC
	SKIPN	USERAC
	ADDI	JA
	PUT	0
	ANDI	0,-1
	MOVE	AR,@0
	GET	0
>

DEFINE	FMRQA(A)<
	MOVE	ACA#		;MEM READ AC
	ADDI	A
	ANDI	17
	ADD	USERAC
	SKIPN	USERAC
	ADDI	JA
	PUT	0
	ANDI	0,-1
	MOVE AR,@0
	GET	0
>

DEFINE	FMWRA (A)<
	MOVEM	AR,CAC+A	;WRITE AC INTO CORE
	TLNN	MA,SU
	JRST	.+13
	MOVE	ACA#
	ADDI	A
	ANDI	17
	ADD	USERAC
	SKIPN	USERAC
	ADDI	JA
	PUT	0
	ANDI	0,-1
	MOVEM	AR,@0
	GET	0
>
DEFINE	STORE (A)<
	GO	HUNGCK
	JUMPGE	MA,.+3		;PRINTER CNTL
	MOVEI	1,[ASCII /A/]
	GO	PRINTA
>

DEFINE	STORM (A)<
	GO	HUNGCK
	TLNN	MA,MS+MT	;PRINTER CNTL
	JRST	.+3
	MOVEI	1,[ASCII /A/]
	GO	PRINTA
>

DEFINE	IFSWIT<
	HLRZ	2,IR		;GET INITIAL AND FINAL SWITCHES
	LSHC	2,-^D10
	TLNE	3,400000
	SKIPA	2,IFTAB(2)	;ODD
	MOVS	2,IFTAB(2)	;EVEN
>
MCRQ1:	MOVE MA			;MEMORY READ REQUEST
	ADD	USERAC
	JUMPN USERAC,.+3
	TRNN MA,777700
	ADDI JA			;IF LESS 100,JOB AREA
	PUT	0
	ANDI	0,-1
	MOVE AR,@0
	GET	0
	MOVE CE,AR
	RTN

MCWR1:	MOVEM AR,CE		;MEMORY WRITE REQUEST
	TLNN MA,SU		;STORE IN USER ONLY IF
	RTN			;SU SWITCH IS SET

	MOVE MA
	ADD	USERAC
	JUMPN USERAC,.+3
	TRNN MA,777700
	ADDI JA
	PUT	0
	ANDI	0,-1
	MOVEM AR,@0
	GET	0
	RTN

OPDEF	MCRQ [GO	MCRQ1]
OPDEF	MCWR [GO	MCWR1]
;SIMULATE INSTRUCTION TIME CYCLE

;INSTRUCTION AND ADDRESS CALL CYCLE

IT0:	SETZB SC,ADBREN#	;CLEAR SC AND AD BR + OR - EN FLAG.
	SETZB MQ,IR		;MQ AND IR CLR.
	SETZM	AF2#		;CLR AF2.
	SETZM	FDF3#		;CLEAR FDF3.
	SETZM	FXUHLD#		;ECO49, CLEAR AR FXU HOLD
	SETZM	BISF#		;FIX FOR BIS SET ON BYTE START
	TLZ MA,NRF1+MPF2+DSF7	;CLEAR NRF1,MPF2,DSF7
	TLNN MA,EXCTF		;EXCTF(0)?
	HRRM PC,MA		;YES...MA FM PC(J)
	TLNE MA,EUUOF		;EUUOF(1)?
	TRO MA,1		;YES...MA 35 SET
	MCRQ			;MC RD RQ
	STORM IT0
	PUT	MA
IT1:	HLL IR,AR		;INST TO IR
	TRZ MA,-1		;CLEAR MA
	TLZ MA,EXCTF+EUUOF	;CLEAR EXCTF AND EUUOF
	STORE IT1
	TLNN IR,17		;IR 14-17 = 0?
IOTT1E:	JRST AT3		;YES...NO INDEX REGISTER
AT1:	SETOM AF2#		;SET AF2#
	MOVE BR,AR		;BR FM AR(J)
	SETZ AR,		;CLEAR AR
	STORE AT1
AT2:	INDEX
	TLNN MA, FMEN		;IS FAST MEMORY ENABLED
	JRST AT2A		;NO
	STORE AT2
	JRST AT3

AT2A:	STORM AT2

AT3:	MOVE AD,AR		;AD AR+EN
	ADD AD,BR		;AD BR+EN
	SKIPE AF2#		;AF2 SET?
	HRR AR,AD		;YES. ARRT FM AD(J)
	SETZM AF2#		;CLEAR AF2
	MOVE BR,AR		;BR FM AR(J)
	TLZ AR,-1		;AR LT CLR
	STORE AT3
	TLNN IR,20		;INDIRECT BIT ON?
	JRST AT6		;NO.

AT4:	HRRM AR,MA		;MA FM AR(J)
	MCRQ			;THE IN DIRECT LOGIC
	HLLZ AR
	TLZ 777740
	TLZ IR,37
	IORM IR
	STORM AT4
	JRST IT1+1
AT6:	TLNE IR,700000		;IR UUO?
	HRR MA,AR		;-IR UUO: MA FM AR(J)
	STORE AT6
	CAMGE IR,[140000000000]	;IR 134-137?
	CAMG IR,[133777777777]
	JRST FT0X

BYTCR1:	TLZ IR,37		;IR RT CLR.
	SKIPN	BISF		;BISF (2ND PART BYTE FIX) SET?
	JRST FT0X		;NO. FIRST TIME THROUGH BYTE.
	MOVEI 2,FACINH+FCE+3	;YES. SECOND TIME THROUGH BYTE.
	TLNE IR,2000
	MOVEI 2,FCE+SACINH+SCE+3	;DPB...TURN OFF FACINH.
	JRST FT0Y

;END OF ADDRESS CYCLE
;AR=0,E
;BR=LAST REF
;MQ=0
;MA=0 OR E
;FETCH CYCLE
FT0X:	HLRZ	IR
	LSH	-11
	MOVEM	IRA#		;SAVE INSTRUCTION CODE.
	CAIGE	200		;IS THIS
	CAIGE	140		;A FP INST?
	JRST	FT0XA		;NO.
	ANDI	145		;YES.
	CAIN	145		;IS IT IMMEDIATE MODE?
	JRST	FT8		;YES..FPIMM..GO TO FT8.
FT0XA:	IFSWIT
FT0Y:	TRNN 2,FCE+FCEPSE
	JRST FT1A		;DO NOT FETCH C(E)
	MCRQ			;GET THE CONTENTS OF E
	TLNE MA,FMEN		;MC FM EN?
	JRST FTX		;YES...FT1

FT1:	STORM FT0;		FCE OR [FCEPSE + (-FMEN)]
	JRST FT1A
FTX:	STORM FT1;		FCEPSE+FMEN
FT1A:	MOVE	0,IRA#		;MOVE INST CODE INTO AC0.
	CAIE 0,254		;IR A JRST?
	MOVE BR,AR		;NO. BR FM AR(J).
	STORE FT1A
	HLRZ	0,IR
	LSH	0,-5
	ANDI	0,17
	MOVEM	0,ACA#		;SAVE AC NUMBER.
	TRNE	2,FACINH
	JRST FT9		;FETCH AC INHIBIT IS SET
;AR=0,E
;BR=(0,E) V C(E) V JRST:LAST REF
;MQ=0
;MA=E
;FETCH CYCLE CONT

FT2:	SETZ AR,		;AR CLR
	STORE FT2
	FMRQA 0
	TLNE MA,FMEN		;MC FMEN?
	JRST FT2X		;YES.
	STORM	FT2RQ
FT2X:	STORE FT3

;AR=C(AC)
;BR=(0,E) V C(E)
;MQ=0
;MA=E

FT2Y:	TRNN 2,FAC2+FCCLT+FCCRT
	JRST FT9		;-(FAC2 V FCCACLT V FCCACRT)
	TRNN 2,FAC2
	JRST FT6		;-FAC2
FT4:	MOVE MQ,AR		;MQ FM AD(J)
	SETZ AR,		;AR CLR
	STORM FT4
	FMRQA 1
FT4Y:	TLNN MA,FMEN		;MC FMEN?
	JRST FT4X		;NO.
FT5:	STORM FT5
	JRST FT4A
FT4X:	STORM	FT4RQ

FT4A:	EXCH AR,MQ		;MQ FM AD(J), AR FM MQ(J)
	STORE FT4A
	JRST FT9
;FETCH CONT

FT6:	TRNN 2,FCCLT		;FCCACRT?
	JRST FT7		;YES...POP,POPJ
	ROT AR,^D18		;AR SWAP
	STORE FT6

FT7:	HRRM AR,MA		;MA FM AR(J)
	MOVE MQ,AR		;MQ FM AR(J)
	MCRQ			;MC RD RQ
	STORM FT7
	JRST FT4Y

FT8:	MOVS  AR,AR		;IR FPIMM...AR SWAP.
	STORM FT8
	JRST FT0XA


FT9:	TRNN	2,PCINH		;PC+1 INHIBIT ON?
	HRRI PC,1(PC)		;NO. PC+1
	STORE FT9

;AR=C(AC) V C(AC) SWAPPED V (0,E) V C(E)
;BR=(0,E) V C(E) V JRST: LAST REF
;MQ=0 V C(AC2) V C(C(ACLT) V C(C(ACRT)
;MA=E V C(ACLT) V C(ACRT)
;EXECUTE CYCLE DISPATCH TO THE INSTRUCTION

GROUP:	HLLZ 1, IR
	LSHC 1,-^D33
	LSHC 2,-^D33
	LSH 3,-^D33
	JRST @GROUPD(1)

GROUPD:	XWD 0,UUOSIM		;UU0
	CAI @IR100(2)
	CAI @MISDIS(2)		;MOVE, MISC, SUBROUTINE
	XWD 0,SKIPJC		;SKIP JUMP COMPARE
	XWD 0,BOOLE		;BOOLE
	XWD 0,HALF		;HALF WORD
	XWD 0,TEST		;AC BIT TEST
	XWD 0,OP700		;IN OUT

MISDIS:	XWD 0,FWT		;MOVE MOVS
	XWD 0,FWTN		;MOVN MOVM
	XWD 0,SMUL		;MULTIPLY
	XWD 0,SDIV		;DIVIDE
	XWD 0,SHROT		;SHIFT ROTATE + JFFO
	CAI @IR250(3)		;MISC
	CAI @IR260(3)		;SUBROUTINE
	XWD 0,ADDSUB		;ADD SUB

IR250:	XWD 0,EXCH3		;DISPATCH TO
	XWD 0,BLTS		;IR 250 IR 257 CODES
	XWD 0,AOBJX
	XWD 0,AOBJX
	XWD 0,JRSTS
	XWD 0,JFCLS
	XWD 0,XCTS
	XWD 0,OP257

IR260:	XWD 0,PUSHJS		;DISPATCH TO SUBROUTINE
	XWD 0,PUSHS		;CALLING AND RETURNING
	XWD 0,POPJS		;INSTRUCTIONS
	XWD 0,POPJS
	XWD 0,JSRS
	XWD 0,JSPS
	XWD 0,JSAS
	XWD 0,JRAS

IR100:	XWD 0,INSNC		;IR 100 TO 177
	XWD 0,INSNC
	XWD 0,INSNC
	XWD 0,SBYTE		;BYTE,FSC,UFA,DFN
	XWD 0,SFAD
	XWD 0,SFSB
	XWD 0,SFMP
	XWD 0,SFDV
;STORE CYCLE

	SKIPA 2,[XWD 0,-1]
SS9:	SETO 2,
	JRST XSS9
ST0:	STORE ST0
ST1:	IFSWIT
	TRNN 2,SACZ		;STORE AC
	JRST .+3		;ON SELF MODE INST
	TLNN IR,740
	TRO 2,SACINH

XSS9:	MOVE 0,ACA#
	ADD	USERAC
	SKIPN	USERAC
	ADDI	JA
	PUT	0
	ANDI	0,-1
	PUT	@0
	MOVE CAC,@0		;C(AC)
	GET	0
	MOVE 0,ACA#
	ADDI 1
	ANDI	17
	ADD	USERAC
	SKIPN	USERAC
	ADDI	JA
	PUT	0
	ANDI	0,-1
	MOVE CAC1,@0		;C(AC+1)
	PUT	@0
	GET	0

	CAMN	2,[-1]
	JRST	XSS91

	MOVE MA
	ADD	USERAC
	JUMPN	USERAC,.+3
	TRNN 777700
	ADDI JA
	PUT	0
	ANDI	0,-1
	TRNE 2,SCE+FCEPSE
	MOVE CE,@0		;C(E)
	GET	0
XSS91:	PUT	CE
	MOVE 0,IRA#
	CAIGE 0,140
	CAIG 0,133
	CAIA
	TRZ 2,FCEPSE
	CAIE 2,-1
	CAMN 2,[-1]
	JRST ST99
	TRNE 2,SACINH
	JRST ST1A
	CAIN 0,130		;IR UFA?
	JRST ST1D		;YES...FMA AC2 SET
	CAIN	0,243		;IR JFFO ?
	JRST ST1D		;YES...FMA AC2 SET

	FMWRA 0
	JRST ST1E

ST1D:	FMWRA 1
ST1E:	STORM ST1
ST1A:	TRNE 2,SAC2+SCE+FCEPSE+SARBR
	JRST ST1B
	TLNN MA,FMEN
	TRNE 2,SACINH
	JRST .+2
	JRST ST1B
	STORE ST1A
	JRST ST9

ST1B:	TLNE MA,FMEN
	JRST ST1C
	TRNN 2,SACINH
	JRST ST2		;GO ST2 FMEN(0) SACINH(0)

ST1C:	TRNN 2,SARBR+SAC2	;SACINH OR
	JRST ST1F		;FM(1) AND NOT SARBR OR SAC2
	TRNE 2,SCE+FCEPSE	;SACINH OR
	HALT	.		;FM(1) AND SCE OR FCEPSE

ST2:	TRNE 2,SARBR		;SAR NE BR?
	MOVE AR,BR		;YES..AR FM AD(J) ; BR
	STORE	ST2
	TRNN	2,SAC2+SCE+FCEPSE+SARBR
	JRST	ST9
	TRNN 2,SCE+FCEPSE+SARBR
	JRST	ST7
	TRNE	2,SARBR
	JRST	ST3
	TRNN 2,FCEPSE
	JRST	ST6
ST5:	MCWR			;STORE PAUSE CYCLE
	STORM ST5
ST6A:	STORE ST6A
	TRNN 2,SAC2
	JRST ST9
ST7:	MOVE AR,MQ		;AR FM MQ(J)
	STORE	ST7
ST8:	FMWRA 1
	STORM ST8
	JRST ST9
ST2B:	TRNN 2,SCE
	JRST ST2C
ST6:	MCWR			;MEM WRITE
	STORM ST6
	JRST ST6A
ST2C:	TRNN 2,SARBR
	JRST ST2D
ST3:	STORE ST3
	TRNN 2,FCEPSE
	JRST ST6
	JRST ST5

ST2D:	TRNN 2,SAC2
	JSP 1,SIMER		;SIMULATE ERROR
	TRNN 2,SCE+FCEPSE+SARBR
	JRST ST7
	JSP 1, SIMER

ST1F:	TRNE 2,FCEPSE
	JRST ST5
	TRNE 2,SCE
	JRST ST6
	JRST SIMER

ST99:	CAIE 2,-1
	JRST ST9
	MCWR
ST9:	STORE ST9
ST9E:	GET	3
	GET	2
	GET	1
	GET	0
	RTN

SIMER:	TLO MA,ERR		;SIMULATE ERROR
	JRST ST9E
;FULL WORD TRANSFERS 20X AND 21X CODE

FWT:	TLNE IR,4000		;MOVE OR MOVS
	ROT AR,^D18		;MOVSX...AR RM AR SW(J)
FWTET0:	STORE ET0
	JRST ST1

FWTN:	TLNE IR,4000		;MOVN OR MOVM
	JUMPGE AR,FWTET0	;MOVM AND AR POSITIVE
	JFCL 17,.+1
	SETCM AD,AR		;AD AR-EN SET
	ADDI AD,1		;AD CRY36 SET
	MOVE AR,AD		;AR FM AD(J)
MTF:	JOV MOV
	JCRY1 MCRY1
	JCRY0	MCRY0
	JRST FWTET0

MOV:	TLO PC,AROV
	JRST MTF+1
MCRY1:	TLO PC,CRY1
	JRST MTF+2
MCRY0:	TLO PC,CRY0
	JRST FWTET0

;INSTRUCTIONS NOT YET CODED
INSNC:	STORE NC
	JRST ST1

;SIMULATE UUO'S

UUOSIM:	HLL	AR,IR		;ARLT FM IR0-12(1)
	TLO	MA,EXCTF+EUUOF	;EXCTF AND EUUOF SET
	TRO	MA,40		;MA 30 SET
	MOVEM	AR,OFFSET+40	;PATCH FOR UUO'S
	JRST FWTET0		;YES. PRINT ET0..GO TO ST1
;OP CODE 250 EXCH

EXCH3:	ROTC BR,^D36		;AR FM AD(J), BR FM AR(J)
	JRST FWTET0		;PRINT ET0..GO TO ST1



;OP CODE 252 AND 253 AOBJX

AOBJX:	JSP	2,PUSET0	;AD AR+EN,AD+1 BOTH
	MOVE AR,AD		;AR FM AD(J)
	TLNE IR,1000
	JUMPL AR,AOBJJ		;AOBJN AND AD0(1)
	TLNN IR,1000
	JUMPGE AR,AOBJJ		;AOBJP AND AD0(0)
	JRST FWTET0		;PRINT ET0...GO TO ST1

AOBJJ:	HRR PC,MA		;PC FM MA(J)
	JRST FWTET0		;PRINT ET0...GO TO ST1

JRSTS:	MOVEM PC,TEMP#
	HRR	PC,MA		;MA FM PC(J)
	HRR	MA,TEMP#	;PC FM MA(J)
	TLNE IR,40		;IR12(1)?
	TLO MA,EXSYNC		;YES...SET USER MODE BIT
	TLNE IR,200		;IR10(1)?
	TLZ MA,RUN		;YES..HALT INSTRUCTION..(CLR RUN)
	TLNE IR,400		;IR9(1)?
	TLZ MA,0		;YES..RELEASE PI CHANNEL
	TLNN IR,100		;IR11(1)?
	JUMPA JRSET0
	TLZ PC,770140		;YES..AR FLAGS FM BR(J)
	MOVSI 770140
	AND BR
	IORM PC
JRSET0:	STORE ET0
	JUMPA ST1
;OP COPE 255 JFCL

JFCLS:	SETZ
	TLNE IR,40		;IR BIT 12(1)?
	TLZN PC,FOV		;YES. CLEAR FOV AND SET
	CAIA			;AC0 FOR PC TRANSFER
	SETO			;IF FOV WAS SET.
	TLNE IR,100		;IR BIT 11(1)?
	TLZN PC,CRY1		;YES. CLEAR CRY1 AND SET
	CAIA			;AC0 FOR PC TRANSFER
	SETO			;IF CRY1 WAS SET
	TLNE IR,200		;IR BIT 10(1)?
	TLZN PC,CRY0		;YES. CLEAR CRY0 AND SET
	CAIA			;AC0 FOR PC TRANSFER
	SETO			;IF CRY0 WAS SET
	TLNE IR,400		;IR BIT 9(1)?
	TLZN PC,AROV		;YES. CLEAR AROV AND SET
	CAIA			;AC0 FOR PC TRANSFER
	SETO			;IF AROV WAS SET.
	SKIPGE			;IF AC=0 NO PC TRANSFER
	HRR PC,MA		;PC FM MA(J)
	JRST FWTET0		;PRINT ET0..GO TO ST1

;OP CODE 256 XCT

XCTS:	TLO MA,EXCTF		;SET A FLOP TO INH PC TO MA
	JRST FWTET0		;PRINT ET0...GO TO ST1

;OP CODE 257 NOT PRESENTLY USED

OP257:	JRST ST1
;OP CODE 260,261 PUSH,PUSHJ

PUSHJS:	JSP 2,PUSET0		;AD AR+EN, AD+1 BOTH
	SKIPGE 1		;AD CRY0?
	SETOM	PDLOVW#		;YES. CPA PDLOV SET
	MOVE AR,PC		;AR FM PC,FLAGS(J)
	TLZ PC,BIS		;CLEAR BIS
	MOVE MQ,AD		;MQ FM AD(J)
	HRR PC,MA		;PC FM MA(J)
	STORE	ET0
	MOVE BR,AR		;BR FM AR(J)
	MOVE AR,MQ		;AR FM MQ(J)
	STORE ET1
	HRR MA,AR		;MA FM AR(J)
PUSET2:	STORE ET2
	JRST ST1
PUSHS:	JSP 2,PUSET0		;PUSH
	SKIPGE	1
	SETOM	PDLOVW		;CPA PDLOV SET
	MOVE AR,AD		;AR FM AD(J)
	STORE	ET0
	HRR MA,AR		;MA FM AR(J)
PUSET1:	STORE ET1
	JRST ST1

PUSET0:	MOVE	1,AR
	MOVE AD,AR		;AD AR+EN SET
	ADD	AD,[1000001]	;AD+1 BOTH
	XOR	1,AD
	JRST (2)
;OP CODE 262,263 POP,POPJ

POPJS:	MOVE AD,AR		;AD AR+EN SET
	ADD AD,[-1]		;AD BR + AND - EN
	SUB AD,[1000000]	;AD-1 LH SET
	XOR AR,AD
	SKIPGE AR		;-AD CRY0?
	SETOM	PDLOVW		;YES. SET CPA PDLOV.
	MOVE AR,MQ		;AR FM MQ(J)
	MOVE MQ,AD		;MQ FM AD(J)
	STORE ET0
	TLNN IR,1000
	JRST POPS		;A POP INSTRUCTION

POPJS1:	HRR MA,AR		;MA FM AR(J)
	MOVE AR,MQ		;AR FM MQ(J)
	STORE ET1
	HRR PC,MA		;PC FM MA(J)
	JRST PUSET2		;PRINT ET2..GO TO ST1

POPS:	EXCH AR,BR		;AR FM AD(J), BR FM AR(J)
	STORE ET1
	HRR MA,AR		;MA FM AR(J)
	MOVE AR,MQ		;AR FM MQ(J)
	JRST PUSET2		;PRINT ET2..GO TO ST1
;OP CODE 264 JSR

JSRS:	MOVE AR,PC		;ARRT FM PC(J),ARLT FLAGS(J)
	TLZ PC,BIS		;CLEAR BIS
	HRR PC,MA		;PC FM MA(J)
	STORE ET0
	HRRI PC,1(PC)		;PC+1
	JRST PUSET2		;PRINT ET2..GO TO ST1

;OP CODE 265 JSP

JSPS:	MOVE AR,PC		;ARRT FM PC(J),ARLT FM FLAGS(J)
	TLZ PC,BIS		;CLEAR BIS
	HRR PC,MA		;PC FM MA(J)
	JRST FWTET0		;PRINT ET0..GO TO ST1


;OP CODE 266 JSA

JSAS:	MOVE BR,AR		;BR FM AR(J)
	HRR AR,PC		;ARRT FM PC(J)
	HRR PC,MA		;PC FM MA(J)
	STORE ET0
	HRL AR,AR		;ARLT FM ARRT(J)
	HRR AR,PC		;ARRT FM PC(J)
	STORE ET1
	HRRI PC,1(PC)		;PC+1
	MOVSS	AR		;AR SWAP
	JRST PUSET2		;PRINT ET2..GO TO ST1
;OP CODE 267 JRA

JRAS:	MOVE AR,BR		;AR FM AD(J)
	STORE ET0
	HRR MA,AR		;MA FM AR(J)
	MOVE AR,MQ		;AR FM MQ(J)
	STORE ET1
	HRR PC,MA		;PC FM MA(J)
	JRST PUSET2		;PRINT ET2..GO TO ST1


;CODE 270 ADD SUB

ADDSUB:	JFCL 17,.+1		;CLR ALL FLAGS
	MOVE AD,AR
	TLNE IR,4000		;IR SUBTRACT?
	SUB AR,BR		;YES.
	TLNN IR,4000		;IR ADD?
	ADD AR,BR		;YES.
ASTF:	JOV ASOVS
	JCRY1 ASCRY1
	JCRY0 ASCRY0
	JRST FWTET0		;PRINT ET0..GO TO ST1

ASOVS:	TLO PC,AROV
	JRST ASTF+1
ASCRY1:	TLO PC, CRY1
	JRST ASTF+2
ASCRY0:	TLO PC,CRY0
	JRST FWTET0		;PRINT ET0..GO TO ST1
;EXECUTE CYCLE 3XX CODES SKIP, JUMP, CAM

SKIPJC:	SETZ	0,

	EXCH	0,IRA
	CAME	0,[SOS_-^D27]
	JRST	.+3
	SOS	AR		;BUG FIX FOR FLAGS ON SOS
	JRST	ASTF1
	CAME	0,[SOJ_-^D27]
	JRST	.+3
	SOJ	AR,		;BUG FIX FOR FLAGS ON SOJ
	JRST	ASTF1

	EXCH	0,IRA
	SETCM	AD,AR
	HLRZM IR,2		;AC 2 = DISPATCHER
	LSH 2,-^D13
	MOVEI 1,1
	TLNE IR, 60000		;IS IT A JUMP INSTRUCTION
	TLNE IR,10000
	SETZ 1,			;NO A SKIP
	XCT SJCTAB-14(2)	;ADD, SUBTRACT, OR DO NOTHING
	SETCMM AD		;RESTORE NUMBERS
	PUT	AD
	CAMGE IR,[XWD 320000,0]
	JRST	KM3

KM:	TLNE	AD,400000
	SETO	0,
	JFCL	17,.+1
	ASH AD,^D36		;SET OV IF NOT ZERO
	MOVE AD,(P)
	TLNE IR,1000
	JRST	KM2
KM1:	TLNN IR,2000
	JRST PCSK+1
	JOV .+2
PCSK:	SETCA 1,		;IR7(1) AND AD=0
	TLNN IR,4000
	SETCA 1,		;NEGATE SKIP ACTION ON IR6
	EXCH	0,IRA
	CAMN	0,[CAML_-^D27]	;BUG FIX FOR MAX POS AND MAX NEG # COMP
	JRST	CAMSK0
	CAMN	0,[CAMLE_-^D27]
	JRST	CAMSK1
	CAMN	0,[CAMG_-^D27]
	JRST	CAMSK2
	CAMN	0,[CAMGE_-^D27]
	JRST	CAMSK3
	CAMN	0,[CAMN_-^D27]
	JRST	CAMSK4
	CAMN	0,[SKIPN_-^D27]
	JRST	CAMSK5
	XCT STAB(1)
PCSK1:	EXCH	0,IRA
	TLNN IR,60000
	JRST SJCET0-1		;A CAM OR CAI INST
	XOR AD,AR
	TLNE AD,400000		;FIX UP
	TLO PC,CRY0		;THE CRY0
	TLNE AD,200000		;AND CRY1 FLAGS
	TLO PC,CRY1		;FOR THE SKIP/JUMP
	GET	AR		;INST AD GOES TO AR
SJCET0:	JRST FWTET0		;PRINT ET0..GO TO ST1
ASTF1:	EXCH	0,IRA
	JRST	ASTF

KM2:	SKIPE 0
	JRST	PCSK
	JRST KM1

KM3:	TLNE AD,400000
	JRST KM4
	JCRY0	.+3
	JCRY1	KM+1
	JRST	KM+2
	JCRY1	KM+2
	JRST	KM+1

KM4:	JCRY0	.+3
	JCRY1	KM+2
	JRST	KM+1
	JCRY1	KM+1
	JRST	KM+2
	ROT
	ROT
STAB:	HRRI PC,1(PC)
	HRR PC,MA
SJCTAB:	ADD AD,BR
	ROT
	SUBI AD,1
	ADDI AD,1

CAMSK0:	CAML	AR,BR
	JRST	PCSK1
	AOS	PC
	JRST	PCSK1

CAMSK1:	CAMLE	AR,BR
	JRST	PCSK1
	AOS	PC
	JRST	PCSK1

CAMSK2:	CAMG	AR,BR
	JRST	PCSK1
	AOS	PC
	JRST	PCSK1

CAMSK3:	CAMGE	AR,BR
	JRST	PCSK1
	AOS	PC
	JRST	PCSK1

CAMSK4:	CAMN	AR,BR
	JRST	PCSK1
	AOS	PC
	JRST	PCSK1

CAMSK5:	SKIPE	AR
	AOS	PC
	JRST	PCSK1
;BOOLE OPERATIONS 4XX CODES
BOOLE:	HLRZM IR,2		;IR BITS FOR BOOLE 0-17
	LSH 2, -^D11		;FOR DISPATCH AT EF0
BEF0:	MOVSS AR		;SWAP HAVES TO AVOID
	MOVSS BR		;TROUBLES COMMON TO TEST GROUP
	MOVE 1,[-1]		;TO AC1
	TDC 1, BR		;CONTENTS OF BR NOT
BET0:	XCT B0TAB-BOL(2)
	MOVSS AR		;RESTORE VALUES
	MOVSS BR		;TO AR, BR
	CAIE 2,BOL+2		;BOOLE 2?
	CAIN 2,BOL+10		;BOOLE 10?
	JRST BFT1		;YES. GO TO BFT1...E LONG.
	CAIE 2,BOL+13		;BOOLE 13?
	CAIN 2,BOL+16		;BOOLE 16
	JRST BFT1		;YES. GO TO BFT1...E LONG.
	JRST	FWTET0		;NO. PRINT ET0..GO TO ST1
	STORE	ET0

BFT1:	MOVE AD,BR
	CAIE 2,BOL+10
	CAIN 2,BOL+16
	TSC AD,[-1]		;COMP ADDER BOL 10,16
	STORE ET1

BET1:	SETCM 1,AD
	CAIE 2,BOL+2
	CAIN 2,BOL+10
	TDZ AR,1		;ADDER AND BOL2,10
	CAIE 2,BOL+13
	CAIN 2,BOL+16
	TDO AR,AD		;ADDER IOR BOL 13,16
	JRST PUSET2		;PRINT ET2..GO TO ST1
B0TAB:	MOVE AR,[0]		;BOOLE 0
	TDZ AR,1		;	1
	TDC AR,[-1]		;      2
	MOVE AR,BR		;      3
	TDZ AR,BR		;	4
	CAI			;      5
	TDC AR,BR		;	6
	TDO AR, BR		;      7
	TDC AR,[-1]		;     10
	TDC AR,1		;	11
	TDC AR,[-1]		;     12
	TDC AR,[-1]		;     13
	MOVE AR,1		;	14
	TDO AR,1		;	15
	TDC AR,[-1]		;     16
	MOVE AR,[-1]		;     17
;EXECUTE CYCLE HALF WORD TRANSFERS 5XX CODES

HALF:	TLNN IR,2000
	EXCH AR,BR
	MOVE	AD,BR
	TLNE IR,32000
	JRST HEF0		;HXX (O,Z,E)X
	TLNN IR,4000
	JRST HEF0
	STORE ET0
	GO	HAFTR		;DO THE TRANSFER TO AR
	JRST PUSET1		;PRINT ET1..GO TO ST1

HEF0:	TLNN IR,30000
	JRST HET0
	SETZ AD,
	TLNN IR,10000
	JRST HEF4
	TLNN IR,20000
	JRST HET0
	TLNN IR,40000
	JRST HEF2
	TLNN IR,4000
	JRST HEF3
HEF1:	JUMPL AR,HEF4
	JRST HET0
HEF2:	TLNN IR,4000
	JRST HEF1
HEF3:	TRNE AR,400000
HEF4:	SETCA AD,
HET0:	GO	HAFTR		;DO THE TRANSFER TO AR
	JRST FWTET0		;PRINT ET0..GO TO ST1

HAFTR:	MOVEI 0,-1		;DO THE HALF TRANSFERS
	TLNE IR,40000		;HXLXX: 0=0,-1
	ROT	^D18		;HXRXX:	0=-1,0
	TLNE IR,4000
	TSZ AR,0		;HRLXX,HLRXX
	TLNE IR,4000
	TSC AR,AR		;HRLXX, HLRXX
	TDZ AR,0
	TSZ AD,0
	TDO AR,AD		;COMBINED TERMS
	RTN
;EXECUTE CYCLE TEST INSTRUCTIONS CODE 6XX

TEST:	HLLZ 2,IR		;LOOK AT BIT 8
	ROT 2,^D8
	SKIPGE 2
	ROT AR,-^D18
	STORE ET0
TEF1:	LSH 2,-3
	MOVE AD,BR
	AND BR, AR		;ZEROS ONES COMP
	XCT TTAB0-30(2)		;OR DO NOTHING
TET1:	STORE ET1

TEF2:	MOVE AD,BR
	HLLZ 1,IR
	ROT 1,^D8
	SKIPGE 1
	ROT AR,^D18		;TLXX OR TSXX
	ANDI 1,3
	JUMPE 1,TET2		;NULL SKIP MODE
	CAIN 1,1
	JUMPE AD,TSKIP		;E SKIP MODE AND ZERO
	CAIN 1,3
	JUMPN AD,TSKIP		;N SKIP MODE AND NOT ZERO
	CAIN 1,2
	JRST TSKIP		;A SKIP MODE
TET2:	JRST PUSET2		;PRINT ET2..GO TO ST1

TSKIP:	HRRI PC,1(PC)
	JRST PUSET2		;PRINT ET2...GO TO ST1

TTAB0:	CAI
	ANDCM AR,AD
	XOR AR,AD
	IOR AR,AD
;I/O INSTRUCTION PROCESS

OP700:	LDB	1,[POINT 3,IR,12]	;GET CODE

	LDB	0,[POINT 10,IR,9]	;GET DEVICE

	CAIN	1624
	JRST	@TTIO(1)		;TTY I/O

	CAIN	1601
	JRST	@PIIO(1)		;PI

	CAIN	1600
	JRST	@APRIO(1)		;APR

	JRST	ST1			;ALL ELSE

TTIO:	ST1		;BLKI
	TTYDI		;DATAI
	ST1		;BLKO
	TTYDO		;DATAO
	TTYCO		;CONO
	TTYCI		;CONI
	TTYCNZ		;CONSZ
	TTYCNO		;CONSO

PIIO:	ST1		;BLKI
	PIDI		;DATAI
	ST1		;BLKO
	PIDO		;DATAO
	PICO		;CONO
	PICI		;CONI
	PICNZ		;CONSZ
	PICNO		;CONSO

APRIO:	ST1		;BLKI
	APRDI		;DATAI
	ST1		;BLKO
	APRDO		;DATAO
	APRCO		;CONO
	APRCI		;CONI
	APRCNZ		;CONSZ
	APRCNO		;CONSO
;TELETYPE FUNCTIONS

TTYDI:	TTCALL	2,AR		;INPUT CHAR
	JRST	.+1
	MOVE	TTYST#
	TRO	40		;SET INPUT DONE
	TRZ	100		;CLEAR INPUT BUSY
	MOVEM	TTYST
	JRST	ST1

TTYDO:	MOVE	MA
	ADDI	OFFSET
	ANDI	-1
	TTCALL	1,@0		;OUTPUT CHAR
	MOVE	TTYST
	TRO	10		;SET OUTPUT DONE
	TRZ	20		;CLEAR OUTPUT BUSY
	MOVEM	TTYST
	JRST	ST1

TTYCO:	HRRZ	BR
	TRZ	773600
	IORM	TTYST
	LSH	BR,-4
	TRZ	BR,777607
	ANDCAM	BR,TTYST
	JRST	ST1

TTYCI:	MOVE	AR,TTYST
	TTCALL	13,0		;SKIP IF CHAR WAITING
	TRZA	AR,100		;NO CHAR, CLEAR INPUT BUSY
	TRO	AR,100		;CHAR, SET INPUT BUSY
	MOVEM	AR,TTYST
	JRST	ST1

TTYCNZ:	MOVE	TTYST
	TTCALL	13,0
	TRZA	100
	TRO	100
	MOVEM	TTYST
	TRNN	0,(BR)
	AOS	PC
	JRST	ST1

TTYCNO:	MOVE	TTYST
	TTCALL	13,0
	TRZA	100
	TRO	100
	MOVEM	TTYST
	TRNE	0,(BR)
	AOS	PC
	JRST	ST1
;APR FUNCTIONS

APRDI:	MOVE	AR,SWITCH
	MOVEI	2,SACINH+SCE
	JRST	XSS9

APRDO:	MOVE	MA
	ADDI	OFFSET
	ANDI	-1
	MOVE	0,@0
	MOVEM	0,APRDWD#
	JRST	ST1

APRCO:	MOVEM	BR,APCOWD#
	JRST	ST1

APRCI:	MOVE	AR,APCIWD#
	JRST	ST1

APRCNZ:	MOVE	APCIWD
	TDNN	0,BR
	AOS	PC
	JRST	ST1

APRCNO:	MOVE	APCIWD
	TDNE	0,BR
	AOS	PC
	JRST	ST1
;PI FUNCTIONS

PIDI:	JRST	ST1

PIDO:	PUT	1
	PUT	2
	PUT	3
	MOVEI	2,"!"		;PRINT "!"
	TTCALL	1,2
	MOVE	MA
	ADDI	OFFSET
	ANDI	-1
	MOVE	2,@0
	MOVEI	1,^D12
PIDO1:	MOVE	3,2
	ROT	3,3
	ANDI	3,7
	ADDI	3,"0"
	TTCALL	1,3		;PRINT 12 OCTAL DIGITS
	LSH	2,3
	SOJG	1,PIDO1
	MOVEI	2,15
	TTCALL	1,2		;CR
	MOVEI	2,12
	TTCALL	1,2		;LF
	GET	3
	GET	2
	GET	1
	JRST	ST1

PICO:	HRRZM	BR,PICOWD#
	JRST	ST1

PICI:	MOVE	AR,PICIWD#
	JRST	ST1

PICNZ:	MOVE	PICIWD
	TDNN	0,BR
	AOS	PC
	JRST	ST1

PICNO:	MOVE	PICIWD
	TDNE	0,BR
	AOS	PC
	JRST	ST1
;SIMULATOR SYMBOL TABLE

DEFINE	INX (A)
<
	ASCII /A/>


TBLMUO:	INX	MUUO
TBLLUO:	INX	LUUO
TBLFLT:	INX	FAD
	INX	FADR
	INX	FSB
	INX	FSBR
	INX	FMP
	INX	FMPR
	INX	FDV
	INX	FDVR
TBLBYT:	INX	UFA
	INX	DFN
	INX	FSC
	INX	IBP
	INX	ILDB
	INX	LDB
	INX	IDPB
	INX	DPB
TBLMV:	INX	MOVE
	INX	MOVS
	INX	MOVN
	INX	MOVM
	INX	IMUL
	INX	MUL
	INX	IDIV
	INX	DIV
	INX	ADD
	INX	SUB
TBLMOV:	ASCII / /
	INX	I
	INX	M
	INX	S
TBLMO:	INX	ASH
	INX	ROT
	INX	LSH
	INX	JFFO
	INX	ASHC
	INX	ROTC
	INX	LSHC
	INX	ERR
	INX	EXCH
	INX	BLT
	INX	AOBJP
	INX	AOBJN
	INX	JRST
	INX	JFCL
	INX	XCT
	INX	ERR
	INX	PUSHJ
	INX	PUSH
	INX	POP
	INX	POPJ
	INX	JSR
	INX	JSP
	INX	JSA
	INX	JRA
TBLAD1:	ASCII / /
	INX	L
	INX	M
	INX	B
	ASCII / /
	INX	I
	INX	M
	INX	B
TBLCOM:	INX	CAI
	INX	CAM
	INX	JUMP
	INX	SKIP
	INX	AOJ
	INX	AOS
	INX	SOJ
	INX	SOS
TBLCM:	ASCII / /
	INX	L
	INX	E
	INX	LE
	INX	A
	INX	GE
	INX	N
	INX	G
TBLBOL:	INX	SETZ
	INX	AND
	INX	ANDCA
	INX	SETM
	INX	ANDCM
	INX	SETA
	INX	XOR
	INX	IOR
	INX	ANDCB
	INX	EQV
	INX	SETCA
	INX	ORCA
	INX	SETCM
	INX	ORCM
	INX	ORCB
	INX	SETO
H:	INX	H
TBLH:	INX	LL
	INX	RL
	INX	LLZ
	INX	RLZ
	INX	LLO
	INX	RLO
	INX	LLE
	INX	RLE
	INX	RR
	INX	LR
	INX	RRZ
	INX	LRZ
	INX	RRO
	INX	LRO
	INX	RRE
	INX	LRE
T:	INX	T
TBLTA:	INX	RN
	INX	DN
	INX	RZ
	INX	DZ
	INX	RC
	INX	DC
	INX	RO
	INX	DO
TBLTA1:	ASCII / /
	INX	E
	INX	A
	INX	N
TBLTB:	INX	LN
	INX	SN
	INX	LZ
	INX	SZ
	INX	LC
	INX	SC
	INX	LO
	INX	SO
TBLCON:	INX	BLKI
	INX	DATAI
	INX	BLKO
	INX	DATAO
	INX	CONO
	INX	CONI
	INX	CONSZ
	INX	CONSO
PNTINS:	SETZM	CONNF#
	MOVE	1,IRA#		;MOVE THE INST CODE TO AC1.
	ANDI	1,77
	SETZ	2,		;CLEAR AC2.
	MOVE	0,IRA
	CAIL	0,700
	JRST	CONN
	CAIL	0,600
	JRST	TTST
	CAIL	0,500
	JRST	HTST
	CAIL	0,400
	JRST	BOTST
	CAIL	0,300
	JRST	COMTST
	CAIL	0,200
	JRST	MOVTST
	CAIL	0,140
	JRST	FLTST
	CAIL	0,130
	JRST	BYTST
	CAIL	0,40
	JRST	MUUOST		;MUUO 40-77
	JUMPE	0,MUUOST	;MUUO 0
	JRST	LUUOST		;LUUO 1-37

MUUOST:	MOVEI	0,TBLMUO
	JRST	OUT

LUUOST:	MOVEI	0,TBLLUO
	JRST	OUT
FLTST:	ANDI	1,37		;FLOATING POINT
	ROT	1,-2
	MOVEI	0,TBLFLT(1)
	PNTA
	ROT	1,2
	ANDI	1,7
	MOVEI	0,TBLAD1(1)
OUT:	PNTA
	RTN

BYTST:	ANDI	1,7		;UFA,DFN,FSC,BYTE
	MOVEI	0,TBLBYT(1)
	JRST	OUT

MOVTST:	CAIGE	1,70
	CAIGE	1,40
	JRST	.+3		;MOVE,ADD,SUB,MUL,+ETC.
	MOVEI	0,TBLMO-40(1)	;SHIFTS,PUSH,POP,+ETC.
	JRST	OUT
	ROTC	1,-2
	CAIL	1,10
	SUBI	1,6		;ADD,SUB.
	MOVEI	0,TBLMV(1)
	PNTA
	ROTC	1,2
	CAIL	1,20
	JRST	IMLTST
	ANDI	1,3
	MOVEI	0,TBLMOV(1)
	JRST	OUT

IMLTST:	ANDI	1,3		;IMUL,MUL,IDIV,DIV
	MOVEI	0,TBLAD1+4(1)
	JRST	OUT

COMTST:	ROT	1,-3		;MEM AND AC MOD AND TEST.
	MOVEI	0,TBLCOM(1)
	PNTA
	ROT	1,3
	ANDI	1,7
	MOVEI	0,TBLCM(1)
	JRST	OUT

BOTST:	ROT	1,-2		;BOOLE
	MOVEI	0,TBLBOL(1)
	PNTA
	ROT	1,2
	ANDI	1,3
	MOVEI	0,TBLAD1+4(1)
	JRST	OUT

HTST:	MOVEI	0,H		;HALF WORD TRANSFERS
	PNTA
	ROT	1,-2
	MOVEI	0,TBLH(1)
	PNTA
	ROT	1,2
	ANDI	1,3
	MOVEI	0,TBLMOV(1)
	JRST	OUT

TTST:	MOVEI	0,T		;TEST
	PNTA
	TRNE	1,1
	JRST	TTODD
	ROT	1,-3
	MOVEI	0,TBLTA(1)
TTSTA:	PNTA
	ROT	1,2
	ANDI	1,3
	MOVEI	0,TBLTA1(1)
	JRST	OUT

TTODD:	ROT	1,-3
	MOVEI	0,TBLTB(1)
	JRST	TTSTA

CONN:	SETOM	CONNF
	HLRZ	1,IR
	ROT	1,-5
	ANDI	1,7		;I/O.
	MOVEI	0,TBLCON(1)
	JRST	OUT
;INITIAL AND FINAL SWITCH TABLE

IFTAB:	REPEAT 40,
	<XWD FACINH+PCINH+SACINH+SCE,FACINH+PCINH+SACINH+SCE>
	REPEAT 14,<XWD 10,10>
IF130:	XWD FCE+5,FCEPSE+SARBR+3
	XWD 1,FCEPSE+FACINH+0
	XWD FACINH+16+FCEPSE+PCINH,FCE+16+PCINH+FACINH
	XWD FACINH+SACINH+FCEPSE+PCINH+SCE+16,SACINH+FCE+SCE+PCINH+16+FACINH
	
	REPEAT 3,
<	XWD FCE+2,FCE+SAC2+4
	XWD SCE+FCE+SACINH,FCE+SCE+3
	XWD FCE+2,1
	XWD SCE+FCE+SACINH,FCE+SCE+3>

IR170:	XWD FCE+2,FCE+FAC2+SAC2+4
	XWD SCE+FCE+SACINH,FCE+SCE+3
	XWD FCE+2,1
	XWD SCE+FCE+SACINH,FCE+SCE+3
IR200:	XWD FCE+2+FACINH,FACINH+1
	XWD SACINH+SCE,FACINH+FCEPSE+SACZ+3
	XWD FCE+2+FACINH,FACINH+1
	XWD SACINH+SCE,FACINH+FCEPSE+SACZ+3
	XWD FCE+2+FACINH,FACINH+1
	XWD SACINH+SCE,FACINH+FCEPSE+SACZ+3
	XWD FCE+2+FACINH,FACINH+1
	XWD SACINH+SCE,FACINH+FCEPSE+SACZ+3
IR220:	XWD FCE+2,7
	XWD FCE+SACINH+SCE,FCE+SCE+3
	XWD FCE+SAC2+4,SAC2+7
	XWD FCE+SACINH+SCE,FCE+SAC2+SCE+5
	XWD FCE+SAC2+4,SAC2+7
	XWD FCE+SACINH+SCE+0,FCE+SAC2+SCE+3
	XWD FAC2+FCE+SAC2+4,FAC2+SAC2+7
	XWD FAC2+FCE+SACINH+SCE+6,FAC2+FCE+SAC2+SCE+5

IF240:	XWD 1,1			;SHIFTING
	XWD 1,7
	XWD FAC2+SAC2+7,FAC2+SAC2+7
	XWD FAC2+SAC2+7,0
	XWD FCEPSE+SARBR+3,PCINH+FCCLT+1
	XWD 1,1
	XWD SACINH+FACINH,FACINH+SACINH+10
	XWD SACINH+FACINH+PCINH+20,0
IF260:	XWD SARBR+12,FCE+SARBR+12	;PUSH,POP,ETC
	XWD FCCRT+SARBR+13,FCCRT+13
	XWD FACINH+SACINH+SCE+0,FACINH+1
	XWD SARBR+3,FCCLT+3
	XWD FCE+2,1
	XWD FCEPSE+SACINH+0,FCEPSE+3
	XWD FCE+2,1
	XWD FCEPSE+SACINH+0,FCEPSE+3
IF300:	REPEAT 4,<XWD SACINH+10,SACINH+10>	;CAI,CAM
	REPEAT 4,<XWD SACINH+FCE+11,SACINH+FCE+11>
	REPEAT 4,<XWD SACINH+10,SACINH+10>
	REPEAT 4,<XWD FCE+SACZ+2+FACINH,FCE+SACZ+2+FACINH>
	REPEAT 4,<XWD 1,1>		;CODE 340 AOJ
	REPEAT 4,<XWD FCEPSE+SACZ+3+FACINH,FCEPSE+SACZ+3+FACINH>
	REPEAT 4,<XWD 1,1>
	REPEAT 4,<XWD FCEPSE+SACZ+3+FACINH,FCEPSE+SACZ+3+FACINH>

IF400:	XWD FACINH+2,FACINH+1	;BOOLE 0
	XWD FACINH+SACINH+SCE,FACINH+SCE+3
	XWD FCE+2,1		;BOOLE1
	XWD FCEPSE+SACINH+0,FCEPSE+3
	XWD FCE+2,1		;BOOLE 2
	XWD FCEPSE+SACINH+0,FCEPSE+3
	XWD FACINH+FCE+2,FACINH+1	;BOOLE 3
	XWD SACINH+FACINH+FCEPSE,FACINH+FCEPSE+3
IF420:	XWD FCE+2,1		;BOOLE 4
	XWD FCEPSE+SACINH+0,FCEPSE+3
	XWD 2,1			;BOOLE 5
	XWD SACINH+SCE,SCE+3
	XWD FCE+2,1		;BOOLE 6
	XWD FCEPSE+SACINH,FCEPSE+3
	XWD FCE+2,1		;BOOLE 7
	XWD FCEPSE+SACINH+0,FCEPSE+3
IF440:	XWD FCE+2,1		;BOOLE 10
	XWD FCEPSE+SACINH+0,FCEPSE+3
	XWD FCE+2,1		;BOOLE 11
	XWD FCEPSE+SACINH+0,FCEPSE+3
	XWD 1,1
	XWD SACINH+SCE,SCE+3
	XWD FCE+2,1		;BOOLE 13
	XWD FCEPSE+SACINH+0,FCEPSE+3
IF460:	XWD FACINH+FCE+2,FACINH+1	;BOOLE 14
	XWD SACINH+FACINH+FCEPSE,FACINH+FCEPSE+3
	XWD FCE+2,1		;BOOLE 15
	XWD FCEPSE+SACINH,FCEPSE+3
	XWD FCE+2,1		;BOOLE 16
	XWD FCEPSE+SACINH,FCEPSE+3
	XWD FACINH+2,FACINH+1	;BOOLE 17
	XWD FACINH+SACINH+SCE,FACINH+3+SCE
IR500:	REPEAT 2,<XWD FCE+2,1		;HALF WORDS
	XWD FCEPSE+SACINH,FCEPSE+FACINH+SACZ>
	REPEAT 6,<XWD FCE+FACINH+2,FACINH+1
	XWD FCEPSE+SACINH,FCEPSE+FACINH+SACZ>
	REPEAT 2,<XWD FCE+2,1
	XWD FCEPSE+SACINH,FCEPSE+FACINH+SACZ>
	REPEAT 6,<XWD FCE+FACINH+2,FACINH+1
	XWD FCEPSE+SACINH,FCEPSE+FACINH+SACZ>
IR600:	REPEAT 4,<XWD SACINH+1,SACINH+1>	;TEST INST
	REPEAT 4,<XWD FCE+SACINH+2,FCE+SACINH+2>
	REPEAT 4,<XWD 1,1>
	REPEAT 4,<XWD FCE+2,FCE+2>
	REPEAT 4,<XWD 1,1>
	REPEAT 4,<XWD FCE+2,FCE+2>
	REPEAT 4,<XWD 1,1>
	REPEAT 4,<XWD FCE+2,FCE+2>
PAGE
	REPEAT 40,<XWD 20,20>
;SHIFT ROTATE

SHROT:	MOVE	0,IRA
	CAIN	0,243		;IR JFFO ?
	JRST	JFFO1		;YES
	HRR SC, BR
	TRZ SC, 777400		;BR 18, 29-35
	TRNE BR, 400000		;GO TO SHIFT
	TRO SC, 777400		;COUNTER
	STORE ET0
	HRRZI -1		;FOR RIGHT SHIFTS
	TRNE BR, 400000
	JRST SHROT1
	MOVN SCAD,SC		;SC NEGAT SETUP
	HRR SC,SCAD		;SC FM SCAD(J)
	STORE SRT1
	MOVEI 1
SHROT1:	MOVE AD,IRA
	GO	SCSUB
	GO	SHROT2
	JRST ST0
SHTAB:	ASH AR,@(P)
	ROT AR,@(P)
	LSH AR,@(P)
	CAI
	ASHC AR,@(P)
	ROTC AR,@(P)
	LSHC AR,@(P)
	CAI
SHROT2:	PUT	0		;C(AC0)=DIRECTION OF SHIFT
	CAIE AD,244		;IR ASHC?
	CAIN AD,240		;OR ASH?
	JRST SHROT3		;YES.
SHRT2:	XCT SHTAB-240(AD)
	GET	0
	RTN

SHROT3:	TRNE BR,400000		;BR18(0)?
	JRST SHRT2		;NO.
	MOVE 1,AR
	LSH 1,1
	XOR 1,AR
	SKIPGE 1		;BR18(0) AND AR0 NE AR1?
	TLO PC,AROV		;YES. SET AROV FLAG.
	JRST SHRT2

JFFO1:	MOVE	0,AR		;SPECIAL FIX TO INCLUDE JFFO
	JFFO	0,.+3
	MOVE	AR,1
	JRST	ST0
	MOVE	AR,1
	HRR	PC,MA
	JRST	ST0
;FLOATING POINT

SFSC:	HRR SC,BR		;SC FM BR(1)
	TRZ SC,777400
	TRNE BR,400000
	TRO SC,777400
	MOVE BR,AR		;BR FM AR(J)
	HLRZ 0,BR
	LSH 0,-11
	HRRM 0,SCAD
	SKIPGE AR
	SETCA SCAD,		;AR0(1) : SCAD SC-BR SETUP
	ADD SCAD,SC		;AR0(0) : SCAD SC+BR SETUP
	STORE ET0
	TLZ AR,377000		;AR1-8 FM AR0(J)
	TLNE AR,400000
	TLO AR,377000
	STORE ET1
	HRR SC,SCAD		;SC FM SCAD(J)
	STORE ET2
	GO	NRT0
	JRST ST0

SDFN:	MOVN AD,BR		;AD MINUS BR
	HLRZ SCAD,BR
	LSH SCAD,-11		;SCAD SC+BR SETUP
	HRR SC,SCAD		;SC FM SCAD(J)
	MOVE BR,AR		;BR FM AR(J)
	MOVE AR,AD		;AR FM AD(J)
	MOVN AD,BR		;AD MINUS BR
	TLNN AR,777
	TRNE AR,-1
	SETCM AD,BR		;AD9-35 NE 0 : AD CRY36 CLR
	STORE ET0
	TLZ AR,777000
	LSH SCAD,33
	IORM SCAD,AR		;AR0-8 FM SCAD(J)
	STORE ET1
	MOVE BR,AR		;BR FM AR(J)
	MOVE AR,AD		;AR FM AD(J)
	STORE ET2
	JRST ST0

SFSB:	MOVNS BR		;AD MINUS BR
	EXCH AR,BR		;AR FM AD(J), BR FM AR(J)
SFAD:	STORE ET0
FAT1:	MOVE AR
	ASH -^D27
	HRRM SC			;SC FM AR0-8(1)
	MOVE SCAD,BR
	ASH SCAD,-^D27
	MOVE BR
	XOR AR
	SKIPL			;AR0 NE BR0?
	SUBM SC,SCAD		;SCAD SC-BR SETUP
	SKIPGE
	ADD	SCAD,SC		;SCAD SC+BR SETUP
	HRRE SCAD,SCAD		;PUT BIT 18 INTO BIT 0.
	STORE FAT1

FAT2:	HRR SC,SCAD		;SC FM SCAD(J)
	MOVE	0,AR
	XOR	0,BR
	JUMPGE 0,FAT2B		;AR0 = BR0.
	JUMPGE SCAD,FAT2A	;SCAD0(0) + AR0 NE BR0.
	HRRI	SCAD,1(SC)	;SCAD0(1) +AR0 NE BR0..SCAD SC+1 SETUP
	JRST	FAT2D

FAT2A:	SETCM	SCAD,SC		;SCAD SC COM SETUP.
	JRST	FAT2D

FAT2B:	SKIPL	SCAD
	MOVN	SCAD,SC		;SC NEGATE SETUP.

FAT2D:	STORE	FAT2

FAT3:	MOVE SC
	LSH	0,33
	XOR	AR
	HRR SC,SCAD		;SC FM SCAD(J)
	STORE FAT3
	JUMPL 0,FAT45		;SC0 = AR0?
	EXCH AR,BR		;YES. AR FM AD(J), BR FM AR(J)
FAT3A:	STORE	FAT3A

FAT45:	HRRE SC			;SHIFT COUNT SIGN TO BIT ZERO
	TRC SC, 700
	TRCE SC, 700
	JUMPL FAT4		;SC 0-2 NOT = 7 AND SC0(1)

FAT5:	TLZ AR,377000		;SC0-2 = 7 OR SC0(0)
	TLNE AR,400000		;AR1-8 FM AR0 (J)
	TLO AR, 377000
	STORE	FAT5
	GO	SCSUB		;CALL SHIFT COUNTER
	GO	FPSHRT		;FOR FLOAT SHIFT RIGHT
FAT6:	MOVE	0,BR
	LSH	0,-33
	MOVE	SCAD,SC
	ADD	SCAD,0		;SCAD SC+BR SETUP
	STORE FAT6
FAT7:	HRR SC,SCAD		;SC FM SCAD(J)
	TLZ BR,377000
	TLNE BR,400000		;BR1-8 FM BR0(J)
	TLO BR, 377000
	SETCM	SCAD,SC		;SCAD SC COM SETUP
	STORE	FAT7
FAT8:	ADD	AR,BR		;AR FM AD(J)
	JUMPGE	BR,FAT8A
	HRR	SC,SCAD		;BR0(1) : SC FM SCAD(J)
FAT8A:	STORE	FAT8
	GO	NRT0		;GO TO NORMALIZE RETURN
	JRST ST0

FAT4:	SETZ AR,		;CLR AR
	TRZ SC,-1		;SC CLR
	STORE FAT4
	JRST FAT6
;FLOATING DIVIDE

SFDV:	MOVE 0,IRA
	CAIN 0,171
	JRST DIVT0		;FDVL
SFDV1:	JUMPGE AR,.+3		;FDV
	MOVNS AR		;AR0(1) : AD AR NEGATE..AR FM AD(J)
	TLO MA,DSF7		;DSF7 SET
SFMP:	STORE ET0
	JRST FPT0

FDT1:	MOVE AD,AR		;AD AR+EN SET
	SKIPL BR
	SUB AD,BR		;BR0(0) : AD BR-EN..AD CRY36 SET
	SKIPGE BR
	ADD AD,BR		;BR0(1) : AD BR+EN SET
	TRNE	SC,400		;ECO49, SC0(0)
	JRST	.+4		;NO
	TRNE	SC,200		;SC1(0)
	SETOM	FXUHLD		;SC0 NE SC1, SET AR FXU HOLD
	JRST	.+3
	TRNN	SC,200		;SC1(0)
	JRST	.-3
	STORE FDT1
	JUMPL AD,FDT4		;AD0(1)?...GO TO FDT4
FDT2:	MOVE AD,AR		;AR ENABLE BR DISABLE
	TLZ FE,-1		;FE CLR
	STORE FDT2
FDT3:	HRLM SCAD,FE		;FE FM SCAD(1)
	GO	FPSHRT		;AR SH RT...MQ SH RT
	SETOM FDF3#		;FDF3 SET
	STORE FDT3
FDT4:	TRZ SC,-1		;SC CLR
	STORE FDT4
FDT5:	HRRI SC,-^D28		;IF IR6(1)
	TLNN IR,4000		;-28 TO SC, IF IR6(0)
	HRRI SC,-^D27		;-27 TO SC
	STORE FDT5

FDT5A:	GO	DST1		;GO TO DIVIDE STEP SUBROUTINE
	JRST SS9		;ERROR RETURN.

FDT6:	TLNN	IR,4000		;IR6(1)?
	JRST	.+3		;NO.
	ADDI	AR,1
	ASH AR,-1		;YES..AR SHRT
	TLO MA,NRF1		;DISABLE FURTHER ROUNDING
	HLR SC,FE		;SC FM FE(1)
	STORE FDT6
	SETOM	FDT7FX#		;FDVL SIM FIX FOR NR ALL ZERO
	GO	NRT0		;TO NORM. ROUTINE
	SKIPN	FDT7FX
	JRST	ST0		;NR ALL ZERO
FDT7:	MOVN AD,AR		;AD AR-EN...AD CRY36 SET
	STORE FDT7
FDT8:	TLNE MA,DSF7		;BR0 NE DSF7?
	JUMPL	BR,FDT8A
	TLNN MA, DSF7
	JUMPGE BR,FDT8A
	MOVE AR,AD		;YES...AR FM AD(J)
FDT8A:	STORE FDT8
	MOVE 0,IRA
	CAIE	171		;FDVL?
	JRST ST0		;NO. FDV

;MORE FLOATING DIVIDE.....FDVL
FDT9:	MOVE BR,AR		;BR FM AR(J)
	SETZ AR,		;AR CLEAR
	TRZ SC,-1		;SC CLEAR
	STORE FDT9
	FMRQA 0
	TLNN MA,FMEN		;MC FMEN?
	JRST FDRQ		;NO.
	STORE FDT10
	JRST FDT11
FDRQ:	STORE FDRQ
FDT11:	HLRZ AR
	ASH -^D9
	HRRM SC			;SC FM AR0-8[1]
	SKIPE FDF3		;FDF3 SET?
	JRST FDT11B		;YES. 32 EN SET
	HRRZI SCAD,-33(SC)	;NO. 33 EN SET
	SKIPGE AR
	HRRZI SCAD, 33(SC)
FDT11A:	MOVE AR,MQ		;AR FM MQ(J)
	STORE FDT11
	JRST FDT12

FDT11B:	HRRZI SCAD,-32(SC)
	SKIPGE AR
	HRRZI SCAD,32(SC)
	JRST FDT11A

FDT12:	TRNN SCAD,400		;AR0=SCAD0 AND AD NE 0 :
	JUMPGE AR,FDT12A	;AR1-8 FM SCAD(J)
	TRNE SCAD,400
	JUMPL AR,FDT12A
	SETZ AR,		;AR0 NE SCAD0 : AR CLR
FDT12A:	JUMPE AR,FDT12B
	HRLZ SCAD
	LSH ^D9
	TLZ 0,400000
	TLZ AR,377000		
	IORM AR			;AR1-8 FM SCAD(J)
FDT12B:	STORE FDT12

FDT13:	MOVEM AR,MQ		;MQ FM AD(J) ;REMAINDER
	STORE FDT13
FDT14:	MOVE AR,BR		;AR FM AD(J) ;QUOTIENT
	STORE FDT14
	JRST	ST0		;END FLOATING DIVIDE
;FLOATING EXPONENT

FPT0:	MOVE	SCAD,AR
	ASH	SCAD,-33
	HRRM	SCAD,SC		;SC FM AR0-8(1),SCAD FM SC(J)
	SKIPGE	AR
	SETCM	SCAD,SC		;AR0(1) : SCAD SC COM SETUP
	STORE	FPT0

FPT1:	HRR	SC,SCAD		;SC FM SCAD(J)
	MOVE	1,BR
	ASH	1,-^D27
	MOVE	0,IR
	LSH	0,5
	XOR	0,BR
	SKIPGE	0		;IR5 = BR0 : SCAD DATA 1 EN
	SETCA	1,		;IR5 NE BR0 : SCAD DATA 0 EN
	ADD	SCAD,1
	TLNE	IR,10000	;IR5(1)?
	ADDI	SCAD,1		;YES. SCAD + 1 EN SET
	STORE	FPT1

FPT2:	HRR	SC,SCAD		;SC FM SCAD(J)
	TLNN	IR,10000
	SUBI	SCAD,200	;IR5(0) : SC-EN (SCAD 200 EN SET)
	TLNE	IR,10000
	ADDI	SCAD,200	;IR5(1) : SC+EN (SCAD 200 EN SET)
	STORE	FPT2

FPT3:	TLZ	BR,377000	;BR1-8 FM BR0(J)
	TLNE	BR,400000
	TLO	BR,377000
	TLZ	AR,377000	;AR1-8 FM AR0(J)
	TLNE	AR,400000
	TLO	AR,377000
	HRLZ	FE,SCAD		;FE FM SCAD(1),SC CLR
	TLNE	IR,10000	;IR5(1)?
	HRR	SC,SCAD		;YES. SC FM SCAD(J)
	ADDI	SCAD,1		;SCAD SC+1 SETUP
	STORE	FPT3
	TLNE	IR,10000	;IR5(1)?
	JRST	FDT1		;YES.
FMT1:	HRRI	SC,745		;SC FP SETUP (745)
	STORE	FMT1

MST0:	JUMPGE BR,.+3
	SKIPG AR
	TLO MA,MPF2		;AR0(1) AND BR0(1) : MPF2 SET.
	MOVE MQ,BR		;MQ FM AD(J)
	MOVE BR,AR		;BR FM AR(J)
	STORE	MST0

MST1:	SETZB AR,AD		;AR CLR
	TRNE	MQ,1		;MQ35(1)?
	SUB AD,BR		;YES. AD BR-EN, AD CRY36 SET
	TRNE MQ,1		;MQ35(1)?
	SETOM ADBREN#		;YES. SET AD BR + V - EN FLAG
	STORE MST1
	GO	SCSUB		;GO TO SC SUBROUTINE
	GO	MULSH		;XCT THIS AT SCT3
	SKIPE	MPF1#		;MPF1 SET?
	JRST	MPT2		;YES. GO BACK TO MUL ROUTINE

FMT3:	MOVE AR,AD		;AR FM AD(J)
	HLR	SC,FE		;SC FM FE(J)
	TRZ	MQ,1		;MQ 35 CLR
	STORE	FMT3
	GO	NRT0		;GO TO NORMALIZE ROUTINE.
	JRST	ST0

;NORMALIZE

NRT0:	HRRI	SCAD,1(SC)	;SCAD SC+1 SETUP
	STORE	NRT0
NRT0A:	JUMPN	AR,NRT10	;AD NE 0 : NOT NR ALL ZERO COND.
	MOVE	0,IRA
	CAIE	0,171		;GO TO NRT99 IF AD=0 + IR = FDVL.
	TDNN MQ,[XWD 1777,-1]	;NR ALL ZERO CONDITION =
				;AD=0 AND MQ8(0) AND MQ9-35 = 0.
	JRST NRT99-1		;GO TO NRT99.

NRT10:	TLNE AR,1000
	JUMPGE AR,NRT10A	;AR0 NE AR8..NR SH RT COND
	TLNN AR,1000
	JUMPL AR,NRT10A		;AR0 NE AR8..NR SH RT COND
	TLNN	AR,1000
	JRST	NRT1		;AR8(0)...NOT NR SH RT COND
	TLNN	AR,777
	TRNE	AR,-1
	JRST	NRT1		;AD9-35 NE 0...NOT NR SH RT COND
NRT10A:	HRR	SC,SCAD		;SC FM SCAD(J)
	MOVE 0,IRA#		;MOVE THE INST CODE INTO AC0.
	CAIL 0,170		;IR FDVX?
	ASH AR,-1		;FDV DISABLE MQ
	CAIGE 0,170		;NOT FDVX?
	GO	FPSHRT		;SHIFT RIGHT
	STORE	NRT10

NRT1:	TLNE	MA,NRF1		;ECO49, NRF1(0)
	JRST	.+10		;NO
	TRNE	SC,400		;SC0(0)
	JRST	.+4		;NO
	TRNE	SC,200		;SC1(0)
	SETOM	FXUHLD		;NRF1(0) + (SC0 NE SC1) : SET AR FXU HOLD
	JRST	.+3
	TRNN	SC,200		;SC1(0)
	JRST	.-3
	SETCM	SCAD,SC		;SCAD SC COM SETUP
	STORE	NRT1
NRTNOR:	TLNE AR,400
	JUMPGE AR,NRT3		;AR SIGN NOT = AR BIT 9
	TLNN AR,400
	JUMPL AR,NRT3		;AR SIGN NOT = AR BIT 9
	MOVE 0,IRA
	CAIN 0,130
	JRST	NRT3		;IR UFA
	MOVSI 777000
	ANDCA AR
	CAME [XWD 400,0]
	JRST	NRT2		;AD9(1) + AD10-35 NE 0
	TLNN	MQ,1000		;ECO49, AD9(1) + AD10-35 = 0 + MQ08(0)
	JRST	NRT3		;YES

NRT2:	HRR SC,SCAD		;SC FM SCAD(J)
	HRRI	SCAD,1(SC)	;SCAD SC+1 SETUP
	MOVE 0,IRA#		;MOVE INST CODE INTO AC0.
	CAIL 0,170		;FDVX?
	ASH	AR,1		;IR FDVX : NO MQ SH LT
	CAIGE 0,170		;NOT FDVX?
	GO	FPSHLT		;FLOATING SHIFT LEFT
	STORE NRT2
	JRST NRTNOR		;LOOK FOR NR NORMAL
NRT3:	HRR SC,SCAD		;SC FM SCAD(J)
	SETCM SCAD,SC		;SCAD SC COMP SETUP
	STORE NRT3
	JRST	SHORT		;LOOK FOR NR ROUND COND.
NRT4:	TRNN	SC,400
	TLO PC,AROV+FOV		;SC0(0) : AROV AND FOV SET
	TRNE	SC,400		;ECO49, SC0(0)
	JRST	.+3		;NO
	SKIPN	FXUHLD		;SC0(0) + AR FXU HOLD(0)
	TLO	PC,FXU		;YES. SET ARFXU.
	HRR	SC,SCAD
	SKIPGE	AR
	TRC	SCAD,-1
	STORE NRT4

NRT5:	HRLZ	SCAD
	LSH	^D9
	TLZ	0,400000
	TLZ AR,377000
	IORM AR			;AR1-8 FM SCAD1-8(J)
	STORE	NRT5
	TLNN IR,6000
	TLNN IR,1000
	JRST NRT99		;NOT LONG
	TLC IR,70000
	TLCN IR,70000
	JRST NRT98		;FDV AND LONG

NLT0:	HRREI SCAD, -33(SC)	;-33 ENABLE
	STORE	NLT0
NLT1:	HRR SC,SCAD		;SC FM SCAD(J)
	EXCH AR,MQ		;MQ FM AD(J), AR FM MQ(J)
	TRNE SC,400		;SCAD0(1) : AR CLR
	SETZ	AR,
	STORE	NLT1

NLT2:	LSH AR,-1		;AR SH RT ; AR0 CLR
	STORE	NLT2

NLT3:	JUMPE AR,NLT3A
	HRLZ SC
	LSH ^D9
	TLZ 0,400000
	TLZ AR,377000
	IORM AR			;AD9-35 NE 0 : AR1-8 FM SCAD1-8 (J)
NLT3A:	STORE NLT3
NLT4:	EXCH AR,MQ		;AR FM MQ(J)...MQ FM AD(J)
	STORE NLT4
	JRST NRT99

SHORT:	TLNN MA, NRF1
	TLNN IR,4000
	JRST	NRT4		;NRF1(1) OR IR6(0),
	TLNN MQ,1000
	JRST	NRT4		;OR MQ8(0),
	TDNN MQ,[XWD 777,-1]
	JUMPL AR,NRT4		;OR MQ9-35 = 0 AND AR0(1)..DON'T ROUND

NRT6:	TLO MA,NRF1		;NRF1 SET
	HRR SC,SCAD		;SC FM SCAD(J)
	STORE	NRT6
NRT7:	ADDI AR,1		;AR FM AD(J)..(AD CRY36 SET)
	SETZ	MQ,		;ECO49, MQ CLEAR
	STORE	NRT7
	JRST NRT0

	SETZM	FDT7FX		;GOT HERE FROM FDVL NR ALL ZERO
NRT99:	STORE NRT99
NRT98:	RTN			;ROUTINE
;FLOATING POINT SHIFT RIGHT, SHIFT LEFT
FPSHRT:	ASHC AR,-1		;AR MQ SH RT
	TLZ MQ,401000
	TLZE MQ,200000		;AR35 TO
	TLO MQ,1000		;MQ BIT 8
	RTN

FPSHLT:	TLZ MQ,200000
	TLZE MQ,1000
	TLO MQ,200000		;MQ BIT 8 TO AR 35
	ASHC AR,1
	TDZ MQ,[XWD 400000,1]
	RTN


;FIXED POINT MULTIPLY

SMUL:	HRRI SC,777735		;SC MD SETUP (735)
	SETOM MPF1#		;MPF1 SET
	STORE ET0
	JRST MST0

MPT2:	MOVE AR,AD		;AR FM AD(J)
	LSH MQ,-1		;MQ SH RT
	TLNE AD,400000		;AND PUT AD SIGN
	TLO MQ,400000		;TO MQ SIGN
	JUMPGE AD,.+3
	TLNE MA,MPF2		;IF AD0(1) AND MPF2(1)
	TLO PC,AROV		;SET OVERFLOW
	SETZM MPF1#		;MPF1 CLR
	STORE MPT2
	TLNE IR,4000		;IR6(1)?
	JRST ST0		;YES..MULX
MPT3:	SKIPGE AD,AR		;IMUL
	SETCA AD,		;AD CRY INS
	STORE MPT3
	SKIPE AD		;AD NE 0?
	TLO PC,AROV		;YES. SET AROV
	MOVE AR,MQ		;AR FM MQ(J)
	STORE MPT4
	JRST ST0		;TO STORE CYCLE

;MULTIPLY SHIFT ADD/SUB SUBROUTINE


MULSH:	MOVEM MQ,TEMP2#		;SAVE MQ
	MOVE AR,AD
	MOVE 0,IRA
	CAIGE 0,220		;IR FMP?
	JRST MULSHA		;YES.
	LSHC AR,-1		;AR SH RT, MQ SH RT
	TLNE AR,200000		;ARB1(1)?
	TLO AR,400000		;YES. SET SIGN BIT.
	MOVE AD,AR

MULAS:	MOVE 0,TEMP2#		;MQ  34  35
	TRNE 0,1		;     0   0  =  NOTHING
	JRST MULAS1		;     0   1  =  ADD
	TRNE 0,2		;     1   0  =  SUB
	SUB AD,BR		;     1   1  =  NOTHING
	TRNE 0,2
	SETOM ADBREN#
	RTN

MULAS1:	TRNN 0,2
	ADD AD,BR
	TRNN 0,2
	SETOM ADBREN#
	RTN

MULSHA:	GO	FPSHRT
	JRST MULAS-1


;FIXED POINT DIVIDE (DIVX)
XSDIV:	HRRI SC,-43		;SC MD SETUP (735)
	STORE ET0
DIVT0:	SETCM AD,AR		;AD AR-EN SET
	JUMPGE AR,DIVT0A	;AR0(0) : DO NOTHING
	TLO MA,DSF7		;AR0(1) : DSF7 SET
	MOVE AR,MQ		;AR FM MQ(J)
	MOVE MQ,AD		;MQ FM AD(J)
DIVT0A:	STORE DIVT0

	TLNN MA,DSF7		;DSF7(1)?
	JRST DIVT4		;NO. GO TO DIVT4
DIVT1:	MOVN AR,AR		;YES. AD AR-EN SET,AD CRY36 SET.
	EXCH AR,MQ		;AR FM MQ(J), MQ FM AD(J)
	STORE DIVT1
	TLNN IR,200000		;DIV LOW ZERO COND =
	JRST DIVT2B		;IR1(0) + AD 8-35 = 0
	TDNE	MQ,[377777,,-1]	;OR IR1(1) + AD CRY1
	JRST DIVT3
DIVT2A:	MOVE AD,AR		;AD AR+EN
	ADDI AD,1		;AD CRY36 SET
DIVT3:	MOVE AR,AD		;AR FM AD(J)
	STORE DIVT3

DIVT4:	LSH MQ,1		;MQ SHIFT LEFT
	STORE DIVT4
	TLNE IR,40000		;FDVL?
	JRST FPT0		;YES.
	GO	DST1		;GO TO DIV SUBROUTINE
	JRST SS9		;ERROR RETURN
	JRST ST0

DIVT2B:	TDNE MQ,[XWD 1777, -1]
	JRST DIVT3
	JRST DIVT2A
;IDIVIDE DIV

SDIV:	TLNE IR,4000
	JRST XSDIV
XSIDIV:	MOVN AD,AR		;ADDER NEGATE OF AR
	HRRI SC,-43		;SC MD SETUP (735)
	JUMPGE AR, .+3
	MOVE AR,AD		;AR0(1) : AR FM AD(J)
	TLO MA,DSF7		;DSF7 SET
	MOVE AD,AR		;AD AR+EN SET..OTHERS CLR
	STORE ET0

SIDIV1:	MOVE MQ,AD		;MQ FM AD(J)
	SETZ AR,		;AR CLR
	STORE ET1
SIDIV2:	ROTC	AR,1		;ECO45, SHIFT AR AND MQ LEFT
	TRC	MQ,1		;AR(35)_MQ(0)
	STORE ET2
	GO	DST1
	JRST SS9
	JRST ST0

DST1:	MOVE AD,AR		;AD AR+EN SET
	SKIPGE	BR
	ADD AD,BR		;BR0(1): AD BR+EN
	SKIPL	BR
	SUB AD,BR		;BR0(0): AD BR-EN
	STORE DST1
	TLNN AD,400000		;AD0(1)?
	JRST DST7		;NO..AN OVERFLOW

DST2:	SETOM ADBREN		;SET ADBR+ OR - EN FLAG.
	STORE DST2
	GO	SCSUB		;GO TO SC SUBROUTINE
	GO	DIVLOC

DST3:	MOVE AR,AD		;AR FM AD(J)
	LSH MQ,1		;MQ SHLT
	TLNN AD,400000		;ADDER NOT BIT ZERO
	TRO MQ,1		;TO MQ35
	STORE DST3
DST4:	GO	FSTDIV
	MOVE AD,0
	TRNN MQ,1		;MQ35(0)?
	MOVE AR,AD		;YES..AR FM AD(J)
	MOVE AD,AR		;AD AR+EN
	TLNE MA,DSF7		;DSF7(1)?
	MOVN AD,AD		;YES..NEGATE ADDER
	STORE DST4
DST5:	MOVE AR,MQ		;AR FM MQ(J) ;QUOTIENT
	MOVE MQ,AD		;MQ FM AD(J) ;REMAINDER
	MOVE AD,AR		;AD AR+EN
	TLNE IR,200000		;IR1(1)?
	MOVN AD,AR		;YES..AD AR-EN AND AD CRY36 SET
	TLNN IR,200000		;IR1(0)?
	ADDI AD,1		;YES.. AD AR+EN AND AD CRY36 SET
	STORE DST5
	TLNN IR,200000		;IR1(0)?
	JRST DIVEN		;YES..FLOATING DIVIDE
DIVT5:	TLNN MA,DSF7		;DSF7 NE BR0?
	JUMPGE BR, DIVT51
	TLNE MA,DSF7
	JUMPL BR,DIVT51
	MOVE AR,AD		;YES..AR FM AD(J)
DIVT51:	STORE DIVT5

DIVEN:	AOS (P)		;TO STORE TIME
	RTN			;RETURN +2

DST7:	TLNN IR,200000		;FDV?
	TLO PC,FOV		;YES..SET AR FOV
	TLO PC,AROV+DCK		;AROV SET, AR DCK SET
	STORE DST7
	RTN			;GO TO END OF STORE CYCLE.


;THE DIVIDE STEP FOR DIVIDE SUBROUTINE
DIVLOC:	SETOM ADBREN#
	MOVE AR,AD
	MOVE IRA
	CAIL 220		;IR FDV?
	JRST	DVLOCA		;NO.
	TLZ MQ,400000		;YES.
	TLZE MQ,1000
	TLO MQ,400000
DVLOCA:	ROTC AR,1
	TRC MQ,1
	GO	FSTDIV
	MOVE AD,0
	RTN


FSTDIV:	MOVE	0,AR
	TLNN AD,400000
	JUMPL BR,.+5		;XOR=0
	TLNE	AD,400000
	JUMPGE BR,.+3		;XOR=0
	SUB 0,BR		;XOR=1...SUBTRACT
	RTN
	ADD 0,BR		;XOR=0...ADD
	RTN

;SHIFT COUNTER
SCSUB:	STORE SCT0
SCSCTX:	TRNN SC,400
	JRST SCT4		;TIME 4 RETURN
	HRRI SC,1(SC)
	SKIPE ADBREN#
	JRST SCT2
SCT3:	XCT	@(P)
	SKIPE	NOSCT#		;DON'T PRINT SCT3 FLAG SET?
	JRST	SCSCTX		;YES.
SCT3A:	STORE	SCT3
	JRST SCSCTX
SCT4:	STORE SCT4
	AOS (P)		;INC RETURN
	RTN			;EXIT

SCT2:	SETZM ADBREN
	SKIPE	NOSCT#		;DON'T PRINT SCT2 FLAG SET?
	JRST	SCT3		;YES.
	STORE SCT2
	JRST SCT3

;BLOCK TRANSFER INST, CODE 251
BLTS:	ROT AR,^D18		;SWAP AR HALVES
	STORE ET0
	HRR MA,AR		;AR RT TO MA
	STORE ET1
	ADD AR,[1000001]	;AD AR+EN SET, AD+1 BOTH
	EXCH AR,MQ		;AR FM MQ(J), MQ FM AD(J)
	MCWR			;MEMORY WRITE
	STORM ET2
SBLT1:	TLZ AR,-1		;AR LT CLR
	HRR AR,MQ		;AR RT FM MQ(J)
	SETCM AD,BR		;AD BR-EN SET
	ADD AD,AR		;AD CRY36 CLR..(AD AR+EN SET)
	STORE BLTT1
	TLNE AD,1		;AD17(0)?
	JRST BLTT3		;NO. GO TO BLTT3
	HRRI PC,1(PC)		;YES. PC+1
	STORE BLTT2
	JRST SS9

BLTT3:	MOVE AR,MQ		;AR FM MQ(J)
	SETZ MQ,		;MQ CLR
	STORE BLTT3
	MOVEI 2,PCINH+FCCLT+1
	JRST FT6

;TIME PRINTER
;THIS ROUTINE PRINTS THE CONTENTS OF THE SEVERAL MACHINE
;REGISTERS AT VARIOUS TIMES IN THE INSTRUCTION CYCLE

PRINTA:	PUT	0		;SAVE AC0.
	SWITCH			;GO READ THE DATA SWITCHES.
	SETZM	NOSCT#		;CLR NO PNT SCT2 + 3 FLAG.
	TRNE	0,INHSCT	;DON'T PNT SCT2 + 3 BIT SET?
	SETOM	NOSCT		;YES. SET FLAG.
	MOVE	0,1
	PNTA
	MOVEI	0,TAB
	PNTA
	MOVE	0,PC
	GO	XPNT6
	MOVE	0,MA
	GO	XPNT6
	HRR	0,SC
	GO	XPNT3
	HLR	0,FE
	GO	XPNT3
	MOVE	0,AR
	GO	XPNTOC
	MOVE	0,MQ
	GO	XPNTOC
	MOVE	0,BR
	GO	XPNTOC
	GO	PCR
	GET	0		;RESTORE AC0.
	RTN
XPNT6:	TRNN	0,77
	JRST	OPNT6
	PNT6
	RTN

OPNT6:	MOVEI	[ASCIZ/0      /]
	PNTAL
	RTN

XPNT3:	TRNN	0,7
	JRST	OPNT3
	PNT3
	RTN

OPNT3:	MOVEI	[ASCIZ/0   /]
	PNTAL
	RTN

XPNTOC:	SKIPN	0
	JRST	OPNTOC
	PNTOCT
	RTN

OPNTOC:	MOVEI	[ASCIZ/0            /]
	PNTAL
	RTN
;PRINT THE INSTRUCTION, INITIAL AND FINAL RESULTS

HEADER:	SETZM	HDCNTL
	SAVE15		;SAVE FIRST 15 ACS
	GO	PCR
HEADP1:	GO	PCR
	SKIPN	PNTSIM
	JRST	.+4
	MOVE	LINCNT
	CAILE	^D46		;ROOM ON PAGE FOR INIT/FINAL
	GO	PCR1		;NO, START A NEW PAGE
	MOVEI	0,AST
HEADP2:	PNTA			;PRINT *
	SETOM	PNTSPC
	MOVE	0,(P)
HEADP3:	PNT6			;PRINT PC
	GO	PNTINS		;GO PRINT INSTRUCTION.
	MOVEI	0,TAB
	PNTA			;PRINT A TAB
HPAC:	HRR	MA,(P)
	ADD	MA,USERAC
	JUMPN	USERAC,.+3
	TRNN MA,777700
	ADDI MA,JA
	PUT	MA
	ANDI	MA,-1
	MOVE	0,@MA
	GET	MA
	SKIPE	CONNF
	JRST	HPIOC		;PRINT I/O DEVICE CODE
	ROT	0,-^D23
	ANDI	0,17
	PNTOCS			;PRINT AC
	MOVEI	0,COMMA
	PNTA			;PRINT A COMMA
HDEF:	PUT	MA
	ANDI	MA,-1
	MOVE 1,@MA
	GET	MA
	TLNE 1,20		;INDIRECT BIT ON?
	GO	PNTIND		;YES. GO PRINT AN AT SIGN
	PUT	MA
	ANDI	MA,-1
	MOVE	0,@MA
	GET	MA
	PUT	PNTSPC
	SETZM	PNTSPC
	PNT6			;PRINT E
	GET	PNTSPC

HIDX:	PUT	MA
	ANDI	MA,-1
	MOVE 1,@MA		;LOOK FOR INDEXING
	GET	MA
	TLNN 1, 17
	JRST	HAC
	MOVEI	0,LFP
	PNTA
	MOVE	0,1
	LSH	0,-^D18
	ANDI	0,17
	PNTOCS
	MOVEI	0,RTP
	PNTA
	JRST	HAC

HPIOC:	ROT	0,-^D24		;PRINT I/O DEVICE CODE
	ANDI	0,774
	PNTOCS
	JRST	HDEF-2
PNTIND:	MOVEI	0,ATSIN
	PNTA			;PRINT AN AT SIGN
	RTN

HAC:	SKIPE	HDCNTL
	JRST	HEND
	IFSWIT
	ANDI	2,37
	CAIN	2,20
	JRST	HTIME		;DON'T PRINT IF 20
	MOVEI	0,[ASCIZ/
INITIAL
C(AC)=/]
	PNTAL
	AOS	LINCNT
	AOS	LINCNT
	MOVE	0,-1(P)
	MOVE	0,@0
	PNTHW
	IFSWIT

HAC2:	TRNE 2,FACINH
	SETOM PFCE#
	MOVEM 1,PINST#
	ANDI 2,17		;MASK SWITCHES
	MOVE	0,-2(P)
	MOVE	0,@0
	CAIGE 2, 10
	CAIGE 2,4
	JRST CROCK1
	PUT	0
	MOVEI	[ASCIZ/  C(AC+1)=/]
	PNTAL
	POP	P,0
	PNTHW
HPCE:	CAIE 2, 1		;PRINT THE CONTENTS
	CAIN 2,7		;OF THE EFFECTIVE ADDRESS
	JRST HEIP		;DO NOT PRINT ON 1, 7 OR 10
	CAIN 2, 10
	JRST HEIP
	MOVE	0,-3(P)
	SKIPN PFCE#
	JRST HPCE1
	HRRZ	1,PINST
	ADD	1,USERAC
	JUMPN	USERAC,.+3
	TRNN 1,777700
	ADDI	1,JA
	PUT	1
	ANDI	1,-1
	MOVE 0,@1
	GET	1
HPCE1:	PUT	0
	MOVEI	[ASCIZ/
C(E)=/]
	PNTAL
	AOS	LINCNT
	POP	P,0
	PNTHW			;PRINT C(E)
	SKIPE P15#
	JRST CROCK7

HEIP:	MOVEI	0,[ASCIZ/
FINAL
/]
	PNTAL			;END OF FIRST LINE.
	AOS	LINCNT
	AOS	LINCNT
	SKIPN	PDLOVW
	JRST	HRESLT
	MOVEI	0,PDLOVF
	PNTAL
	SETZM	PDLOVW

HRESLT:	MOVE	0,CAC		;GET C(AC).
	CAIN 2,6
	JRST CROCK3
	JUMPE 2, .+3
	CAIE 2, 10
	CAIN 2, 11
	JRST CROCK3
	PUT	0
	MOVEI	[ASCIZ/C(AC)=/]
	PNTAL
	POP	P,0
	PNTHW			;PRINT AC.
HRAC2:	CAIE	2,4
	CAIN 2, 5
	JRST .+3
	CAIE 2, 7
	JRST CROCK2
	MOVEI	[ASCIZ/  C(AC+1)=/]
	PNTAL
	MOVE	0,CAC1
	PNTHW
HRPCE:	JUMPE 2,HRPCE1		;PRINT THE C(E)
	CAIE 2, 3		;RESULTS
	CAIN 2, 5
	JRST HRPCE1
	CAIN 2,6
	JRST HRPCE1
	CAIGE 2, 12
	JRST HTIME		;DO NOT PRINT C(E)
HRPCE1:	CAIN	2,16
	MOVE	0,PONTR#
	CAIN	2,16
	JRST	HRPCE2
	MOVE	0,CE
	SKIPN PFCE#
	JRST HRPCE2
	HRRZ	1,PINST
	ADD	1,USERAC
	JUMPN	USERAC,.+3
	TRNN 1,777700
	ADDI 1,JA
	PUT	1
	ANDI	1,-1
	MOVE 0,@1
	GET	1
HRPCE2:	PUT	0
	MOVEI	[ASCIZ/
C(E)=/]
	PNTAL
	AOS	LINCNT
	POP	P,0
	PNTHW
	SKIPE P15#
	JRST	CROC11		;END OF SECOND LINE.
HTIME:	SETZM	PFCE#
	MOVE	CONSW
	TRNE	INHMT
	JRST	HEND
	TLNE MA,MS+MT
	GO	TIMPNT		;PRINT TIME, AR, MQ, AND ETC.
HEND:	RST15			;END OF HEADER
	RTN			;PRINTOUT

P15:	0

TIMPNT:	GO	PCR
	GO	PCR
	MOVEI	0,TIMMES
	PNTAL
	GO	PCR
	RTN

TIMMES:	ASCIZ .TIME    PC     MA     SC  FE  AR           MQ           BR.
CROCK1:	CAIE 2,1
	CAIN 2,7
	JRST HEIP
	CAIN 2,10
	JRST HEIP
	CAIL 2,12
	JRST CROCK4
	JRST HPCE

CROCK2:	CAIN 2,6
	JRST SPCS13
	JUMPE 2,SPCS13
	CAIE 2,3
	CAIN 2,5
	JRST SPCS13
	CAIGE 2,12
	JRST HTIME
	CAIG 2,14
	JRST CROC10
	JRST HRPCE1
SPCS13:	JRST HRPCE1

CROCK3:	JRST HRAC2

CROCK4:	CAILE 2,14
	JRST CROCK5
	MOVE 1,-1(P)
	GO	CROC4
	JRST HEIP

CROC4:	CAIE 2,14
	HRRZ 1,1
	CAIN 2,14
	HLRZ 1,1
CROCK6:	CAIN 2,12
	ADDI 1,1
	CAMLE	1,VMEM
	RTN
	ADD	1,USERAC
	JUMPN	USERAC,.+3
	TRNN 1,777700
	ADDI 1,JA
	PUT	1
	ANDI	1,-1
	MOVE 0,@1
	GET	1
	PUT	0
	MOVEI	[ASCIZ/  C(C(ACR+1))=/]
	CAIN	2,13
	MOVEI	[ASCIZ/  C(C(ACR)=/]
	CAIN	2,14
	MOVEI	[ASCIZ/  C(C(ACL))=/]
	PNTAL
	POP	P,0
	PNTHW
	RTN

CROCK5:	SETOM P15#
	JRST HPCE
CROCK7:	HRRZ 1,@1
	ADD	1,USERAC
	JUMPN	USERAC,.+3
	TRNN	1,777700
	ADDI	1,JA
	MOVEI	[ASCIZ/  C(C(E))=/]
	PNTAL
	PUT	1
	ANDI	1,-1
	MOVE	0,@1
	GET	1
	PNTHW
	JRST HEIP

CROC10:	MOVE 1,CAC
	GO	CROC4
	JRST HTIME

CROC11:	CAIE 2,16
	JRST CROK11
	MOVEI	1,@PONTR#
	ADD	1,USERAC
	JUMPN	USERAC,.+3
	TRNN	1,777700
	ADDI	1,JA
	MOVEI	[ASCIZ/  C(C(E))=/]
	PNTAL
	PUT	1
	ANDI	1,-1
	MOVE	0,@1
	GET	1
	PNTHW
CROK11:	SETZM P15#
	JRST HTIME
IT0IN:	SETZM	HNGCNT#		;CLEAR HUNG COUNTER
	MOVEM	PC,PCSAVE#
	GO	IT0		;SIMULATE INSTRUCTION
	RTN

HUNGCK:	AOS	1,HNGCNT	;INCREMENT TIME STATE COUNTER
	CAIG	1,^D1000	;HUNG IN SIMULATION ?
	RTN			;NO, CONTINUE
	MOVEI	[ASCIZ/
**SIMULATOR ERROR**
INSTRUCTION HUNG UP/]
	PNTALF
	SETOM	HDCNTL		;SET HEADER TO RETURN AFTER INST
	MOVE	0,PCSAVE
	GO	HEADER+1	;PRINT INST
	MOVEI	CRLF
	PNTAF
HNGERR:	JRST	.+1
	ERRHLT
	JRST	DDTSRT
INT:	0
	SETZM	PDLOVW		;CLEAR PUSHDOWN LIST OVERFLOW FLAG.
	HRLZI MA,USERAC
	SETZB	USERAC,HDCNTL#
	MOVE	USERAC,RELOC
	HRRZ	PC,INPC		;SET PSEUDO PROGRAM COUNTER
	JRST	@INT		;RETURN.
RELOC:	0

;SIMULATE INITIAL AND FINAL
;RESULTS PRINTED

SIMIF:	JSR INT
	TLZ MA,MT+MS+SU
	TLO MA,RUN+SU
	SETZM	PNTCTL#
	HRRZ	PC
	CAMGE	CNTLPC
	JRST	SIMIF1
	CAMLE	UPRPC
	JRST	SIMIF1
	MOVE	OFFSET(PC)
	AND	MASK
	CAMN	INSTR
	SETOM	PNTCTL		;PRINT THIS INSTRUCTION
SIMIF1:	GO	IT0IN		;GO TO SIMULATE INST
	SKIPE	PNTCTL
	GO	HEADER		;PRINT THE RESULTS
	TLNE MA, RUN		;IF RUN ON A ONE
	JRST SIMIF+1		;GO TO NEXT INST
	JRST	DDTEX		;EXIT
;SIMULATE THE MACHINE TIMES
;FOR ONE INSTRUCTION

SMMT1:	JSR INT
	PUT	PC		;SAVE PC ON PUSH LIST
	GO	IT0IN		;SIMULATE THE INST
	TLO MA,MS+MT+SU
	PUT	0
	SWITCH
	TRNE	0,INHMT
	TLZ	MA,MS+MT
	POP	P,0
	GO	HEADER		;PRINT INITIAL FINAL
	GET	PC		;PRINT MACHINE STATES
	GO	IT0IN		;FOR THE INST AT PC
	RTN			;EXIT TO MONITOR

;SIMULATE THE MEMORY STOP TIMES
SIMMS:	JSR INT
	TLO MA,RUN+SU
	TLZ MA,MT+MS+ERR
	HRRZ	PC
	CAMGE	CNTLPC
	JRST	SIMMS1
	CAMLE	UPRPC
	JRST	SIMMS1
	MOVE	OFFSET(PC)
	AND	MASK
	CAMN	INSTR
	TLZ	MA,SU
SIMMS1:	PUT	PC	;SAVE PC ON LIST
	GO	IT0IN
	GET	0
	TLON	MA,SU
	TLO	MA,ERR
	TLNN	MA,RUN
	JRST	VMHALT
	TLNE	MA,ERR
	SKIPA	PC,0
	JRST	SIMMS+3
	TLO	MA,MS
	GO	HEADER		;PRINT INITIAL FINAL
	TLNE	MA,ERR
	GO	IT0IN
	JRST SIMMS+1		;GO TO NEXT INSTRUCTION
;SIMULATE THIS PROGRAM

SIMPRG:	JSR INT
	TLO MA,RUN+SU
	TLZ MA,MT+MS+ERR

	MOVE	OFFSET(PC)	;IS THIS SPECIAL LEAVE SIMULATION INST ?
	CAMN	[776000,,SEXIT1]
	JRST	@0		;YES, RETURN TO COMMAND MODE

	HRRZ	PC
	CAMGE	CNTLPC
	JRST	SIMPR1
	CAMLE	UPRPC
	JRST	SIMPR1
	MOVE	OFFSET(PC)
	AND	MASK
	CAMN	INSTR
	TLZ	MA,SU

SIMPR1:	PUT	PC		;SAVE THE PC
	GO	IT0IN		;SIMULATE
	GET	0		;OLD PC TO ZERO

	TLON	MA,SU
	TLO	MA,ERR
	TLNN	MA,RUN
	JRST	VMHALT		;VIRTUAL MACHINE HALT

	TLNE	MA,ERR
	SKIPA PC,0		;RUN = 0 OR ERROR
	JRST SIMPRG+3
	TLO MA,MT+MS
	GO	HEADER		;PRINT INITIAL FINAL.
	SWITCH
	TRNE	INHMT		;INHIBIT MACHINE TIMES ?
	TLZ	MA,MS+MT	;YES
	TLNE	MA,ERR
	GO	IT0IN

	TTALTM			;IF ALTMODE, GO TO DDT
	JRST	.+2
	JRST	DDTEX5		;CONTINUE WITH "SIMCON$G"

SIMCON:	JRST SIMPRG+1
SMNST1:	JSR	INT
	TLZ	MA,700000
	TLO	MA,RUN+SU	;SET RUN AND STORE USER FLAGS.
	GO	IT0IN		;SIMULATE THE INST.
	RTN			;RETURN TO MAIN PROG.

INPC:	0,,30000
MASK:	-1
INSTR:	0
CNTLPC:	0
UPRPC:	0,,-1
SWITCH:	0

ACS:
JA:	BLOCK 200	;JOB STORAGE AREA
;BYTE FIRST CYCLE

SBYTE:	MOVE 0,IRA
	CAIN	130		;IR UFA?
	JRST	SFAD		;YES.
	CAIN	131		;IR DFN?
	JRST	SDFN		;YES.
	TLNN IR,5000
	JRST SFSC		;FLOAT SCALE
	SKIPE	BISF		;2ND PART OF BYTE ?
	JRST SECOND		;SECOND CYCLE OF BYTE
	TLNE	PC,BIS		;PC BIS FLAG SET ?
	JRST	BYT6		;YES, NO INCREMENT
	TLC IR,5000
	TLCE IR,5000
	JRST INCBYT		;INCREMENT BYTE

BYT6:	STORE ET0
	HLRZ SCAD,AR
	ROT SCAD,-6
	ANDI SCAD,77
	TRC SCAD,-1		;SCAD AR6-11 EN SET..-S
	STORE BYT6
BYT7:	HRRI SC,1(SCAD)
	STORE BYT7
	GO	SCSUB		;SHIFT SUBROUTINE
	GO	BYTMQ		;MQ MASK OF SIZE
BYT7A:	TLO PC,BIS
	SETOM	BISF		;2ND PART OF BYTE FIX
	HLRZ SCAD,AR
	ASH SCAD,-^D12
	HRRM SCAD,SC		;SC FM AR0-5[1]...P
	STORE BYT7A
	MOVEM	AR,PONTR#	;SAVE NEW POINTER FOR PNT ROUTINE
	MOVE BR		;AD BR+EN SET.
	TLZ 777740
	TRZ -1
	IORM IR
	JRST IT1+1
BYTMQ:	LSH MQ,1		;SUBROUTINE TO 
	TRO MQ,1
	RTN			;MAKE A MASK IN MQ

;BYTE ,FIRST CYCLE INCREMENT
INCBYT:	STORE ET0
BYT1:	HLRZ SCAD,AR
	ASH SCAD,-^D12
	HRRM SCAD,SC		;SC FM AR0-5[1]...P
	HLRZ AR
	ASH -6
	ANDI 77
	SUB SCAD,0		;SCAD AR6-11 EN SET
	TRC -1
	PUT	0
	STORE BYT1
INCBY1:	TRNN SCAD,400
	JRST BYT4

BYT2:	TRZ SC,-1		;SC CLR
	ADDI AR,1		;AR FM AD(J) ; Y+1
	STORE BYT2
BYT3:	HRRI SC,144		;SC GET 36 DECIMAL
	STORE BYT3
	HLRZ AR
	ASH -6
	ANDI 77
	HRRZ SCAD,SC
	SUB SCAD,0
	JRST INCBY1
BYT4:	HRLZ SCAD
	LSH ^D12
	TLZ AR,770000
	XORM AR			;AR0-5 FM SCAD3-8(J)
	TRZ SC,-1		;SC CLR
	GET	SCAD		;ADDER GET AR 6-11
	STORE BYT4
	TLNN IR,4000		;IR IBP?
	JRST SS9-1		;YES.
	MCWR
	JRST BYT7

;BYTE SECOND PART
SECOND:	TRC SC,-1		;SCAD SC COMP SET, SCAD SC NEG SETUP
	HRRI SC,1(SC)		;SC FM SCAD(J)
	STORE ET0
	TLZ PC,BIS
	TLNE IR,2000
	JRST DPBET0		;GO TO DEPOSIT BYTES
	GO	SCSUB		;CALL SHIFT SUBROUTINE
LBT1:	LSH AR,-1		;FOR LOAD BYTE
	AND AR,MQ		;AR FM MQ[0]
	STORE LBT1
	JRST ST0

;DEPOSIT BYTES
DPBET0:	GO	SCSUB		;CALL SHIFT SUBROUTINE
	GO	BYTSH		;SHIFT AR,MQ LEFT
DBT1:	MOVE AD,BR		;AD BR+EN SET
	STORE DBT1
DBT2:	MOVE BR,AR		;BR FM AR(J)
	MOVE AR,MQ		;AR FM MQ(J)
	MOVE MQ,AD		;MQ FM AD(J)
	SETCM AD,AR		;AD AR-EN SET
	STORE DBT2
DBT3:	AND BR,AR		;BR FM AR[0]
	MOVE AR,AD		;AR FM AD(J)
	MOVE AD,BR		;AD BR+EN SET
	STORE DBT3
DBT4:	AND AR,MQ		;AR FM MQ[0]
	STORE DBT4
	IOR AR,AD		;AR FM AD[1]
DBT5:	STORE DBT5
	JRST ST0		;GO TO STORE TIME

BYTSH:	LSH AR,1		;SHIFT AR MQ
	LSH MQ,1		;SEPERATELY
	RTN

PDLOVF:	ASCIZ ?
PUSHDOWN LIST OVERFLOW.
?