BUILTIN[M,2];		*Declare macro
BUILTIN[N,3];		*Declare neutral
BUILTIN[MEMORY,4];	*Declare MEMORY[NAME,WORDSIZE,LENGTH,SRCMACRO,
			*SINKMACRO]
BUILTIN[TARGET,5];
BUILTIN[DEFAULT,6];
BUILTIN[FLX,7];		*Declare field
BUILTIN[PF,10];		*Preassign value to field
BUILTIN[SET,11];	*Declare integer and set value
BUILTIN[ADD,12];	*Add up to 8 integers
BUILTIN[IP,13];		*Integer part of adddress
BUILTIN[IFSE,14];	*If string equal
BUILTIN[IFA,15];	*If any bits of field assigned
BUILTIN[IFE,16];	*If integers equal
BUILTIN[IFG,17];	*If integer #1 .gr. integer #2
BUILTIN[IFDEF,20];	*If symbol in symbol table and not unbound address
BUILTIN[IFME,21];	*If memory part of address .eq. string
BUILTIN[ER,22];		*Error message (ER[STRING,ABORTFLAG,INT])
BUILTIN[LIST,23];	*Set listing mode for memory
BUILTIN[INSERT,24];	*Insert file
BUILTIN[NOT,25];	*1's complement
BUILTIN[REPEAT,26];	*Repeat the text #2 #1 times
BUILTIN[OR,27];		*Inclusive or up to 8 integers
BUILTIN[XOR,30];	*Exclusive or up to 8 integers
BUILTIN[AND,31];	*And up to 8 integers
BUILTIN[COMCHAR,32];	*Set comment char for conditional assemblies
*BUILTIN[BITTABLE,33];	*Makes #1 a bit table of length #2 bits
*BUILTIN[GETBIT,34];	*Is the bit in bit table #1 at pos. #2
*BUILTIN[SETBIT,35];	*SETBIT[TABLE,1STBIT,NBITS,DISTANCE,VAL]
*BUILTIN[FINDBIT,36];	*FINDBIT[TABLE,1STBIT,NBITS,DISTANCE,HOPDISTANCE,NHOPS]
*BUILTIN[MEMBT,37];	*MEMBT[MEMORY,TABLE] creates a bit table for memory
BUILTIN[LSHIFT,40];	*Shifts the integer #1 left #2 positions
BUILTIN[RSHIFT,41];	*Shifts the integer #1 right #2 positions
BUILTIN[FVAL,42];	*FVAL[FIELD] is an integer whose value is the
			*current contents of the field
BUILTIN[SELECT,43];	*#1 is an integer .ge. 0 and .le. 7.  Evaluates
			*#2 if #1 = 0, ..., #9 if #1 = 7.  Error if #1 > 7
BUILTIN[SETPOST,44];	*Set post-evaluation macro (SETPOST[MEM,MACRO])
BUILTIN[LISTFIELDS,46];	*LISTFIELDS[mem,word] assembles word as for DEFAULT
			*and the 1-bit denote the right-most bits of
			*fields in the octal listing.
*BUILTIN[SETMBEXT,47];	*Set binary output file extension (default .MB)
BUILTIN[SUB,50];	*SUB[a1,a2,...,an] = a1-a2-...-an (16-bit args)

COMCHAR[~];		*Makes "*~" Work like "%" at beginning of lines

ER[D1DLANG-model1.4/30/80];	*Print release date on .ER file

*Memory declarations must have names and sizes agreeing with Midas.
M[W,];			*Dummy macro required for memory defs.
MEMORY[LDR,44,140,W,W];	*Alto memory holding instructions that will be
			*executed by ramming into MIR (assembled in IM
			*format, not involuted MIR format)
MEMORY[MDATA,44,10,W,W];	*Alto memory for BITS-CHECKED, etc.
MEMORY[MADDR,40,15,W,W];	*Alto memory for LOW-ADDRESS, etc.
MEMORY[DMUX,20,200,W,W];	*DMUX
MEMORY[$ABSOLUTE,10,77777,W,W]; *Wrong length, but Micro can't handle
			*larger lengths (want 200000 here).
MEMORY[$ABS,20,77777,W,W];	***Want 100000 here after Micro fix
MEMORY[MSTAT,40,24,W,W];

LDR[LDRLC,0];		*Location counter for LDR

SET[XTASK,0];

