Comp 200 Homework 8

Due in class on Wed 24 Apr 2002
  1. Write a Jelly2000 program which multiplies the two numbers stored in memory locations 2001 and 2004 respectively, and stores the result in memory location 2010. Show the contents of these memory locations, then run the program, and again show the contents of these memory locations.

    Then, run your program in the Jelly2000 Machine Inspector. (You'll want your program in a separate file, for this.)

  2. Write a Jelly2000 program which sums the squares of odd numbers between 1 and N, where N is provided in memory location 321. That is, calculate 1²+3²+5²+...+N². (Note that the reference sheet already contains a program to compute 1+2+3+...+N.) As above, run your program with Jelly2000 Machine Inspector to check your work.

    Alternately: you can compute the sum: 1 - 1/3 + 1/5 - 1/7 + 1/9 - ..., for N terms or so, and multiply the result by four. (There are better ways to calculate pi, though.) Okay, Jelly2000 doesn't have fractions, so you instead can mutliply each term in the series by K (with perhaps K being 100,000 or so), and compute K*pi (or at least, an integer near K*pi). You can base one of your projects on calculating pi several ways, in Scheme and/or Jelly2000, along with a 1-2 page write-up of your approach.