COS 111, Fall 1998 - Problem Set 4

Due by 5pm, Tuesday Oct. 20, 1998

Show your work on all problems. Without it, we can't give partial credit.

Problems 1 - 5
Brookshear, Chapter Two Review Problems (pgs 84 - 85):
5, (Added Thu Oct 15 14:39: Assume the machine has a subtraction instruction, unlike Brookshear's machine of Appendix C.)
8 a, b, and e,
11,
12,
15-c.

Problem 6: (This problem also uses the machine language of Appendix C in Brookshear.) Someone wrote the following 2-instruction sequence attempting to interchange the contents of registers 1 and 2:
             4012
             4021

a) This sequence does not work. Execute it assuming the initial contents of register 1 is F5 (hexadecimal) and the initial contents of register 2 is 7A (hexadecimal). Show the result of each instruction, and describe in general terms what actually happens.
b) Write a new instruction sequence that does correctly interchange the contents of registers 1 and 2. (Hint: you need a third register.)

Extra credit
The machine of Appendix C in Brookshear has no subtraction operation. In class, we added one. This was not actually necessary, because the operations of Brookshear's machine can be used to form the two's complement of the contents of a register. If a number x is represented in the register, forming the two's complement of x gives the representation of (-x). Then (-x) can be added to the contents of another register, with the effect of subtracting x from the contents of the second register. Note that applying the two's complement algorithm twice gives you back the same number, so that forming the two's complement of a negative number (-x) represented in two's complement will give you the correct representation for x (= -(-x)).

Give a sequence of machine instructions that takes the contents of register 1, forms the two's complement, and changes the contents of register 1 to be that two's complement.
Hint: consider the logic operation XOR (section 2.5).


Back to Schedule and Assignments