Computer Science 361.01

Computer Organization

Fall 2003

Homework 7: Due Friday, October 24th at 4:00PM

50 points

 

Please do individually and begin early.

I will not answer questions on this assignment anytime after Thursday’s class.

 

 

1. (20 points) Recall that for the HSC-I computer, bits 0..4 were used for the opcode, and bits 8..15 were used for the operand.   Bits 5..7 were left as zeroes and essentially ignored.  Direct addressing was used except for branching, which used immediate addressing. 

 

For the HSC-II computer, we wish to allow for immediate addressing for some instructions other than branching instructions.  (This will obviously not make sense for all instructions).  An instruction that uses immediate addressing will have its bits 5..7 encoded as 001, except for branch instructions where the interpreter (your C++ program) will continue to assume immediate addressing and ignore these bits.   Direct addressing will explicitly use 000 so HSC-I programs can still run on the HSC-II. 

 

Some examples:

            Jump to instruction at address 5                     01001 xxx 00000101  (xxx any bits)

            Accum := Mem[20]                                          00001 000 00010100  (as in HSC-I)

            Accum := 20                                                    00001 001 00010100

            Accum := -1                                                     00001 001 11111111

 

Note that the range of constants that can be designated using immediate addressing is

-128..+127.

 

Add appropriate code to the Execute() function of your HSC-I Interpreter program so that various instructions are permitted to use immediate addressing.  Then test your C++ program with an HSC-II input program that reads a series of values (just like the HSC-I test program does) but simply outputs the number of values read prior to the sentinel.

You should therefore be incrementing a counter (using immediate addressing) instead of summing.  You should also have the subtraction that tests for the sentinel use immediate addressing.

 

 

 


 

 

2. (10 points) Do problem #26 on page 217.

 

 

3. (10 points) Translate the following Level 6 program to Level 5.

 

      int larger, x, y;

 

      main() {

            cin >> x;

            larger = x;

            cin >> y;

            if (y > larger)

                  larger = y;

     

            cout << larger;

      }

 

 

4. (10 points) Translate the following Level 6 program to Level 5.

It gives approximate temperature conversions:  Fahrenheit to/from Centigrade.

 

     

      char scale;

      int temp;

const int freeze = 32;

 

main() {

      cin >> temp >> scale;

      if (scale == ‘F’) {

            temp = (temp – freeze)/2;

            cout << temp << ‘C’;

      }

      else {

            temp = 2 * temp + freeze;

            cout << temp << ‘F’;

      }

}