X-TOY EXERCISES
1. This question tests the difference between load address, load,
and load indirect. For each of the following X-TOY programs,
give the contents of registers 1, 2, and 3 upon termination.
(a) 10: 7211 (b) 10: 8211 (c) 10: 7211
11: 7110 11: 8110 11: A120
12: 2321 12: 2312 12: 2312
13: 0000 13: 0000 13: 0000
2. Consider the following X-TOY program. What is the value of
register 3 upon termination?
10: 7101
11: 7207
12: 7301
13: 1333
14: 2221
15: D213
16: 0000
3. Write a program that reads in three integers a, b, and c from
standard input, and computes the discriminant d = b^2 - 4ac.
Use the multiplication from lecture.
4. Write a function that takes two integers as input and
computes their greatest common divisor (gcd). You may use
the following (inefficient) algorithm:
while (b > 0) {
if (b > a) swap a and b
a -= b;
}
return a;
5. Puzzler: write a code fragment that swaps the contents of
registers A and B, without writing to main memory or any
other registers.
6. Suppose one wanted to increase the X-TOY machine memory to 2048
16-bit words, instead of 256. What is the major problem that would
need to be addressed?