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-6

Exercise 1.3.1-6

not stated yet in Lean solution written

Rating10
KindK8, compute by machine: find a number or an object by a large computation from the written solution
SectionSection 1.3.1 of Volume 1. Companion chapter: Description of MIX

The task

Find the result of five load instructions on a given word and state which ones are undefined.

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 word as sign, byte 1, byte 2, bytes 3 and 4 (the two-byte number 200), byte 5.

Hint 2

A partial field is shifted to the right of the register. The sign is used only when the field starts at 00. Otherwise the sign ++ is understood.

Hint 3

An index register has only two bytes and a sign.

Solution

Show the solution

Let h=⌊200/b⌋h = \lfloor 200 / b \rfloor and l=200 mod bl = 200 \bmod b. Then bytes 3 and 4 are hh and ll. For b=64b = 64 they are 33 and 88, and for b=100b = 100 they are 22 and 00. The word is + 5 1 h l 15+\ 5\ 1\ h\ l\ 15.

(a) LDAN 3000 loads the whole word with the sign reversed, so rA=− 5 1 h l 15\text{rA} = -\ 5\ 1\ h\ l\ 15 (written −5 1 200 15- 5\ 1\ 200\ 15).

(b) LD2N 3000(3:4) takes bytes 3 and 4 with the sign ++ and then negates. So rI2=−200\text{rI2} = -200. This fits in two bytes.

(c) LDX 3000(1:3) takes bytes 1 to 3, that is 5,1,h5, 1, h, and moves them to the right: rX=+ 0 0 5 1 h\text{rX} = +\ 0\ 0\ 5\ 1\ h. The sign is ++.

(d) LD6 3000 is undefined. It would put the whole word in an index register, which has room for two bytes. Here bytes 1 to 3 are not zero.

(e) LDXN 3000(0:0) takes the sign alone, which is ++ with the magnitude 00, and negates it. So rX=− 0 0 0 0 0\text{rX} = -\ 0\ 0\ 0\ 0\ 0.

Check

python3: with b=64b = 64 the value 200=3⋅64+8200 = 3 \cdot 64 + 8, and with b=100b = 100 it is 2⋅100+02 \cdot 100 + 0. In both cases hb+l=200h b + l = 200. In (c) the last byte is 33 for b=64b = 64 and 22 for b=100b = 100.

Remarks

Case (d) is the usual reason why one loads an index register from a field such as (4:5)(4:5) and not from the whole word.

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.