INSERT[D1LANG];
INSERT[ALUD1];
TITLE[D1TEST1];

*THIS FILE IS A TEST OF THE MICROASSEMBLER

MP[BIT0,100000];	MP[BIT4,4000];	MP[BIT10,200];	MP[BIT14,10];
MP[BIT1, 40000];	MP[BIT5,2000];	MP[BIT11,100];	MP[BIT15, 4];
MP[BIT2, 20000];	MP[BIT6,1000];	MP[BIT12, 40];	MP[BIT16, 2];
MP[BIT3, 10000];	MP[BIT7, 400];	MP[BIT13, 20];	MP[BIT17, 1];

SP[LEFTHALF,BIT0,BIT1,BIT2,BIT3,7000,BIT7];
NSP[RIGHTHALF,BIT0,BIT1,BIT2,BIT3,BIT4,3400];

RMREGION[RGN1];
RESERVE[2];
RVN[RTEMP1];
RVN[RTEMP2];
RV[BLAST,BIT1,BIT2,BIT4,BIT6,BIT10,BIT12];
RV[LFTHLF,LEFTHALF];
RV[RTHLF,RIGHTHALF];
RVN[SVLINK];

RVN[R1A]; RVN[R1B]; RV[R1C,BIT1]; RVN[R1D];
RVN[R1E]; RVN[R1F]; RVN[R1G]; RVN[R1H];

RMREGION[RGN2];
RESERVE[2];
RVN[RTEMP3];
RVN[RTEMP4];
RV[FOO,20,BIT2,BIT17];

RVREL[RSV0,0];
RVREL[RSV1,1];

MC[MIDDLE,BIT4,BIT5,BIT6,BIT7,377];
MSC[TWO,2];
MSC[SIX,BIT16,BIT15];
NMC[LFOUR,RIGHTHALF,BIT4,BIT5,BIT6,BIT7];

DEVICE[DSP,123];
BR[MDS,0]; BR[L,1]; BR[G,2];

TOP LEVEL;

*ASSEMBLY OF CONSTANTS, SMALL CONSTANTS, RM←, T←, AND A LITTLE ALU STUFF
START:	T←LFOUR, GLOBAL;
	RBASE←RBASE[RGN1];
BRNCH0:	RTEMP2←MIDDLE;
BRNCH1:	RTEMP1←(RTEMP1) OR (34C);
BRNCH2:	T←ID OR (BLAST);
BRNCH4:	CNT←2S;
BRNCH3:	RTEMP1←T←177400C;
BRNCH6:	RTEMP1←MD, T←(RTEMP1) OR (1000C);
BRNCH9:	T←MD, RTEMP1←(RTEMP1) OR (3377C);
BRNCH8:	RTEMP1←((RTEMP1) AND NOT T) RSH 1;
BRNCH7:	RTEMP3←RTEMP1;
	RTEMP1←T←MD;

*BRANCHING CLAUSES
BRNCH:	GOTO[.+2,ALU<0], WAKEUP[FLT];
	BRANCH[.+1];
	T←ID, GOTO[BRNCH,R ODD];
	BRANCH[BRNCH], RSV0←NOT(LINK);
	BRANCH[BRNCH], RSV1←TIOA&STKP;
SUBROUTINE;
	CORETURN, T←MD, TISID, RSV0←T;
*	SCORETURN[ALU=0];
	RETURN, RSV0←SHC;
