Fig. 18.2.2 shows a simple program in the style of the CSC-1 computer that does the CPU's end of the transfer. This program is actually too simple, since it has no provision for stopping and the STD instruction is extremely unrealistic since it stores the bytes into the same variable, overwriting the old values. A real program would probably put the data bytes into an array. LDI 001b ;form the code for the START command OUT 2 ;send START command to the tape reader LDI 01b ;put CPU's status into its status port OUT 0 ;which the TR reads as "Go read for me now!" WHILE0: NOP ;get data bytes until done (see below...) ;a spin loop to wait until the TR has delivered next byte WHILE1: IN 1 ;read the tape reader's status SUB DATAREADY ;compare to 10b, which is data is ready to pickup JZ ENDWHILE1 ;if equal, then done JMP WHILE1 ;else go back to top of loop ENDWHILE1:NOP IN 3 ;read data byte on port 3 from the tape reader STD X ;store into main memory somewhere (X) LDI 10b ;get ready to write 1 into data accepted OUT 0 ;write to status port so tape reader sees it ;the tape reader is now spinning, waiting for CPU LDI 100 ;pause the loop to allow the tape reader ;to catch up WHILE2: JZ ENDWHILE2 ;busy loop to waste 100 time units here because TR is slower than CPU SUB ONE ;It counts down from 100 to 0 by subtracing 1 JMP WHILE2 ;...sometime inside this loop, the tape reader sets the status ; register back to "00" so the CPU will see it ENDWHILE2:NOP JMP WHILE0 ;do it all over again to read next byte ENDWHILE0:HLT DATAREADY:NUM 10b ;"10" is the code for the Tape Reader saying data is ready to get ONE: NUM 1 Fig. 18.2.2: Simple polling program to read bytes from a device |