CS 10 Homework 6

Due by the beginning of class Tuesday, March 4
  1. Finish reading the Programming Languages article by Lawrence Tesler that I handed out in class.

  2. Write two PIPPIN assembly language programs: one for converting Farenheit to Celsius, and the other for converting Celsius to Farenheit. The relevant formulas are shown below:

    C = 5 × (F - 32) / 9

    F = 9 × C / 5 + 32

    Each program should assume that its input value (the initial Farenheit or Celsius value) is stored in memory location X, and should store its output value (the converted temperature) in memory location Y. For example, storing 50 in location X and running the Farenheit-to-Celsius program should result in 10 at location Y when the program halts. Make sure to test your programs in the simulator to verify that they work.

    WARNING: When you test your programs in the simulator, use small numbers, in order to ensure that the values being computed don't go outside the range of -128 to +127 (including intermediate values such as 9 × C). Otherwise, the simulator may crash or freeze up.

    Use the SAVE AS button in the PIPPIN CPU simulator to save your programs under the names FtoC and CtoF.

  3. Write a PIPPIN program to add up the numbers 1, 2, 3, ..., N. The input to the program should be the number N, stored in location X. The output (the sum of the numbers) should be stored in location Y. For example, with X equal to 5, the program should output 15 in Y (the sum of 1 + 2 + 3 + 4 + 5). You will need to use some sort of loop for this problem.

    Save your program under the name Sum.

  4. Write a program to determine if the input number X contains a particular digit W. The output in location Y should be 1 if the digit is present, or 0 if it isn't. For example, if X is the number 124 and W is 2, the output in Y should be 1, since 2 occurs in 124. If W is 3, the output should be 0. You should use a loop for this problem. Hint: to figure out the next digit of a number, use a variant of the divide-then-multiply trick we discussed in class.

    Save your program under the name Digits.

Turning in your homework

Put your four PIPPIN program files into a folder called Your name HW 6 and drop it into the CS 10 drop folder. In addition, please write or print out your programs on paper and turn this in during class.