%"TITLE" outputs the file name and the value of ILC on the .ER file
to help correleate errors with source statements.  It also resets
various assembly flags to standard states.
%
M[TITLE,(ER[#1] SET[XTASK,0] TARGET[LDRLC])];
M[END,(ER[Last.location...LDRLC=,0,IP[LDRLC]])];

*LDR memory field definitions
FLX[RSTK,0,3];		*RM address or STK modification
  FLX[RSTK13,1,3];	*RSTK1 is parity bad for IM write
			*RSTK.2 is value for RSTK.0 on IM l.h. write,
			*or value for BLOCK on IM r.h. write.
			*RSTK.3 is 0 for l.h. write, 1 for r.h. write
  FLX[RSTK23,2,3];	*Byte select for READIM
FLX[ALUF,4,7];		*ALU function select (addresses ALUFM)
FLX[BSEL,10,12];	*Source for B
  FLX[BSEL0,10,10];	*High bit of BSEL (indicates constant selected)
FLX[LC,13,15];		*Source (H3,Md) and loading for RM/STK and T
FLX[ASEL,16,20];	*A operation select
  FLX[ASEL0,16,16];
FLX[BLK,21,21];		*Block task (non-emu) -or- StackSelect (emulator)
FLX[FF,22,31];		*Function
  FLX[FA,22,23];	*FF[0:1] used with memory ops
  FLX[F1,22,25];	*FF[0:3] used with constants and FF shifts
  FLX[F2,26,31];	*FF[4:7] "
  FLX[FBC,24,31];	*FF[2:7] used when memory ops done
FLX[JCN,32,41];		*Jump control


%Second arg of LIST controls output as follows:
1 = (TAG) nnnn nnnn nnnn ...
2 = (TAG) F1←3, F2←4, ...
4 = numerically-ordered list of address symbols
10 = alphabetically-ordered list of address symbols
20 = (TAG) 1nnnnn 1nnnnn ... (16-bit rather than 12-bit printout)
%
LISTFIELDS[LDR,RSTK[1] ALUF[1] BSEL[1] LC[1] ASEL[1] BLK[1] FF[1] JCN[1]];
LIST[LDR,25]; LIST[MDATA,25]; LIST[MADDR,25]; LIST[$ABSOLUTE,25];
LIST[,25];


M[FFT,ER[FF.used.twice]];
M[FAT,ER[FA.used.twice]];
M[IMPB,ER[Impossible.B←]];
M[ILLIO,IFE[XTASK,0,,ER[#1.ill.in.io.task]]];
M[ILLEM,IFE[XTASK,0,ER[#1.ill.in.emulator]]];
M[TMARGS,ER[Too.many.args.for.#1]];

*Execute #1 if FF field not used as data, else #2
M[FFOK,IFE[FVAL[BSEL0],1,#2,#1]];

M[FF64,IFA[FBC,(FFT),FBC[#1]]];
M[FF256,IFA[FF,(FFT),FF[#1]]];

*The following macros define B destinations encodable as either
*FF64/FF256 or, if FF encodes an external B source, in BSEL.
*#1 is the value for FF, #2 for BSEL
M[FFBSL1,IFG[FVAL[FF],177,(IMPB),IFG[FVAL[FF],157,BSEL[#1],(IMPB)]]];
M[FFBSEL,IFA[FBC,IFE[FVAL[ASEL0],1,FFBSL1[#2],(IMPB)],FBC[#1]]];
M[FFBSEL256,IFA[FF,IFE[FVAL[ASEL0],1,FFBSL1[#2],(IMPB)],FF[#1]]];

%Three macros define parameters from which constants, small constants,
RM values, or IM data can be constructed:
   MP[NAME,OCTALSTRING] makes a parameter of NAME;
   SP[NAME,P1,P2,P3,P4,P5,P6,P7,P8] makes a parameter NAME equal to the sum
of P1, P2, P3, P4, P5, P6, P7, and P8, where the Pn may be parameters or
addresses.
   NSP[NAME,P1,P2,P3,P4,P5,P6,P7,P8] is ones complement of SP.

The parameter "NAME" is defined by the integer "NAME!", so it is ok
to use "NAME" for a constant as well as a parameter.  However, it is
illegal to define constants, small constants, addresses, etc. with
identical names.

"Literal" constants such as "322C", "177422C", "32400C", or "32377C"
or literal small constants such as "14S", etc. may be inserted in
microinstructions without previous definition.

Alternatively, constants may be constructed from parameters, integers,
and addresses using the following macros:
   MC[NAME,P1,P2,P3,P4,P5,P6,P7,P8] defines name as a constant with value =
sum of parameters P1, P2, P3, P4, P5, P6, P7, and P8;
   NMC[NAME,P1,P2,P3,P4,P5,P6,P7,P8] is the ones complement of MC;
   MSC[NAME,P1,P2,P3,P4] defines a small constant.

NOTE:  MC, NMC, and MSC also defined NAME as a parameter.
%

*Fields for initializaing 16-bit wide memories
FLX[E0,0,3]; FLX[E1,4,17];

*Macro to initialize 16-bit variables in the target memory.  This is
*done by writing 32100V (i.e., as a literal).
M[V,E1[#1] E0[#2]];

M[!,0];
M[MP,SET[#1!,#2]];
M[PX,IFDEF[#1!,#1!,#1]];
M[DPS,ADD[PX[#1],PX[#2],PX[#3],PX[#4],PX[#5],PX[#6],PX[#7],PX[#8]]];
M[SP,IFG[#0,11,TMARGS[#1],SET[#1!,DPS[#2,#3,#4,#5,#6,#7,#8,#9]]]];
M[NSP,IFG[#0,11,TMARGS[#1],SET[#1!,NOT[DPS[#2,#3,#4,#5,#6,#7,#8,#9]]]]];


M[C,IFE[AND[#3#2,177760],0,
  SET[!T1,ADD[LSHIFT[#2,4],RSHIFT[#1,10]]] SET[!T2,AND[#1,377]]
  IFE[!T1,0,BSEL[4]FF256[!T2],
    IFE[!T2,0,BSEL[6]FF256[!T1],
      IFE[!T1,377,BSEL[5]FF256[!T2],
        IFE[!T2,377,BSEL[7]FF256[!T1],ER[Illegal.constant]]
      ]
    ]
  ],ER[Constant.too.big]]B
];

M[-C,SUB[0,#3#2#1]C];

M[MC,IFG[#0,11,TMARGS[#1],
  SP[#1,DPS[#2,#3,#4,#5,#6,#7,#8,#9]] M[#1,ADD[#1!]C]]];

M[NMC,IFG[#0,11,TMARGS[#1],
  SP[#1,NOT[DPS[#2,#3,#4,#5,#6,#7,#8,#9]]] M[#1,ADD[#1!]C]]];

M[S,SET[SCONS,#2#1] SC];

M[MSC,IFG[#0,5,TMARGS[#1],SP[#1,DPS[#2,#3,#4,#5]] M[#1,ADD[#1!]S]]];

%ALU stuff
%

%#1 = before, A, between,
#2 = after B,
#3 = ALUF value,
#4 = text to get A source selected
%
%*Arithmetic (slow) ALU ops use this one
M[SDEFOP,M[#1RB#2,(ALUF[#3]PD,#4,B←RB)]
	M[#1T#2,(ALUF[#3]PD,#4,B←T)]
	M[#1B#2,(ALUF[#3]PD,#4)]
	M[#1MD#2,(ALUF[#3]PD,#4,B←MD)]
	M[#1Q#2,(ALUF[#3]PD,#4,B←Q)]
];

*Logical (fast) ALU ops use this one
M[DEFOP,M[#1XB#2,(ALUF[#3]#5PD,#4)]
	SDEFOP[#1,#2,#3,#4,#5]
];

M[ALUOP,DEFOP[#1RB#2,#3,#4,A←RB]
	DEFOP[#1T#2,#3,#4,A←T]
	DEFOP[#1ID#2,#3,#4,A←ID]
	DEFOP[#1MD#2,#3,#4,A←MD]
	DEFOP[#1A#2,#3,#4]
	DEFOP[#1Q#2,#3,#4,A←Q]
	DEFOP[#1SC#2,#3,#4,A←SC]
]

*Operations of one arg which can use either A or B are defined by both
*"ABOPA" and "ABOPB".  They prefer B for RB, T, MD, and Q.
*#1 = before A
*#2 = after A
*#3 = ALUF value

M[ABOPA,M[#1T#2,#1(IFA[BSEL,A←T,B←T])#2]
	M[#1ID#2,#1(A←ID)#2]
	M[#1SC#2,#1(A←SC)#2]
	M[#1A#2,ALUF[#3]PD]
];

M[ABOPB,M[#1RB#2,#1(IFA[BSEL,A←,B←]RB)#2]
	M[#1MD#2,#1(IFA[BSEL,A←,B←]MD)#2]
	M[#1Q#2,#1(IFA[BSEL,A←,B←]Q)#2]
	M[#1B#2,ALUF[#3] PD]
	M[#1XB#2,ALUF[#3] PD]
];
%

M[BOP,M[#1B#2,ALUF[#3]PD]
	M[#1XB#2,ALUF[#3]PD]
	M[#1T#2,#1(B←T)#2]
	M[#1RB#2,#1(B←RB)#2]
	M[#1MD#2,#1(B←MD)#2]
	M[#1Q#2,#1(B←Q)#2]
];

M[AOP,	M[#1T#2,#1(A←T)#2]
	M[#1RB#2,#1(A←RB)#2]
	M[#1ID#2,#1(A←ID)#2]
	M[#1MD#2,#1(A←MD)#2]
	M[#1Q#2,#1(A←Q)#2]
	M[#1SC#2,#1(A←SC)#2]
	M[#1A#2,ALUF[#3]PD]
];

BOP[PD←,,0,25];	*B control in loc. 0
AOP[NOT,,16,1];	*NOT A control in loc. 16

%The various sources and destinations connected by "←" reduce to the
following source and destination classes:
%
N[?];	*Illegal as source or destination
N[RB];	*Feed A, B, or shifter
N[T];	*Feed A or B
N[MD];	*Feed R, T, A, or B
N[B];	*B
N[XB];	*External B
N[A];	*A
N[Q];	*Feeds B (BSEL) or A (FF64)
N[ID];	*Feed A (ASEL or FA with mem ops) or B
N[PD];	*ALU ops, ←INPUT, ALUFMEM, POINTERS, CNT, SHC, or TIOA&STKP
N[SC];	*Small constants

*Destinations expecting small constant as source (also RBASE←B,
*MEMBASE←B, and CNT←B)
N[RBASE←]; N[CNT←]; N[MEMBASEX←]; N[MEMBASE←]; N[MEMBX←];

N[RB←];		N[T←];		N[B←];		N[PD←];		N[A←];
N[FETCH←];	N[STORE←];	N[MM←];

*Connection macros
M[B←B,B];	M[B←XB,XB];
M[MAPBUF←,B←];	M[DBUF←,B←];
M[A←A,A];	M[PD←PD,PD];


%The following macros fix up the LC field according to the R← and T←
selections.  T←R←MD is a special case requiring LC[5] and TGETSMD function.
%
M[RERR,ER[Illegal.R←]];
M[RMD,SELECT[FVAL[LC],PF[LC,4],LC[5],RERR,LC[5]FF64[75],,,RERR,RERR]];
M[RPD,SELECT[FVAL[LC],PF[LC,6],LC[7],,LC[2],RERR,RERR,,]];

M[RB←MD,MD(RMD)];
M[RB←B,PD←B(RPD)];	M[RB←XB,PD←XB(RPD)];
M[RB←T,PD←T(RPD)];
M[RB←RB,PD←RB(RPD)];
M[RB←A,PD←A(RPD)];
M[RB←ID,PD←ID(RPD)];
M[RB←PD,PD(RPD)];
M[RB←Q,PD←Q(RPD)];
M[RB←SC,PD←SC(RPD)];

M[TERR,ER[Illegal.T←]];
M[TMD,SELECT[FVAL[LC],PF[LC,3],TERR,,,LC[5]FF64[75],TERR,LC[2],TERR]];
M[TPD,SELECT[FVAL[LC],PF[LC,1],,TERR,TERR,LC[5],,LC[7],]];

M[T←MD,MD(TMD)];
M[T←B,PD←B(TPD)];	M[T←XB,PD←XB(TPD)];
M[T←T,PD←T(TPD)];
M[T←RB,PD←RB(TPD)];
M[T←A,PD←A(TPD)];
M[T←ID,PD←ID(TPD)];
M[T←PD,PD(TPD)];
M[T←Q,PD←Q(TPD)];
M[T←SC,PD←SC(TPD)];

M[EMCHK,BLK[1]RSTK13[#1]ILLIO[Stack.op]];
M[UEMCHK,BLK[1]RSTK[#1]ILLIO[Stack.op]];

*No StkP=0 underflow check on read because pointer will go negative.
*If also writing STK, write macro will impose the StkP←0 underflow check.
M[STACK&-4,RB(EMCHK[4])];
M[STACK&-3,RB(EMCHK[5])];
M[STACK&-2,RB(EMCHK[6])];
M[STACK&-1,RB(EMCHK[7])];

*StkP=0 underflow check is required
M[STACK,RB(UEMCHK[10])];
M[STACK&+1,RB(UEMCHK[11])];
M[STACK&+2,RB(UEMCHK[12])];
M[STACK&+3,RB(UEMCHK[13])];

*These modify StkP after writing, so no check for StkP←0 required
M[STACK&-4←,RB(EMCHK[4])];
M[STACK&-3←,RB(EMCHK[5])];
M[STACK&-2←,RB←(EMCHK[6])];
M[STACK&-1←,RB←(EMCHK[7])];
M[STACK&+1←,RB←(EMCHK[1])];
M[STACK&+2←,RB←(EMCHK[2])];
M[STACK&+3←,RB←(EMCHK[3])];

*These modify StkP before writing, so must check for StkP←0 when
*decrementing StkP and must use ModStkPBeforeW function.
M[STACK-4←,RB←(UEMCHK[14],FF64[27])];
M[STACK-3←,RB←(UEMCHK[15],FF64[27])];
M[STACK-2←,RB←(UEMCHK[16],FF64[27])];
M[STACK-1←,RB←(UEMCHK[17],FF64[27])];
M[STACK←,RB←(UEMCHK[10])];

M[STACK+1←,RB←(EMCHK[1],FF64[27])];
M[STACK+2←,RB←(EMCHK[2],FF64[27])];
M[STACK+3←,RB←(EMCHK[3],FF64[27])];

*For STKP change without reference
M[STKP-4,?(EMCHK[4])];
M[STKP-3,?(EMCHK[5])];
M[STKP-2,?(EMCHK[6])];
M[STKP-1,?(EMCHK[7])];
M[STKP+1,?(EMCHK[1])];
M[STKP+2,?(EMCHK[2])];
M[STKP+3,?(EMCHK[3])];

%Block
%
M[BLOCK,ILLEM[BLOCK]BLK[1]];

%Shifter stuff:
Result of a 0-masking Shift is
	[(ALU) & NOT (LMask U RMask)].
Result of an Md-masking Shift is
	[((ALU) & NOT (LMask U RMask))U(MD & (LMask U RMask)].
For these normally ALU←A←Shifter.  The Shifter output is complemented,
so normally the "NOT A" ALU operation is used.

Compound shift expressions of the forms:
  LSH[X,shiftcount,Y]	RSH[X,shiftcount,Y]
  LDF[X,size,pos,Y]	DPF[X,size,pos,Y]
  RCY[U,V,cyclecount]	LCY[U,V,cyclecount]
where X may be an RM address or T, shiftcount an integer in the range 0 to
17, Y either MD or 0 (defaulted to 0 if omitted), U and V are an RM address
and T in either order.
%
M[DOSF,(ASEL[7]BSEL[#1] PD,IFA[FF,(FFT),F1[#2] F2[#3]])];

M[DOLDF,(DOSF[IFSE[#1,T,7,4],SUB[20,#2],AND[17,SUB[20,#3]]],#1)];
M[DORSH,(DOSF[IFSE[#1,T,7,4],#2,AND[17,SUB[20,#2]]],#1)];
M[DODPF,(DOSF[IFSE[#1,T,7,4],SUB[20,#2,#3],#3],#1)];
M[DOLCY,IFSE[#1,T,
  (IFSE[#2,T,DOSF[7,0,#3],(DOSF[6,0,#3],#2)]),
  (IFSE[#2,T,DOSF[5,0,#3],(DOSF[4,0,#3],#2)],#1)
]];

*RCY reverses args of left cycle unless count = 0
M[RCY,ALUF[0] IFE[#3,0,DOLCY[#1,#2,0],DOLCY[#2,#1,SUB[20,#3]]]];
M[LCY,ALUF[0] DOLCY[#1,#2,#3]];
M[RSH,ALUF[IFSE[#3,MD,12,2]] DORSH[#1,#2]];
M[LDF,ALUF[IFSE[#4,MD,12,2]] DOLDF[#1,#2,#3]];
M[LSH,ALUF[IFSE[#3,MD,14,4]] (DOSF[IFSE[#1,T,7,4],0,#2],#1)];
M[DPF,ALUF[IFSE[#4,MD,16,6]] DODPF[#1,#2,#3]];

M[XRCY,ALUF[1] IFE[#3,0,DOLCY[#1,#2,0],DOLCY[#2,#1,SUB[20,#3]]]];
M[XLCY,ALUF[1] DOLCY[#1,#2,#3]];
M[XRSH,ALUF[IFSE[#3,MD,13,3]] DORSH[#1,#2]];
M[XLDF,ALUF[IFSE[#4,MD,13,3]] DOLDF[#1,#2,#3]];
M[XLSH,ALUF[IFSE[#3,MD,15,5]] (DOSF[IFSE[#1,T,7,4],0,#2],#1)];
M[XDPF,ALUF[IFSE[#4,MD,17,7]] DODPF[#1,#2,#3]];

*Shifter ops assembled as ALU outputs
M[SHFTOP,(ALUF[#1] ASEL[7] PD, #2)];

M[SHIFTNOMASK,SHFTOP[0,#1]];
M[SHIFTLMASK,SHFTOP[2,#1]];
M[SHIFTRMASK,SHFTOP[4,#1]];
M[SHIFTBOTHMASKS,SHFTOP[6,#1]];
M[SHMDNOMASK,SHFTOP[10,#1]];	*Pretty useless--same as SHIFTNOMASK
M[SHMDLMASK,SHFTOP[12,#1]];
M[SHMDRMASK,SHFTOP[14,#1]];
M[SHMDBOTHMASKS,SHFTOP[16,#1]];

M[XSHIFTNOMASK,SHFTOP[1,#1]];
M[XSHIFTLMASK,SHFTOP[3,#1]];
M[XSHIFTRMASK,SHFTOP[5,#1]];
M[XSHIFTBOTHMASKS,SHFTOP[7,#1]];
M[XSHMDNOMASK,SHFTOP[11,#1]];
M[XSHMDLMASK,SHFTOP[13,#1]];
M[XSHMDRMASK,SHFTOP[15,#1]];
M[XSHMDBOTHMASKS,SHFTOP[17,#1]];

%Stuff for ASEL field
%
M[A←RB,IFE[FVAL[ASEL],7,FF64[20],ASEL[4]] A];
M[A←ID,ASEL[5] ILLIO[ID] A];
M[A←T,IFE[FVAL[ASEL],7,FF64[21],ASEL[6]] A];
*ASEL=7 is shifts, defined earlier
M[A←MD,FF64[22] A];
M[A←Q,FF64[23] A];
M[A←SC,IFG[20,SCONS,FF64[SCONS],ER[Illegal.A←SC]] A];

M[PRISRC,IFE[FVAL[BSEL0],1,,IFA[FA,(FAT),PF[FA,3]]] A];
M[SECSRC,IFA[FA,(FAT),FA[#1]]];
M[SREF0,ASEL[0] IFA[FA,(FAT),FA[#1]] MM←];
M[SREF1,ASEL[1] IFA[FA,(FAT),FA[#1]] MM←];

*Illegal use of an FF > 77 to the left of a Fetch←/Store← with
*RM/T as source is not detected as an error.
M[FETCH←RB,ASEL[1] PRISRC];
M[FETCH←T,ASEL[3] PRISRC];
M[FETCH←MD,ASEL[3] SECSRC[0] A];
M[FETCH←ID,ASEL[3] SECSRC[1] A];
M[FETCH←Q,ASEL[3] SECSRC[2] A];
M[FETCH←SC,ASEL[1] SECSRC[3] A←SC];

M[STORE←RB,ASEL[0] PRISRC];
M[STORE←T,ASEL[2] PRISRC];
M[STORE←MD,ASEL[2] SECSRC[0] A];
M[STORE←ID,ASEL[2] SECSRC[1] A];
M[STORE←Q,ASEL[2] SECSRC[2] A];
M[STORE←SC,ASEL[0] SECSRC[3] A←SC];

M[PREFETCH←,SREF0[0]];
M[MAP←,ILLIO[MAP←]SREF0[1]];
*MAP← with READMAP FF decode (only legal source is RM)
M[RMAP←,ILLIO[RMAP←] ASEL[0] FF256[131] MM←];
M[IOFETCH←,ILLEM[IOFETCH←]SREF0[1]];
M[LONGFETCH←,SREF0[2]];
M[DUMMYREF←,SREF1[0]];
M[FLUSH←,ILLIO[FLUSH←]SREF1[1]];
M[IOSTORE←,ILLEM[IOSTORE←]SREF1[1]];
M[IFETCH←,ILLIO[IFETCH←]SREF1[2]];

M[MM←A,A];
M[MM←RB,A];
M[MM←T,FF64[21] A];
M[MM←MD,FF64[22] A];
M[MM←Q,FF64[23] A];
M[MM←SC,A←SC];


%Stuff for BSEL
%
M[B←MD,BSEL[0] B];
M[B←RB,BSEL[1] B];
M[B←T,BSEL[2] B];
M[B←Q,IFG[FVAL[BSEL],3,IFE[FVAL[ASEL],7,,ER[BSEL.already.set]],BSEL[3]] B];
*BSEL = 4,5,6,7 are (0,,FF), (377,FF), (FF,,0), and (FF,,377)

%Stuff for 100 functions and branch conditions:
%

*FF= 0 TO 17 are A←small constants, given earlier
*FF=20 to 23 select A sources, defined with ASEL stuff

M[XORCARRY,FF64[24] ?];
M[XORSAVEDCARRY,FF64[25]?];
M[CARRY20,FF64[26] ?];
*27 is MODSTKPBEFOREW, used implicitly
*30 undefined
*31 is READMAP, used implicitly in RMAP←
M[INPUT,FF64[32] PD];
M[INPUTNOPE,FF64[33] PD];
M[RISID,ILLIO[RISID]FF64[34] ?];
M[TISID,ILLIO[TISID]FF64[35] ?];
M[OUTPUT←,FF64[36] B←];
M[FLIPMEMBASE,FF64[37]?];

*40 to 57 supply RSTK for write, used implicitly
*60 to 67 are fast branches defined with control

M[BIGBDISPATCH←,FF64[70] B←];	*256-way B dispatch
M[BDISPATCH←,FF64[71] B←];	*8-way B dispatch
M[MULTIPLY,FF64[72] ?];
M[Q←,FFBSEL[73,3] B←];
*74 undefined
*75 is TGETSMD, used implicitly
M[FREEZEBC,FF64[76]?];
M[NOFF,FF[77] ?];	*No operation, used only for IM default


M[PCF←,FF256[100] B←];	*PCF←B and start IFU
M[IFUTEST←,FF256[101] B←];
M[IFUTICK,FF256[102] ?];
M[RESCHEDULENOW,FF256[103] ?];
*104 undefined
M[MEMBASE←B,FF256[105] B];	M[MEMBASE←RB,MEMBASE←(B←RB)];
  M[MEMBASE←T,MEMBASE←(B←T)];	M[MEMBASE←MD,MEMBASE←(B←MD)];
  M[MEMBASE←Q,MEMBASE←(B←Q)];
M[RBASE←B,FF256[106] B];	M[RBASE←RB,RBASE←(B←RB)];
  M[RBASE←T,RBASE←(B←T)];	M[RBASE←MD,RBASE←(B←MD)];
  M[RBASE←Q,RBASE←(B←Q)];
M[POINTERS←,FF256[107] B←];

*110-117 undefined

*120-121 undefined Mar sources
M[CFLAGS←,FF256[122] A←];	*Source stable on Mar during preceding cycle
M[BRLO←,FF256[123] A←];
M[BRHI←,FF256[124] A←];
M[LOADTESTSYNDROME,FF256[125] ?];	*Loads from DBuf, ties up Mar
M[LOADMCR,(FF256[126] A←#1,B←#2)];	*Some bits from Mar, some from B
M[PROCSRN←,FF256[127] B←];

M[INSSETOREVENT←,FF256[130] B←];	M[MOS←,FF256[130] B←];
M[EVENTCNTB←,FF256[131] B←];		M[GENOUT←,FF256[131] B←];
M[RESCHEDULE,FF256[132] ?];
M[NORESCHEDULE,FF256[133] ?];

M[IFUMRH←,FF256[134] B←];
M[IFUMLH←,FF256[135] B←];
M[IFURESET,FF256[136] ?];
M[BRKINS←,FF256[137] B←];	*BRKINS←B[0:7] & set BRKPENDING

M[USEDMD,FF256[140] ?];
M[MIDASSTROBE←,FF256[141] B←];
M[TASKINGOFF,FF256[142] ?];
M[TASKINGON,FF256[143] ?];
M[STKP←,FF256[144] B←];

M[RESTORESTKP,FF256[145] ?];
M[CNT←B,FF256[146] B];	M[CNT←RB,CNT←(B←RB)];
  M[CNT←T,CNT←(B←T)];	M[CNT←MD,CNT←(B←MD)]; M[CNT←Q,CNT←(B←Q)];
M[LINK←,FF256[147] B←];

M[Q LSH 1,FF256[150] ?];
M[Q RSH 1, FF256[151] ?];
M[TIOA←,FF256[152] B←];
*153 undefined
M[HOLD&TASKSIM←,FF256[154] B←];
M[WF←,FF256[155] A←];
M[RF←,FF256[156] A←];
M[SHC←,FF256[157] B←];

*External B
M[XBOK,IFA[BSEL,ER[Multiple.B.sources],FF256[#1]]];

*From memory
M[FAULTINFO',XBOK[160] XB];
M[PIPE0,XBOK[161] XB];	M[VAHI,XBOK[161] XB];
M[PIPE1,XBOK[162] XB];	M[VALO,XBOK[162] XB];
M[PIPE2',XBOK[163] XB];
M[PIPE3',XBOK[164] XB];	M[MAP',XBOK[164] XB];
M[PIPE4',XBOK[165] XB];	M[ERRORS',XBOK[165] XB];
M[CONFIG',XBOK[166] XB];
M[PIPE5,XBOK[167] XB];		M[PREF,XBOK[167] XB];

*From IFU
M[PCX',XBOK[170] B];
M[EVENTCNTA',XBOK[171] XB];
M[IFUMRH',XBOK[172] XB];
M[IFUMLH',XBOK[173] XB];
M[EVENTCNTB',XBOK[174] XB];

M[DBUF,XBOK[175] XB];	*From memory

*From Control
M[RWCPREG,XBOK[176] XB];
M[LINK,XBOK[177] XB];
  M[CPREG,XBOK[177] XB]; *Synonym for LINK

%Stuff for small constant functions
%
M[SCFN,IFG[#1,SCONS,FF256[ADD[#2,SCONS]],ER[Illegal.arg.for.#3]] ?];

M[RBASE←SC,SCFN[20,200,RBASE←]];
*220-237 are change-RBase-for-write, unused by Midas
M[TIOA,SCFN[10,240,TIOA]];
M[MEMBASEX←SC,SCFN[4,250,MEMBASEX←]];
M[MEMBX←SC,SCFN[4,254,MEMBX←]];

*260-261 undefined
N[ALUFMRW←]; M[ALUFMRW←B,FF256[262] PD];
  M[ALUFMRW←MD,ALUFMRW←(B←MD)]; M[ALUFMRW←T,ALUFMRW←(B←T)];
  M[ALUFMRW←RB,ALUFMRW←(B←RB)]; M[ALUFMRW←Q,ALUFMRW←(B←Q)];
M[ALUFMEM,FF256[263] PD];
M[CNT,FF256[264] PD];
M[POINTERS,FF256[265] PD];
M[TIOA&STKP,FF256[266] PD];
M[SHC,FF256[267] PD];

M[PD RSH 1,FF256[270] PD];	*PD[0]←0
  M[T RSH 1,FF256[270] PD←T];
  M[RB RSH 1,FF256[270] PD←RB];
  M[A RSH 1,FF256[270] PD←A];
  M[ID RSH 1,FF256[270] PD←(A←ID)];
  M[B RSH 1,FF256[270] PD←B];
  M[MD RSH 1,FF256[270] PD←MD];
  *Q RSH 1 through the ALU has to be written (B←Q) LSH 1

M[PD RCY 1,FF256[271] PD];	*PD[0]←ALU[17]
  M[T RCY 1,FF256[271] PD←T];
  M[RB RCY 1,FF256[271] PD←RB];
  M[A RCY 1,FF256[271] PD←A];
  M[ID RCY 1,FF256[271] PD←(A←ID)];
  M[B RCY 1,FF256[271] PD←B];
  M[MD RCY 1,FF256[271] PD←MD];
  M[Q RCY 1,FF256[271] PD←(B←Q)];

M[PD BRSH 1,FF256[272] PD];	*PD[0]←ALUcarry
  M[T BRSH 1,FF256[272] PD←T];
  M[RB BRSH 1,FF256[272] PD←RB];
  M[A BRSH 1,FF256[272] PD←A];
  M[ID BRSH 1,FF256[272] PD←(A←ID)];
  M[B BRSH 1,FF256[272] PD←B];
  M[MD BRSH 1,FF256[272] PD←MD];
  M[Q BRSH 1,FF256[272] PD←(B←Q)];

M[PD ARSH 1,FF256[273] PD];	*PD[0] unchanged
  M[T ARSH 1,FF256[273] PD←T];
  M[RB ARSH 1,FF256[273] PD←RB];
  M[A ARSH 1,FF256[273] PD←A];
  M[ID ARSH 1,FF256[273] PD←(A←ID)];
  M[B ARSH 1,FF256[273] PD←B];
  M[MD ARSH 1,FF256[273] PD←MD];
  M[Q ARSH 1,FF256[273] PD←(B←Q)];

M[PD LSH 1,FF256[274] PD];	*PD[17]←0
  M[T LSH 1,FF256[274] PD←T];
  M[RB LSH 1,FF256[274] PD←RB];
  M[A LSH 1,FF256[274] PD←A];
  M[ID LSH 1,FF256[274] PD←(A←ID)];
  M[B LSH 1,FF256[274] PD←B];
  M[MD LSH 1,FF256[274] PD←MD];
  *Q LSH 1 through the ALU has to be written as (B←Q) LSH 1

M[PD LCY 1,FF256[275] PD];	*PD[17]←ALU[0]
  M[T LCY 1,FF256[275] PD←T];
  M[RB LCY 1,FF256[275] PD←RB];
  M[A LCY 1,FF256[275] PD←A];
  M[ID LCY 1,FF256[275] PD←(A←ID)];
  M[B LCY 1,FF256[275] PD←B];
  M[MD LCY 1,FF256[275] PD←MD];
  M[Q LCY 1,FF256[275] PD←(B←Q)];

M[DIVIDE,FF256[276] ?];		*Q[15]←ALU carry
M[CDIVIDE,FF256[277] ?];	*Q[15]←ALU carry'

M[MEMBASE←SC,SCFN[40,300,MEMBASE←]];
M[CNT←SC,IFE[SCONS,20,FF256[340] ?,IFE[SCONS,0,ER[Illegal.CNT←],
  SCFN[20,340,CNT←]]]];
M[NOTIFY,FF256[ADD[360,PX[#1]]]];

%Control stuff:
%

%Branch conditions are irrelevant ?
*Use FBC BC if available.
M[BRC,IFA[FBC,JCN[#2],FBC[#1]]]; **Doesn't work**

*REGULAR BC'S
M[~ALU=0,BRC[60,0]];
M[~ALU<0,BRC[61,1]];
M[~CARRY',BRC[62,2]];
M[~CNT=0&-1,BRC[63,3]];
M[~R<0,BRC[64,4]];
M[~R ODD,BRC[65,5]];
M[~IOATTEN',ILLEM[IOATTEN']BRC[66,6]];
M[~RESCHEDULE,ILLIO[RESCHEDULE]BRC[66,6]];
M[~OVERFLOW,FF64[67]];
M[~,];
%

M[RETURN,JCN[107]?];
M[LOCBR,JCN[ADD[200,#1]]?];
M[LONGBR,JCN[AND[#1,17]] FF[RSHIFT[#1,4]]?];
M[GCALL,JCN[ADD[300,RSHIFT[#1,6]]] ?];
M[IFUJUMP,JCN[ADD[47,LSHIFT[#1,3]]] ?];

%IM read/write to/from LINK.
%
M[IMLHR0POK←,RSTK13[3] JCN[177] B←];
M[IMLHR0PBAD←,RSTK13[7] JCN[177] B←];
M[IMLHR0'POK←,RSTK13[1] JCN[177] B←];
M[IMLHR0'PBAD←,RSTK13[5] JCN[177] B←];
M[IMRHBPOK←,RSTK13[2] JCN[177] B←];
M[IMRHBPBAD←,RSTK13[6] JCN[177] B←];
M[IMRHB'POK←,RSTK13[0] JCN[177] B←];
M[IMRHB'PBAD←,RSTK13[4] JCN[177] B←];

M[READIM,JCN[167] RSTK23[#1] ?];


%TPC read/write from LINK, address from B[14:17]
%
M[LDTPC←,JCN[157] B←];
M[RDTPC←,JCN[147] B←];


DEFAULT[LDR,(NOFF, PD←B, ASEL[4] BSEL[1] LC[0] RSTK[0] LOCBR[1])];