MAIN START RPUSH ; Init Variables LAD GR1,I001 XOR GR2,GR2 LAD GR3,777 CALL C010 ; Print "WORDS? (comma separated)" OUT LB001,LL001 ; Input s IN SB007,SL007 XOR GR0,GR0 ST GR0,EOF LD GR0,SL007 JPL J001 JZE J001 ST GR0,EOF XOR GR0,GR0 ST GR0,SL007 J001 NOP ; ub = (Len(s) - 1) LD GR7,SL007 LAD GR7,-1,GR7 ST GR7,I006 ; For i = 0 To ub Step 1 LD GR7,I006 ST GR7,T001 XOR GR7,GR7 ST GR7,I001 J002 NOP LD GR1,I001 CPA GR1,T001 JPL J004 ; If (s(i) = ","c) Then LD GR7,I001 LD GR1,GR7 LD GR2,SL007 LAD GR3,SB007 CALL C011 LD GR7,GR0 LD GR6,=',' SUBA GR7,GR6 JZE J010 LAD GR7,#FFFF J010 XOR GR7,=#FFFF AND GR7,GR7 JZE J005 ; cnt += 1 LAD GR7,1 LAD GR6,I005 ADDA GR7,0,GR6 ST GR7,0,GR6 ; End If J005 NOP ; Next i J003 NOP LAD GR1,I001 LD GR2,0,GR1 LAD GR2,1,GR2 ST GR2,0,GR1 JUMP J002 J004 NOP ; For i = 1 To cnt Step 1 LD GR7,I005 ST GR7,T001 LAD GR7,1 ST GR7,I001 J011 NOP LD GR1,I001 CPA GR1,T001 JPL J013 ; p0 = 0 XOR GR7,GR7 ST GR7,I002 ; For p1 = 0 To ub Step 1 LD GR7,I006 ST GR7,T002 XOR GR7,GR7 ST GR7,I003 J014 NOP LD GR1,I003 CPA GR1,T002 JPL J016 ; If (s(p1) = ","c) Then LD GR7,I003 LD GR1,GR7 LD GR2,SL007 LAD GR3,SB007 CALL C011 LD GR7,GR0 LD GR6,=',' SUBA GR7,GR6 JZE J018 LAD GR7,#FFFF J018 XOR GR7,=#FFFF AND GR7,GR7 JZE J017 ; Exit For JUMP J016 ; End If J017 NOP ; Next p1 J015 NOP LAD GR1,I003 LD GR2,0,GR1 LAD GR2,1,GR2 ST GR2,0,GR1 JUMP J014 J016 NOP ; For p2 = (p1 + 1) To ub Step 1 LD GR7,I006 ST GR7,T002 LD GR7,I003 LAD GR7,1,GR7 ST GR7,I004 J019 NOP LD GR1,I004 CPA GR1,T002 JPL J021 ; If (s(p2) = ","c) Then LD GR7,I004 LD GR1,GR7 LD GR2,SL007 LAD GR3,SB007 CALL C011 LD GR7,GR0 LD GR6,=',' SUBA GR7,GR6 JZE J023 LAD GR7,#FFFF J023 XOR GR7,=#FFFF AND GR7,GR7 JZE J022 ; w1 = Mid(s, p0, (p1 - p0)) LD GR7,I002 LD GR6,I003 LD GR5,I002 SUBA GR6,GR5 LD GR1,GR7 LAD GR5,TB001 LAD GR3,SB007 LD GR4,SL007 LD GR2,GR4 CALL C006 ST GR0,TL001 LAD GR1,SB008 LAD GR2,SL008 LAD GR3,TB001 LD GR4,TL001 CALL C007 ; w2 = Mid(s, (p1 + 1), (p2 - (p1 + 1))) LD GR7,I003 LAD GR7,1,GR7 LD GR6,I004 LD GR5,I003 LAD GR5,1,GR5 SUBA GR6,GR5 LD GR1,GR7 LAD GR5,TB001 LAD GR3,SB007 LD GR4,SL007 LD GR2,GR4 CALL C006 ST GR0,TL001 LAD GR1,SB009 LAD GR2,SL009 LAD GR3,TB001 LD GR4,TL001 CALL C007 ; If (w1 > w2) Then LAD GR3,SB008 LD GR4,SL008 LAD GR1,SB009 LD GR2,SL009 CALL C004 SRA GR0,15 LD GR7,GR0 AND GR7,GR7 JZE J032 ; Mid( s, p0 ) = ((w2 & ",") & w1) LAD GR1,TB001 LAD GR2,TL001 LAD GR3,SB009 LD GR4,SL009 CALL C007 LAD GR1,TB001 LAD GR2,TL001 LAD GR3,=',' LAD GR4,1 CALL C005 LAD GR1,TB001 LAD GR2,TL001 LAD GR3,SB008 LD GR4,SL008 CALL C005 LD GR7,I002 LD GR1,GR7 LAD GR5,SB007 LD GR2,SL007 LAD GR3,TB001 LD GR4,TL001 LD GR6,GR2 CALL C008 ; p0 += (Len(w2) + 1) LD GR7,SL009 LAD GR7,1,GR7 LAD GR6,I002 ADDA GR7,0,GR6 ST GR7,0,GR6 JUMP J031 ; Else J032 NOP ; p0 = (p1 + 1) LD GR7,I003 LAD GR7,1,GR7 ST GR7,I002 ; End If J031 NOP ; p1 = p2 LD GR7,I004 ST GR7,I003 ; End If J022 NOP ; Next p2 J020 NOP LAD GR1,I004 LD GR2,0,GR1 LAD GR2,1,GR2 ST GR2,0,GR1 JUMP J019 J021 NOP ; w1 = Mid(s, p0, (p1 - p0)) LD GR7,I002 LD GR6,I003 LD GR5,I002 SUBA GR6,GR5 LD GR1,GR7 LAD GR5,TB001 LAD GR3,SB007 LD GR4,SL007 LD GR2,GR4 CALL C006 ST GR0,TL001 LAD GR1,SB008 LAD GR2,SL008 LAD GR3,TB001 LD GR4,TL001 CALL C007 ; w2 = Mid(s, (p1 + 1), (p2 - (p1 + 1))) LD GR7,I003 LAD GR7,1,GR7 LD GR6,I004 LD GR5,I003 LAD GR5,1,GR5 SUBA GR6,GR5 LD GR1,GR7 LAD GR5,TB001 LAD GR3,SB007 LD GR4,SL007 LD GR2,GR4 CALL C006 ST GR0,TL001 LAD GR1,SB009 LAD GR2,SL009 LAD GR3,TB001 LD GR4,TL001 CALL C007 ; If (w1 > w2) Then LAD GR3,SB008 LD GR4,SL008 LAD GR1,SB009 LD GR2,SL009 CALL C004 SRA GR0,15 LD GR7,GR0 AND GR7,GR7 JZE J045 ; Mid( s, p0 ) = ((w2 & ",") & w1) LAD GR1,TB001 LAD GR2,TL001 LAD GR3,SB009 LD GR4,SL009 CALL C007 LAD GR1,TB001 LAD GR2,TL001 LAD GR3,=',' LAD GR4,1 CALL C005 LAD GR1,TB001 LAD GR2,TL001 LAD GR3,SB008 LD GR4,SL008 CALL C005 LD GR7,I002 LD GR1,GR7 LAD GR5,SB007 LD GR2,SL007 LAD GR3,TB001 LD GR4,TL001 LD GR6,GR2 CALL C008 ; End If J045 NOP ; Next i J012 NOP LAD GR1,I001 LD GR2,0,GR1 LAD GR2,1,GR2 ST GR2,0,GR1 JUMP J011 J013 NOP ; Print s OUT SB007,SL007 EXIT NOP RPOP RET ; Dim i As Integer I001 DS 1 ; Dim p0 As Integer I002 DS 1 ; Dim p1 As Integer I003 DS 1 ; Dim p2 As Integer I004 DS 1 ; Dim cnt As Integer I005 DS 1 ; Dim ub As Integer I006 DS 1 ; Dim s As String SL007 DS 1 SB007 DS 256 ; Dim w1 As String SL008 DS 1 SB008 DS 256 ; Dim w2 As String SL009 DS 1 SB009 DS 256 EOF DS 1 T001 DS 1 T002 DS 1 TL001 DS 1 TB001 DS 256 LL001 DC 24 LB001 DC 'WORDS? (comma separated)' ; UtilCompareStr C004 PUSH 0,GR1 PUSH 0,GR2 PUSH 0,GR3 PUSH 0,GR4 PUSH 0,GR5 XOR GR0,GR0 J033 AND GR2,GR2 JPL J034 CPL GR2,GR4 JNZ J035 JUMP J037 J034 AND GR4,GR4 JZE J036 LD GR5,0,GR1 CPL GR5,0,GR3 JMI J035 JPL J036 LAD GR1,1,GR1 LAD GR2,-1,GR2 LAD GR3,1,GR3 LAD GR4,-1,GR4 JUMP J033 J035 LAD GR0,-1 J036 OR GR0,=1 J037 POP GR5 POP GR4 POP GR3 POP GR2 POP GR1 RET ; UtilConcatStr C005 PUSH 0,GR1 PUSH 0,GR2 PUSH 0,GR3 PUSH 0,GR4 LD GR0,0,GR2 LD GR2,GR1 ADDL GR1,GR0 LAD GR2,256,GR2 ADDL GR4,GR3 J043 CPL GR1,GR2 JZE J044 CPL GR3,GR4 JZE J044 LD GR0,0,GR3 ST GR0,0,GR1 LAD GR1,1,GR1 LAD GR3,1,GR3 JUMP J043 J044 LD GR0,GR1 POP GR4 POP GR3 POP GR2 POP GR1 SUBL GR0,GR1 ST GR0,0,GR2 RET ; UtilCopyFromOffsetStr C006 PUSH 0,GR1 PUSH 0,GR2 PUSH 0,GR3 PUSH 0,GR4 PUSH 0,GR5 PUSH 0,GR6 CALL C013 LD GR1,GR6 LD GR6,GR0 CPL GR1,GR2 JMI J024 LD GR1,GR2 J024 ADDL GR1,GR6 LD GR0,GR1 CPL GR0,GR2 JMI J025 LD GR0,GR2 J025 SUBL GR0,GR6 CPL GR0,GR4 JMI J026 LD GR0,GR4 J026 ADDL GR3,GR6 LD GR6,GR5 ADDL GR6,GR0 J027 CPL GR5,GR6 JZE J028 LD GR1,0,GR3 ST GR1,0,GR5 LAD GR3,1,GR3 LAD GR5,1,GR5 JUMP J027 J028 POP GR6 POP GR5 POP GR4 POP GR3 POP GR2 POP GR1 RET ; UtilCopyStr C007 PUSH 0,GR1 PUSH 0,GR2 PUSH 0,GR3 PUSH 0,GR4 ST GR4,0,GR2 AND GR4,GR4 JZE J030 J029 LD GR2,0,GR3 ST GR2,0,GR1 LAD GR3,1,GR3 LAD GR1,1,GR1 SUBL GR4,=1 JPL J029 J030 POP GR4 POP GR3 POP GR2 POP GR1 RET ; UtilCopyToOffsetStr C008 PUSH 0,GR1 PUSH 0,GR2 PUSH 0,GR3 PUSH 0,GR4 PUSH 0,GR5 PUSH 0,GR6 CALL C013 LD GR1,GR6 LD GR6,GR0 CPL GR1,GR2 JMI J038 LD GR1,GR2 J038 ADDL GR1,GR6 LD GR0,GR1 CPL GR0,GR2 JMI J039 LD GR0,GR2 J039 SUBL GR0,GR6 CPL GR0,GR4 JMI J040 LD GR0,GR4 J040 ADDL GR5,GR6 LD GR6,GR5 ADDL GR5,GR0 ADDL GR3,GR0 J041 CPL GR5,GR6 JZE J042 LAD GR3,-1,GR3 LAD GR5,-1,GR5 LD GR1,0,GR3 ST GR1,0,GR5 JUMP J041 J042 POP GR6 POP GR5 POP GR4 POP GR3 POP GR2 POP GR1 RET ; UtilFill C010 PUSH 0,GR1 PUSH 0,GR2 PUSH 0,GR3 ADDL GR3,GR1 J046 CPL GR1,GR3 JZE J047 ST GR2,0,GR1 LAD GR1,1,GR1 JUMP J046 J047 POP GR3 POP GR2 POP GR1 RET ; UtilLoadElement C011 AND GR2,GR2 JNZ J006 XOR GR0,GR0 RET J006 CALL C013 PUSH 0,GR3 ADDL GR3,GR0 LD GR0,0,GR3 POP GR3 RET ; UtilSafeIndex C013 AND GR2,GR2 JNZ J007 XOR GR0,GR0 RET J007 LD GR0,GR1 JPL J008 XOR GR0,GR0 RET J008 CPL GR0,GR2 JMI J009 LAD GR0,-1 ADDL GR0,GR2 J009 RET END