CR = 015
        MOV #LOC, R0

RWAIT:  TSTB KBSTATUS
        BPL RWAIT
        MOVB TTYIN, @R0

WWAIT:  TSTB PRSTATUS
        BPL WWAIT
        MOVB @R0, TTYOUT

        CMPB (R0)+, #CR
        BNE RWAIT
        HALT

The above uses three PDP-11 facilities. First of all, byte instructions for the i/o-related MOVs and TSTs, as noted in the question. Secondly, BPL rather than BGE, because BPL on the PDP-11 just tests N=0 rather than the more complex test which BGE does (on both PDP-11 and VELMA). Thirdly, I'm using an "equate" right at the beginning -- this gives the symbol "CR" the value 15, similar to a label, but where you specify the value right there as opposed to the assembler's taking the value from the current location. Most assemblers have "equates".

Note that since the most significant bit of the status bytes indicates readiness, after a TSTB (using the byte version, because you don't want to consult an entire word, just one byte), the N bit indicates whether the system is ready for the next byte to be processed. For KBSTATUS, the most significant bit is 1 if a character has been typed, and for PRSTATUS, the most significant bit is 1 if the previous character has finished being output -- depending on how you look at it, they're opposite, but it means that the same BPL loop does a busy wait for either register, which is presumably why they did it that way.


[I/O problems] [CSC 258 additional problems] [main course page]