taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.3.1-26

Exercise 1.3.1-26

not stated yet in Lean solution written

Rating32
KindK6, write a program: write a MIX or MMIX program from the written solution
SectionSection 1.3.1 of Volume 1. Companion chapter: Description of MIX

The task

Design a two-card loading routine for MIX that reads data cards and a transfer card under the stated character restrictions.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Write the plan as a MIXAL program first, and then convert it to a card. The restriction says that every byte of every instruction word is a character code below 4848, not 2020 and not 2121.

Hint 2

With these limits the address of every instruction is less than 4848 (the high byte must be 00), the fields F=8L+RF = 8L + R must not be 2020 or 2121 or above 4747, and the constants must be made by arithmetic or loaded as parts of the card.

Hint 3

Use the instruction NUM to convert the digits: it takes each byte mod 1010, so both 30…3930 \ldots 39 and the over-punched 10…1910 \ldots 19 give the digit.

Solution

Show the solution

This exercise is only sketched here. The plan is below, and the coding of the program into 32 words under the restrictions is left to the reader.

Plan. The GO button reads one card into the cells 0…150 \ldots 15 and jumps to cell 0. The first card holds a short program that reads the second card into the cells 16…3116 \ldots 31 by IN 16(16) and waits with JBUS *(16). The two cards together hold the loader and its constants, at most 3232 words in the cells 0…310 \ldots 31. Every address in the loader has a high byte 00, so that it does not depend on bb. The buffer for a data card is the cells 32…4732 \ldots 47, so that the buffer addresses are less than 4848 as well.

The main loop reads a card into the buffer, then looks at column 6. A zero means the transfer card TRANS0nnnn: the loader converts columns 7 to 10 to a number, as below, and jumps to the cell nnnnnnnn. A digit c≥1c \ge 1 means a data card with cc words. The loader takes the word that holds the columns 66 to 1010 and drops column 6 by a shift. The field (2:5)(2:5) cannot be used for this, because 8⋅2+5=218 \cdot 2 + 5 = 21 is not a legal character. Then NUM gives the location. The loader stores it by STA with the field (0:2)(0:2) into the address field of an instruction below. Then, for each of the cc words, LDA and LDX take the two buffer words of columns 11…2011 \ldots 20, NUM turns them into a number, and the sign is decided from the character in column 20 (its code is less than 2020 when the digit is over-punched). The word is stored by an instruction whose address was set from the location and the count. The loop counts the words down by DEC and J..P.

The three difficulties are listed here. First, ENT, INC and CMP are not allowed, so constants come from words on the cards and counters are made with SUB and with JAP, JAN. Second, a constant like the byte value 2020 cannot be punched, so it has to be made as a sum or a product of allowed bytes. Third, all instructions have to be placed so that the self-modified fields stay below 4848. The proof that all of this fits in two cards is the part that is not given here.

Check

The plan was not run. A check of the sizes: a card has 8080 columns, that is 1616 words, so two cards give 3232 words. A data card has 5+5+7⋅10=805 + 5 + 7 \cdot 10 = 80 columns: the five ignored columns, the count with the location, and seven words of ten digits.

Remarks

The problem is the same as the problem of the first loader of any real machine. Exercise 1.3.1-21 mentions the GO button that starts it.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.