[an error occurred while processing this directive]
CIS 110

Recitation 7 Exercises (24/25 October 2012)

This week's exercises will likely take longer than usual. It's worth putting some time into them if possible, because they are directly relevant to homework 5.

Question 1 Write a program that takes two numbers stored in mem[01] and mem[02] (memory addresses 0x01 and 0x02), adds them together, and stores the result in mem[03]. This should require 4 TOY instructions.





Question 2 Write a TOY program that computes c = a % b using repeatedly subtracting b from a until the result is smaller than b. Assume that a is stored in register R[A], b is stored in register R[B], and c in R[C]. Your program will be very similar to the multiplication program below (a simplified version of what we covered in lecture on Friday). Hint: Use the "branch positive" instruction.

10: 7C00   R[C] <- 0000                  c = 0;
11: CB15   if (R[B] == 0) goto 20        while (b != 0) {
12: 1CCA   R[C] <- R[C] + R[A]               c += a;
13: 2BB1   R[B] <- R[B] - R[1]               b--;
14: C010   goto 10                       }
15: 0000   halt





Question 3 Write a TOY program that repeatedly reads from stdin into R[A] until it reads the value OxFFFF. Recall that to read from stdin, you simply read from memory location OxFF. This will be the basis for the outer loop of your TOY Encryption program.





Question 4 Write a register map for your TOY Encryption program. Your map should list every variable and constant value your program will need, and which register you will store it in. Even if you change your mind or discover your forgot something later, figuring out as detailed a register map as possible in advance will help you develop your program.