Homework Ten

From Scheme to C

Comp210

Due: 97.Apr.08 (Wed.) in class

You don't need to write templates if you don't want, but (as always) every function must have a contract, and (if it's not obvious from the name) a short description of what it does. A large component of the grade is based not so much on correctness, as on having a clearly organized, well thought out, straightforward solution. If you notice yourself repeating similar chunks of code, abstract over it!

Be sure to submit your test inputs and the resulting outputs for each problem.

  1. Transliterate the solution to the jail-cell problem from Scheme into C. Change as little as possible -- keep corresponding functions, a globally-declared vector, a placeholder for the number of cells, etc. Use a C "for"-loop instead of the Scheme fori=, and will make the appropriate translations for this. However, instead of returning a list, the C program will print the open cells' numbers.

  2. For this problem use a global vector of numbers data, and placeholder N for its size. That is, in Scheme, your solution would start off with
    (define N 5)
    (define data (make-vector N 'uninitialized))
    
    1. Using Scheme, write a function with natural recursion which returns the sum of data[0]...data[N-1].
    2. Convert this to a tail-recursive function.
    3. Write a function which reads N numbers from the keyboard, placing those numbers into data.
    4. Re-write the tail-recursive-summing and reading in Scheme using fori= as seen in lecture.
    5. Rewrite these functions (sum and read) as a C program.
    6. Convert your C program into Jam2000 machine language, including assembly code in comments (as well as english comments to the assembly code).