$ > AsmPDP PDP11 Assembler v1.09 3 v1.04 31-Aug-2005: Searches for DOS filenames 4 v1.05 30-Apr-2006: On Windows uses console i/o (4 v1.06 19-May-2006: '$' recognised in constants 21 v1.07 25-Feb-2007: Implmented ADR label,dst <[ v1.08 02-Mar-2007: Errors trapped in evaluation and assignment, SXT, SWAB implemented F: v1.09 12-Aug-2008: SOB, M[F|T][PD|PI|PS] implemented P( --- to do: multiple BBS directives Z: d#A$=OS_GetEnv:Init:ver$="1.09" n:fmax%=10: word% 7,cache% 259,file$(fmax%),ptr%(fmax%) x :CloseAll:exit(0): Cin%=0:out%=0:in$="":out$="":lst$="":error$="":quit$="":debug%= Q A$<>"":A%=" "+A$," -d"):A%:debug%=:A$=A$,A%-1)+A$,A$+" "," ",A%+1)+1) 8 A$<>"":A%=A$+" "," "):in$ =A$,A%-1):A$=A$,A%+1) 8 A$<>"":A%=A$+" "," "):out$=A$,A%-1):A$=A$,A%+1) 8 A$<>"":A%=A$+" "," "):lst$=A$,A%-1):A$=A$,A%+1) N in$="-?":"Usage: AsmPDP [ [ []]]":exit(0):  "PDP11 Assembler v";ver$ 4 in$="":"Input file: "in$:"Output file: "out$ )out$=fname(out$): in$="":exit(0): Bin%=openin(in$): in%=0: "File '"in$"' not found":exit(0): Q out$<>"":out%=(out$): out%=0: "Can't open '"out$"'":CloseAll:exit(0):  lst$<>"":"Spool "+lst$ X : " ";error$;part$,error$<>"");" ",error$<>"");"in "in$:CloseAll:exit(0): :  pass%=1 2 3#in%=0:Line$="":P%=0:O%=0:L%=0:errs%=0:fnum%=0 " , 61AssemLine: pass%=2:Pass2 debug%:Text$ @P%=P%+num%:O%=O%+num% J #in% TVfnum%=fnum%-1: fnum%>-1:in$=file$(fnum%):#in%:in%=openin(in$):#in%=ptr%(fnum%) ^ fnum%<0 h pass% r, "Errors: ";errs%: errs%>127:errs%=127 |CloseAll: exit(errs%) " out$<>"":SetType(out$,&1C5) " lst$<>"":SetType(lst$,&FFF) exit(errs%)  : #Pass2:num%<256:cache%?num%=0 * op%<>-1:cache%?1=op%256:?cache%=op%  o0(P%,6); C num%: A%=0 num%-1 2: (A%7)*3.5+7);o0(cache%!A%,6);: : 35);Text$;(24- Text$,24))(Text$<>""),32);Line$ 7 error$<>"": "****** ";error$;part$:errs%=errs%+1 C num%: out%: L%=0 P%8: "SetType "+A$+" "+~A%  : ݤopenin(A$): in0% in0%=(A$): in0%:=in0% I os%<8:A%=A$,"."): A%:in0%=(A$,A%-1)+"/"+A$,A%+1)): in0%:=in0%  os%<>32 A$,"."):=0 in0%=(A$+"."): in0%:=in0% =(A$+".mac")  : AssemLine  /Item$="":Word$="":num%=0:error$="":part$="" *Line$=#in%: PRINTLine$ 4 IF Line$="":Line$=GET$#in% >8 A%=INSTR(Line$+":",":",2):REM falls over on ASC":" H6 B%=INSTR(Line$+";",";"):REM falls over on ASC";" R IF B%>1:IF B%>"Item$"<<" f p: z Assem :A%=Line$+";",";"):Text$=Line$,A%-1):Line$=Line$,A%) < A%=Text$,9): A%:Text$=Text$,A%-1)+" "+Text$,A%+1) 6 A%=0: IF LEFT$(Text$,1)=":":Text$=MID$(Text$,2) ,Item$=s(Text$): Item$="":: Null line ;A%=Item$,":"): A%:Item$="."+Item$,A%-1)+Item$,A%+1) L Item$,1)=".":SetLabel: Item$="":: Needs to allow label:instr $ Item$,1)=";":: Long comment % Item$,1)="\":: Short comment EA%=Item$+" "," "):Word$=uc(Item$,A%-1)):Item$=s(Item$,A%+1))  num%=2 9A%="CLRCOMINCDECNEGADCSBCTSTRORROLASRASL",Word$,3)) X A%:(A%-1)3=0:op%=5*8*8*8+((A%-1)3)*8*8-(Word$,4,1)="B")*8*8*8*8*8+dd(Item$): $A%="MOVCMPBITBICBIS",Word$,3)) T A%:(A%-1)3=0:op%=((A%+2)3)*8*8*8*8-(Word$,4,1)="B")*8*8*8*8*8+sd(Item$): )A%="BPLBMIBHIBLSBVCBVSBCCBCS",Word$) B A%:(A%-1)3=0:op%=((A%-1)3)*256+1*8*8*8*8*8+disp(Item$): $/A%=0+0+0+"BR BNEBEQBGEBLTBGTBLE",Word$) .6 A%:(A%-1)3=0:op%=((A%-1)3)*256+disp(Item$): 8, Word$="ADD":op%=6*8*8*8*8+sd(Item$): B- Word$="SUB":op%=14*8*8*8*8+sd(Item$): L$A%="MUL DIV ASH ASHCXOR",Word$) V@ A%:(A%-1)4=0:op%=7*8*8*8*8+((A%-1)4)*8*8*8+rd(Item$): `* Word$="JSR":op%=4*8*8*8+rd(Item$): j( Word$="JMP":op%=1*8*8+dd(Item$): t) Word$="SWAB":op%=3*8*8+dd(Item$): ~0 Word$="SXT":op%=6*8*8*8+7*8*8+dd(Item$): N Word$="RTS":A%=r(Item$):op%=2*8*8+A%:error$="Missing register",A%<0): . Word$="EMT":op%=68*8*8*8+value(Item$): 5 Word$="TRAP":op%=68*8*8*8+4*8*8+value(Item$): 4 Word$="MARK":op%=6*8*8*8+4*8*8+value(Item$): / Word$="SPL":op%=2*8*8+3*8+value(Item$): %A%="MTPSMFPDMTPDMFPS",Word$,4)) J A%:(A%-1)4=0:op%=1*8*8*8*8*8+6*8*8*8+((A%-1)4+4)*8*8+dd(Item$): A%="MFPIMTPI",Word$,4)) > A%:(A%-1)4=0:op%=6*8*8*8+((A%-1)4+5)*8*8+dd(Item$): Y Word$="SOB":A%=Item$,","):op%=63*8*8*8+r(Item$,A%-1))*8*8+disp6(Item$,A%+1)): 7 Word$,2)="CL":op%=160+"CV N N",Word$,3,1)): 7 Word$,2)="SE":op%=176+"CV N N",Word$,3,1)):  Word$="CCC":op%=175:   Word$="SCC":op%=191:  Word$="NOP":op%=160:  Word$="RTT" :op%=6: ( Word$="RESET":op%=5: 2 Word$="IOT" :op%=4: < Word$="BPT" :op%=3: F Word$="RTI" :op%=2: P Word$="WAIT" :op%=1: Z Word$="HALT" :op%=0: d Word$="ADR" :ADR: nnum%=0:op%=-1 x$ Word$="ORG":P%=value(Item$):  Word$="BSS":L%=P%:  Word$,3)="EQU":EQU: ' Word$="ALIGN":op%=0:num%=(P%1):  Word$,1)="#":Module: error$="Unknown opcode": : BSS:L%=P%:  bss%=bss%+1:IFP%>L%:L%=P%  oldP%=P%:IFoldL%:P%=oldL%  ENDPROC :  ADR *Line0$=Line$:Text0$=Text$:Item0$=Item$ >A%=Item0$,","):Line$="MOV PC"+Item0$,A%):Assem:op0%=op% IA%=Item0$,","):Line$="ADD #"+Item0$,A%-1)+"-$-2"+Item0$,A%):Assem Hnum%=num%+2:cache%!4=cache%!2:cache%?3=op%256:cache%?2=op%:op%=op0% "Line$=Line0$:Text$=Text0$ , 6: @-EQU: Word$="EQUM":num%=value(Item$): Jsize%="SBW D",Word$,1))-1 Td size%>1: cache%!num%=value(Item$):num%=num%+size%:Item$=Item$,Item$+",",",")): Item$="": ^ h Item$,1)="""":A%=Item$,"""",2):$(cache%+num%)=Item$,2,A%-2):Item$=Item$,A%+1):num%=num%+A%-2 cache%?num%=value(Item$):num%=num%+1 r'Item$=s(Item$,Item$+",",",")+1)) |A Item$="" num%>256:num%>256:error$="equate item too long"  :  Module  Word$<>"#INCLUDE": Lin0%=openin(q(Item$)): in0%=0:error$="#include "+Item$+" not found": 4file$(fnum%)=in$:ptr%(fnum%)=#in%:fnum%=fnum%+1 -#in%:in%=in0%:in0%=0:in$=fname(Item$): : ݤmr(A$): A%:A$=s(A$)  m%,r%,v% / A$=2:r%=r(A$): r%>-1:=r%: Rn, SP, PC + A$=4: A$,1)="(": A$,1)=")":m%=1 4 A$,1)="@":m%=1:A$=A$,2) : 3/5/7 G A$,1)="#":v%=value(A$,2))&FFFF:num%=num%+2:=(m%+2)*8+7+256*v% 2 A$,2)="-(":m%=m%+4:A$=A$,2) : 4/5 . A$,1)="+":m%=m%+2:A$=A$, A$-1): 2/3 &;A%=A$,"("): A%: A$,1)<>")":error$="Missing ')'":=-1 0/ A%:r%=r(A$,A%+1,2)):A$=A$,A%-1) r%=7 :@ A$<>"":v%=value(A$)&FFFF:m%=m%+6:num%=num%+2 : 6/7 DP r%=7: m%>5:v%=(v%-P%-num%)&FFFF: If 6,6 or 7,7 does this have to sub 4? N=m%*8+r%+256*v% X: b Addressing modes: l. 0 - Rn eg R4 r6 sp pc PC sP Pc v> 1 - (Rn) eg (R4) technically, equiv. of @Rn  2 - (Rn)+ eg (SP)+  3 - @(Rn)+ eg @(R4)+  4 - -(Rn) eg -(SP)  5 - @-(Rn) eg @-(R2) , 6 - offset(Rn) eg &400(R1) label(PC) " 7 - @address(Rn) eg @&40(R5) :  R=7 also recognise: G 2 - #value absolute location = (PC)+:EQUW value H 3 - @#value contents of absolute location = @(PC)+:EQUW value F 6 - value location relative to PC same as value(PC) G 7 - @value contents of label_rel_to_PC same as @value(PC) : ݤr(A$): A$<>2:=-1  ( A$="PC"A$="Pc"A$="pC"A$="pc":=7 ( A$="SP"A$="Sp"A$="sP"A$="sp":=6  # A$,1)<>"R" A$,1)<>"r":=-1 *! A$,1)<"0" A$,1)>"7":=-1 4 = A$,1) >: Hݤsd(A$): src,dst R A%,src%,dst%,n% \,A%=A$,","): A%=0:error$="Missing ,":=0 f>part$=" in source":n%=num%:src%=mr(A$,A%-1)): src%<0:=0 p. n%<>num%:cache%!n%=src%256:src%=src%63 z' error$="":part$=" in destination" +n%=num%:dst%=mr(A$,A%+1)): dst%<0:=0 . n%<>num%:cache%!n%=dst%256:dst%=dst%63 =64*src%+dst% : ݤrd(A$): Rn,dst  A%,r%,dst%,n% ,A%=A$,","): A%=0:error$="Missing ,":=0 num%:cache%!n%=dst%256:dst%=dst%63 =64*r%+dst% : ݤdd(A$): dst  A%,dst%,n% Cn%=num%:dst%=mr(A$): n%<>num%:cache%!n%=dst%256:dst%=dst%63  =dst% : $#ݤdisp(A$): 8-bit displacement .]A%=((value(A$)-P%-2)/2): A%<&FFFFFF80 A%>&7F: error$="":error$="branch out of range" 8 =A%&FF B: L$ݤdisp6(A$): 6-bit displacement V]A%=((value(A$)-P%-2)/2): A%<&FFFFFFE0 A%>&1F: error$="":error$="branch out of range" ` =A%&3F j: tݤvalue(V$): p% ~! : :error$=$:P%=p%:=P% ? Look at value, eg "42", "&2A", "label", "&o52", "%101010" + Need to convert &o to & within string $A%=V$,"+$"): A%=0:A%=V$,"-$") 3 A%:V$=V$,A%)+"P%"+V$,A%+2): Change $ to P% &A%=V$,"+P%"): A%=0:A%=V$,"-P%") 3 A%:V$=V$,A%)+"p"+V$,A%+2): Change P% to p% ? os%<>32:p%=P%:P%=word%:[OPT 0:EQUD V$:EQUD V$:]:P%=p% : os%=32:p%=P%:P%=word%:[OPT 0:DD V$:DD V$:]:P%=p% "EQU ":Var_Assign(L$, P%):error$="": P:Var_Assign(L$, value(Item$,5))):error$="":Item$="" Z d: n# Octal number output functions x# ============================= ݤo0(A%,N%):A%=A%&FFFF:="00000"+(48+((A%32768)7))+(48+((A%4096)7))+(48+((A%512)7))+(48+((A%64)7))+(48+((A%8)7))+(48+(A%7)),N%) :  String functions  ================ %ݤsL(A$): A$,1)=" ":A$=A$,2)  A$,1)<>" ":=A$ 8ݤq(A$):A$=s(A$): A$,1)="""":A$=s(A$,2, A$-2)) =A$ :  > BLib.Variable # Variable assignment functions # ============================= (: 2 Var_Assign(Var$,Val$) <8 Sets the variable in 'Var$' to the value in 'Val$' F8 -------------------------------------------------- P: ZVar_Assign(Var$,Val$) d7 Var$,1)="$":A%=("FNVar_S("+Var$+","+Val$+")"): n7 Var$,1)="%":A%=("FNVar_I("+Var$+","+Val$+")"): x(A%=("FNVar_R("+Var$+","+Val$+")"):  : ݤVar_S( a$,b$):a$=b$:=0 ݤVar_I( a%,b%):a%=b%:=0 ݤVar_R( a, b ):a =b :=0 : " > BLib.String 1.00 09Aug1998 : # String Manipulation Functions (# ============================= 2: <7 FNs() - strip spaces from start and end of string F7 ------------------------------------------------- P/ݤs(A$):A$,1)=" ":A$=A$,2):A$,1)<>" " Z+A$,1)=" ":A$=A$,A$-1):A$,1)<>" " d=A$ n: x+ FNuc() - convert string to upper case + ------------------------------------- ݤuc(A$): B$:A$="":="" 5B$=B$+(A$((A$<"@")&DF)):A$=A$,2):A$="":=B$ : + FNlc() - convert string to lower case + ------------------------------------- ݤlc(A$): B$:A$="":="" 5B$=B$+(A$((A$<"_")&20)):A$=A$,2):A$="":=B$ : # > BLib.ProgEnv 1.04 09Jan2007 : # Program Environment Functions (# ============================= 2: &FFFF:ș"GetModuleFileName",0,X%,255:A$=$$X%:run$=A$:=@cmd$ xos%=32:A$=$&100 {A$=0:>&7FFF:run$=$&8100:ș"OS_GetEnv"A$,,A%:ș"OS_WriteEnv","",A%:A$=A$,1+A$+" "," ",1+A$," "))):A$=0:A$=run$ 2A$=0:?(P-3):A$=$&600 A$=0:A$=$(-&300) 7A%=A$+" "," "):run$=A$,A%-1):run$<>"":=A$,A%+1) bY%=X%256:A%=9:?X%=0:X%!1=X%+16:X%!16=0:&FFD1:A%=X%+16:!A%?A%+A%?2<>8:A%?(A%+1)=13:=$(A%+1) ="" : . Run a program, passing it a command line = If program is *Command, called with OSCLI, else CHAINed = ------------------------------------------------------- &os(A$):A$=42:A$ A$<>"":A$  : ( Exit program, setting return value ( ---------------------------------- @exit(A%):"FX1,"+A%:quit$=quit$:A$=quit$:quit$="":os(A$) os%=32:Ș A% "os%<6: *Quit , 6: