% Section 2.1, Ex.9 % Author Andrey Dubinchak kachnibud@gmail.com % Beta-test version % % Each term has the two-octabyte form % % +----+----+----+----+----+----+----+----+ % |TAG |SUIT|RANK|PILE| TITLE | % +----+----+----+----+----+----+----+----+ % | NEXT | % +----+----+----+----+----+----+----+----+ % % TOP IS $0 NTMP IS $1 TTMP IS $2 X IS $3 t IS $255 Temporary storage TAG IS 0 NAME IS 4 Defenition of fields NEXT IS 8 LOC Data_Segment+#100 GREG @ Card1 OCTA #01010A2031302043 OCTA #0000000000000000 LOC Data_Segment+#380 GREG @ Card2 OCTA #0004032020332053 OCTA #2000000000000100 LOC Data_Segment+#240 GREG @ Card3 OCTA #0002022020322044 OCTA #2000000000000380 GREG @ Empty BYTE "PILE EMPTY",0 Message printed in case pile is empty PAREN1 BYTE "(" Name1 BYTE " )" BYTE #a,0 BLANKS BYTE " " Name2 BYTE " " BYTE #a,0 LOC #100 Main LDA TOP,Card3 SET X,TOP LDA t,Empty BZ X,2F Is the pile empty? 1H LDB TTMP,X,TAG TTMP<-TAG(X). LDT NTMP,X,NAME NTMP<-NAME(X). BZ TTMP,Yes Is TAG = 0 (is card face up)? STT NTMP,Name1 No: Copy parentheses. LDA t,PAREN1 JMP No Yes STT NTMP,Name2 Yes: Copy blanks. LDA t,BLANKS No LDO X,X,NEXT Set X<-NEXT(X). 2H TRAP 0,Fputs,StdOut Print the line PBNZ X,1B If X<>0, repeat the print loop. TRAP 0,Halt,0