====== MIDAS and PDP-10 Assembly ====== [[http://pdp10.nocrew.org]] has useful information on the instruction set. I recommend getting familiarized with //DECsystem-10/DECSYSTEM-20 Processor Reference Manual// first. The ''MIDAS'' is a macro assembler, it does not check whether you provide correct number of arguments to opcode. Notice that almost all numbers in MIDAS are treated as octal. To specify a decimal number such as nineteen, use ''19.'' (appending a dot). You can lookup '':info midas'' for more details about the assembler. ===== PDP-10 Instruction format ===== Unlike some CISC instruction set, every instruction of PDP-10 is of the same 36-bit format (except for I/O instructions that are not available when the program is been supervised by an OS). 000000000 0111 1 1111 112222222222333333 012345678 9012 3 4567 890123456789012345 ________________________________________ | | | | | | | OP | AC |I| X | Y | |_________|____|_|____|__________________| OP = operation code AC = accumulator field I = indirect bit X = index field Y = address field DEV = device code IOP = input-output operation code ===== Addressing ===== Every instruction takes a register argument, and another address argument ''E''. Indirect addressing even applies to immediate variant of instructions. For example, the ''movei'' below would actually set register ''a'' to ''12''. start: movei a,@add ... add: addi b,12 IFETCH: MA <- PC OP <- Bits 0:8 of C(MA); AC <- Bits 9:12 of C(MA); EACOMP: I <- Bit 13 of C(MA); X <- Bits 14:17 of C(MA); Y <- Bits 18:35 of C(MA); E <- Y; IF NOT(X=0) then E <- E+C(X); IF I=0 then go to done; MA <- E; GO TO EACOMP; DONE: ===== Print first 500 primes ===== The ''$'' actually stands for ''^@'' (Control At). ; -*- MIDAS -*- TITLE PRIME L==500. ; Decimal 500 J=1 N=2 K=3 A=4 R=5 PRIME: BLOCK L BUF: BLOCK 30 PDL: BLOCK 10 START: MOVE J,[-L-1,,PRIME-1] ; setup J MOVEI N,2 PUSH J,N MOVEI N,3 ; N <- 3 P2: PUSH J,N HLRO A,J AOJE A,PRIN ; found P4: ADDI N,2 MOVEI K,1 P6: MOVE A,N IDIV A,PRIME(K) JUMPE R,P4 ; Goto P4 if remainder is zero CAMG A,PRIME(K) ; if Q <= P[K] JRST P2 ; Goto P2 ADDI K,1 JRST P6 PRIN: .OPEN 1,[.UAO,,'TTY] .LOSE %LSSYS MOVE J,[-10,,PDL-1] MOVE A,[440700,,TITL] PUSHJ J,OUT MOVEI K,0 ; Setup line CONV: MOVE N,[440700,,BUF] NUM: MOVE A,PRIME(K) IDIVI A,1000. PUSHJ J,DPC IDIVI A,100. PUSHJ J,DPC IDIVI A,10. PUSHJ J,DPC CAIL K,450. JRST PUTL MOVEI A,40 IDPB A,N ADDI K,50. JRST NUM PUTL: MOVE A,[440700,,BUF] PUSHJ J,OUT ADDI K,1 CAIL K,L .LOGOUT 1, SUBI K,450. JRST CONV DPC: ADDI A,60 IDPB A,N MOVE A,R POPJ J, OUT: ILDB N,A JUMPE N,EXIT .IOT 1,N JRST OUT EXIT: .IOT 1,[^M] .IOT 1,[^J] POPJ J, TITL: ASCIZ $FIRST FIVE HUNDRED PRIMES$ END START