'Buffer swapping I/O in MIX
Page 217 of TAOCP provides the following example of buffer swapping on input:
01 WORDIN STJ 1F Store the exit location.
02 INC6 1 Advance to the next word.
03 2H LDA 0,6 Is it the end of the
04 CMPA =SENTINEL= buffer?
05 1H JNE * If not, exit.
06 IN -100,6(U) Refill this buffer.
07 LD6 1,6 Switch to the other
08 JMP 2B buffer and return.
09 INBUF1 ORIG *+100 First buffer
10 CON SENTINEL Sentinel at end of buffer
11 CON *+1 Address of other buffer
12 INBUF2 ORIG *+100 Second buffer
13 CON SENTINEL Sentinel at end of buffer
14 CON INBUF1 Address of other buffer
The input device is magnetic tape, which has a block size of 100 words.
We have two buffers, INBUF1 and INBUF2. Each buffer is 102 words long: the first 100 words hold the input, the 101st word is a sentinel value marking the end of the buffer and the 102nd word is the address of the other buffer.
When the main program is ready to process the next word of input, it calls WORDIN. WORDIN retrieves the word from the current buffer, loads it in rA (line 3) and transfers control back to main. Once it reaches the end of the current buffer, it calls IN to refill the current buffer and switches to the other buffer (line 6-7).
This way the main program can continue processing input from one buffer while input is being read into the other buffer.
Question
Point 3) on page 218 says:
- No JBUS instruction was necessary, since the next input was initiated before any word of the previous block was accessed. If the quantities C and T refer as before to computation time and tape time, the execution time per tape block is now max (C, T); it is therefore possible to keep the tape going at full speed if C ≤ T. (Note: MIX is an idealized computer in this regard, however, since no I/O errors must be treated by the program. On most machines some instructions to test the successful completion of the previous operation would be necessary just before the ‘IN’ instruction here.)
I don't quite understand why we don't need a JBUS instruction in WORDIN. Say our input is spread across four blocks:
- We start off with block 1 in INBUF1 and block 2 in INBUF2.
- Then, when we reach the end of INBUF1, we call IN to read block 3 into it and start processing block 2 in INBUF2.
- When we reach the end of INBUF2, we call IN to read block 4 into it and start processing block 3 in INBUF1.
But what if we haven't finished reading block 3 into INBUF1 yet? Shouldn't we insert a JBUS *(U) before line 6 to ensure that all words of block 3 have been read in before we start processing it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