TOPLEVEL;
	CALL[START], STORE←RSV0, DBUF←Q;
	CALL[START], T←POINTERS;
	BRANCH[.+1], T←Q;
	BRANCH[.+2,ALU>=0], T←ID OR (Q);
	DBLBRANCH[BRNCH4,BRNCH5,ALU=0], T←ID OR (MD);
	GOTO[BRNCH2,ALU#0], T←(RSV0) OR Q;
	GOTO[BRNCH3,R EVEN];
	DBLGOTO[BRNCH6,.+2,R EVEN,R>=0];
	BRANCH[.+1];
*	DBLCALL[BRNCH7,BRNCH8,CARRY',CNT=0&-1];
SET[XTASK,1];
	GOTO[.+2,IOATTEN',ALU<0];
	BRANCH[.+1];
	BRANCH[.+1];
SET[XTASK,0];
	IFUJUMP[0];
	IFUJUMP[3,R ODD];
	IFUJUMP[3];
	RDTPC←T;
	RDTPC←EMU;
	LDTPC←T;
	LDTPC←FLT;
SUBROUTINE;
BRNCH5:	RETURN;
	RETURN[ALU=0];
TOP LEVEL;
	IMLHR0POK←T;
	IMLHR0PBAD←T;
	IMLHR0'POK←T;
	IMLHR0'PBAD←T;
	IMRHBPOK←T;
	IMRHBPBAD←T;
	IMRHB'POK←T;
	IMRHB'PBAD←T;

*ALU OPERATIONS
TALU0:	RTEMP1←A0;
	T←A1;

TALU1:	RTEMP1←T;
	RTEMP1←T, B←RTEMP1;
	T←RTEMP1;
	T←RTEMP1, B←177401C;
	T←NOT(RTEMP1);
	T←NOT(RTEMP1), B←177777C;
	T←NOT T;
	T←NOT T, B←MD;
	T←(17S)+(T);
	T←NOT(17S);
	T←(RTEMP1) AND (177400C);
	T←Q OR MD;
	T←(ID) OR (MD);
	T←(RTEMP1) OR (PCX');
	T←T#(RTEMP1);
	T←(RTEMP1)#T;
	T←(RTEMP1)#(T);
	T←(T)#(RTEMP1);
	T←T#MD;
	T←T+MD;
	T←T+(RTEMP1);
TALU2:	T←T # (PIPE1);
	T←T#(PIPE1);
	T←T XOR (PIPE1);
	T←(T) XOR (PIPE1);
	T←T+(PCX');
	T←(RTEMP1), XORCARRY;
	T←NOT T;
	T←NOT(RTEMP1);
	T←NOT T;
	T←NOT T;
	T←NOT ID;
	T←NOT ID;

SET[TIMTAB,101];
	DATA[(TIMD: BYT0[BIT10,BIT7] BYT1[BIT11] BYT2[BIT12] BYT3[BIT13] AT[TIMTAB])];
	DATA[(BYT0[BIT7] BYT1[BIT15] BYT2[BIT13] BYT3[BIT14] AT[TIMTAB,1])];

TDISP:	T←BIGBDISPATCH←RTEMP1;
	RTEMP1←T, MULTIPLY;
	BDISPATCH←T;

TAMUX:	T←T, B←Q;	*SHOULD USE ASEL
	T←ID;	*SHOULD USE ASEL
	T←RTEMP1, B←34C;	*SHOULD USE ASEL
	A←T, B←Q, RTEMP1←SHIFTNOMASK;	*SHOULD USE FF FOR T
	A←RTEMP1, B←Q, RTEMP1←SHIFTLMASK;	*SHOULD USE FF FOR RTEMP1
	A←RTEMP1, B←Q, RTEMP1←SHIFTRMASK;	*SHOULD USE FF FOR RTEMP1
	T←SHIFTBOTHMASKS[RTEMP1];
	A←Q, RTEMP1←SHMDLMASK, GOTO[TAMUX,ALU>=0];
	A←MD, RTEMP1←SHMDBOTHMASKS;
	T←XSHIFTNOMASK; T←XSHIFTRMASK; T←XSHIFTLMASK; T←XSHIFTBOTHMASKS;
	T←XSHMDRMASK; T←XSHMDLMASK; T←XSHMDBOTHMASKS;
TNEWSH:	RTEMP1←LSH[T,0];
	RTEMP1←LSH[T,1,MD];
	RTEMP1←LSH[RTEMP1,2,0];
	T←LSH[RTEMP1,17];
	RTEMP1←RSH[T,0];
	RTEMP1←RSH[RTEMP1,17];
	RTEMP1←RCY[T,RTEMP1,0];
	RTEMP1←RCY[RTEMP1,T,13];
	T←LCY[T,RTEMP1,0];
	T←LCY[RTEMP1,T,17];
	T←LDF[T,1,13,MD];
	T←LDF[RTEMP1,1,13,MD];
	T←LDF[RTEMP1,17,1];
	RTEMP1←LDF[RTEMP1,2,12];
	BRANCH[.+1];
	RTEMP1←DPF[RTEMP1,2,12];
	RTEMP1←DPF[RTEMP1,2,12,MD];
	T←DPF[T,1,13];
	T←DPF[T,15,2,0];

TFF20:	T←T-(RTEMP1)-1, XORCARRY;
	T←T-(RTEMP1)-1, XORSAVEDCARRY;
	T←T+1, CARRY20;

TFF30:	T←INPUT;
	T←INPUTNOPE;
	FETCH←T, T←RTEMP1, RISID;
	FETCH←RTEMP1, T←T, TISID;
	OUTPUT←T;
	FLIPMEMBASE;

TFF70:	BIGBDISPATCH←T;
	BDISPATCH←T;
	MULTIPLY;
	Q←LINK;
	T←RTEMP1←MD;
	FREEZEBC;
	NOFF;

KNOWRBASE[RGN1];

TASEL:	RBASE←RBASE[RTEMP1];
	T←(RTEMP1) OR T, DIVIDE;
	MULTIPLY;
	MEMBX←0S;
	MEMBX←3S;
	MEMBASE←10S;
	MEMBASE←30S;
	MEMBASE←L;
	MEMBASE←G;
	MEMBASEX←L;
*THESE FIRST FOUR SHOULD LEAVE FA[X] FOR RTEMP1
	FETCH←RTEMP1;
	STORE←RTEMP1, DBUF←T;
	T←(FETCH←T), XORCARRY;
	STORE←T, DBUF←377C;
	T←(FETCH←Q), XORCARRY;
	T←(FETCH←MD), XORCARRY;
	T←(FETCH←ID), XORCARRY;
	XORCARRY, T←(STORE←Q);
	XORCARRY, T←(STORE←MD);
	XORCARRY, T←(STORE←ID);

SET[XTASK,14];
	IOSTORE←RTEMP1;
	IOFETCH←RTEMP1;
	BLOCK;

SET[XTASK,0];
	IFETCH←RTEMP1;
	LONGFETCH←T, B←RTEMP1;
	FETCH←RTEMP1, FREEZEBC;
	FETCH←0S;
	FETCH←17S;
	PREFETCH←RTEMP1;
	PREFETCH←T;
	PREFETCH←Q;
	MAP←RTEMP1, MAPBUF←T;
	MAP←T, T←MAPBUF←RTEMP1;
	MAP←MD, MAPBUF←T;
	MAP←Q, MAPBUF←Q;
	FLUSH←T;
	FLUSH←RTEMP1;
	FLUSH←MD;
	FLUSH←RTEMP1;
	DUMMYREF←RTEMP1;
	T←1S;

SET[XTASK,1];
	Q←T;
	Q←RTEMP1;
	Q←MD;

TFF100:	PCF←T;
	IFUTEST←T;
	IFUTICK;
	MEMBASE←T;
	RBASE←T;
	POINTERS←T;

TFF120:	LOADTESTSYNDROME;
	LOADMCR[T,RTEMP1];
	BRLO←T;
	BRHI←T;
	PROCSRN←Q;
	CFLAGS←T;

TFF130:	MOS←T;
	GENOUT←T;
	RESCHEDULE;
	NORESCHEDULE;
	IFUMRH←T;
	IFUMLH←T;
	IFURESET;
	BRKINS←T;

TFF140:	USEDMD;
	MIDASSTROBE←T;
	TASKINGOFF;
	TASKINGON;
	STKP←Q;
	STKP←T;
	STKP←MD;
	STKP←B;
	STKP←RTEMP1;
	RESTORESTKP;
	CNT←Q;
	CNT←MD;
	CNT←T;
	CNT←RTEMP1;
	CNT←B;
	LINK←Q;

TFF150:	Q LSH 1;
	Q RSH 1;
	TIOA←Q;
	HOLD&TASKSIM←Q;
	WF←T;
	RF←T;
	SHC←Q;

TFF160:	T←FAULTINFO';
	T←PIPE0;
	T←VAHI;
	T←PIPE1;
	T←VALO;
	T←PIPE2';
	T←PIPE3';
	T←MAP';
	T←PIPE4';
	T←ERRORS';
	T←CONFIG';
	T←PIPE5';

TFF170:	T←JUNK';
	T←IFUMRH';
	T←IFUMLH';
	T←(T)+(PCX');
	T←DBUF;
	T←RWCPREG;
	T←LINK;

TFF200:	RBASE←0S;
	RBASE←RBASE[RTEMP1];
	TIOA[DSP];
	MEMBASEX←0S;
	MEMBASEX←3S;
	MEMBX←0S;
	MEMBX←3S;

TFF260:	T←(ALUFMRW←RTEMP1),ALUF[17];
	T←(ALUFMRW←T), ALUF[0];
	T←(ALUFMRW←Q), ALUF[16];
	T←(ALUFMRW←MD), ALUF[17];
	T←(ALUFMRW←B);
	T←ALUFMEM, ALUF[3];
	T←CNT;
	T←POINTERS;
	T←TIOA&STKP;
	T←SHC;

TFF270:	T←(RTEMP1) RSH 1;
	T←(T) RSH 1;
SET[XTASK,0];
	T←(ID) RSH 1;
SET[XTASK,1];
	T←(MD) RSH 1;
	T←(PD←Q) RSH 1;
	T←(RTEMP1) RCY 1;
	T←(RTEMP1) BRSH 1;
	DIVIDE;
	RTEMP1←(RTEMP1) XOR T, CDIVIDE;
	T←(T) LSH 1;
	T←(T) ARSH 1;

TFF>277:
	MEMBASE←0S;
	MEMBASE←37S;
	MEMBASE←L;
	MEMBASE←G;
	CNT←3S;
	CNT←20S;
	CNT←1S;
*New form of NOTIFY
	WAKEUP[FLT];
	WAKEUP[EMU];

	BRANCH[.+1];
TH3LIT:	T←25H;
	T←0H;
	T←13H;
	T←1H;
	T←31H;
	T←7H;
	T←14H;
	T←214H;
	T←222H;
	T←22H;
	T←35H;
	T←27H;
	T←23H;
	T←33H;
	T←200H;
	T←36H;
	BRANCH[.+1];

SET[XTASK,0];

TSTKP:	STKP←STKP+1, BREAKPOINT;
	STKP←STKP-1;
	STKP←STKP-2;
	STACK←T;
	STACK&+1←T;
	STACK&-1←T;
	STACK&-2←T;
	STACK-4←T;
	STACK-3←T;
	STACK-2←T;
	STACK-1←T;
	STACK+1←T;
	STACK+2←T;
	STACK+3←T;
	T←STACK;
	T←STACK&-1;
	T←STACK&+1;
	T←STACK&+3;
	T←STACK&+2;
	T←STACK&-3;
	T←STACK&-4;
	T←STACK&-2, BRANCH[.];

INSSET[0,1];

IFUREG[0,2,MDS,TFF150,17,1,0];	*LENGTH=2, NO N, SIGN-EXTEND, NO-PA
IFUJMP[1,2,L,TFF150,0];		*LEN=2, NO N, NO-SIGN-EXTEND, NO-PA
IFUJMP[2,1,L,TFF150,177740];
IFUJMP[3,1,L,TFF150,37];
IFUPAUSE[4,3,MDS,TFF150,1,1,1];	*LEN=3, N=1, SIGN-EXTEND, PA=1

END;