Homework 11

  1. Add the following methods to the intVector class which you can fine here. Add functions to test your new methods in intVectorTes.cc.
  2. Suppose you have a machine 32 general purpose registers R0..R21 and with the assembly language instructions in the table below. Write the assembly code for the following switch statement for this machine.
      int s, t, n; //assume these get initialized
    
      switch(n){
      case 0:
        t = 1;
      case 1:
        s = 1;
        break;
      case 2:
        s = 2;
        t = 2;
        break;
      default:
        s = 3;
        t = 3;
      }
    
    Instruction Description
    LOAD R1 X Load the variable X from memory into the register R1
    LDI R1 C Load the constant C (given in the instruction) into register R1
    STORE R1 X Store the value in register R1 into the memory location for variable X
    ADD R1 R2 R3 Add the contents of register R2 and R3 and store the result in register R1. R1 = R2 + R3
    SUB R1 R2 R3 Subtract the contents of R3 from R2 and store the result in R1. R1 = R2 - R3
    JMP L Jump to the instruction with label L
    JE L Jump to the instruction with label L if the result of the last ALU operation was 0.
    JNE L Jump to the instruction with label L if the result of the last ALU operation was lesss than or equal to 0.

HINT: you might consider putting this code in a C program and assembling it to see what it does on our machines.


Clif Presser<cpresser@gettysburg.edu>
Last modified: Thu Apr 23 09:17:46 EDT 2009