This assignment continues the construction of the Java Virtual Machine (JVM) you began writing in Assignment 3. Hopefully you designed the code in an extensible fashion, and it is debugged.
You have two alternatives: extend your JVM code to implement the features in this assignment, or extend Ashish's sample program. If you use the sample solution, you'll need to answer a few questions so that we know you understand what goes on in that code. In this case, hand in your answers to the following in class on Monday:
You'll need to add the following new bytecodes:
Name | Bytecode | Instruction Format | Operations | Description |
IALOAD | 0x2e | IALOAD | POP v1, PUSH *(v1) | Load from index at top of stack |
IASTORE | 0x4f | IASTORE | POP v1, POP v2, *(v1) = v2 | Store at index at top of stack |
IDIV | 0x6b | IDIV | POP v1, POP v2, PUSH (v2/v1) | Integer division (no rounding) |
END | 0x00 | END | End program | End your program |
Name | Bytecode | Instruction Format | Operations | Description |
IADD | 0x60 | IADD | POP v1, POP v2, PUSH (v2+v1) | Integer add |
ISUB | 0x64 | ISUB | POP v1, POP v2, PUSH (v2-v1) | Integer sub |
IMUL | 0x68 | IMUL | POP v1, POP v2, PUSH (v2*v1) | Integer mul |
ILOAD | 0x15 | ILOAD index | PUSH *(index) | Load from mem at index |
ISTORE | 0x36 | ISTORE index | POP v1; *index = v1 | Store to mem at index |
BIPUSH | 0x10 | BIPUSH immed | PUSH immed | Byte Immediate push |
SIPUSH | 0x17 | SIPUSH immedhi immedlo | PUSH immedhi_immedlo | Short Immediate push |
POP | 0x57 | POP | POP v1 | POP value, discard |
IFEQ | 0x99 | IFEQ offsethi offsetlo | POP v1; cond. br. to PC+ offsethi_offsetlo | Branch if v1==0 |
IFNE | 0x9A | IFNE offsethi offsetlo | POP v1; cond. br. to PC+ offsethi_offsetlo | Branch if v1!=0 |
IFLT | 0x9B | IFLT offsethi offsetlo | POP v1; cond. br. to PC+ offsethi_offsetlo | Branch if v1<0 |
IFLE | 0x9E | IFLE offsethi offsetlo | POP v1; cond. br. to PC+ offsethi_offsetlo | Branch if v1<=0 |
IFGT | 0x9D | IFGT offsethi offsetlo | POP v1; cond. br. to PC+ offsethi_offsetlo | Branch if v1>0 |
IFGE | 0x9C | IFGE offsethi offsetlo | POP v1; cond. br. to PC+ offsethi_offsetlo | Branch if v1>=0 |
GOTO | 0xA7 | GOTO offsethi offsetlo | Jump to PC+ offsethi_offsetlo | Unconditional branch |
IRETURN | 0xAC | IRETURN | POP v1 | Integer return |
For the purposes of this assignment, assume that all storage is in 32-bit
words; your stack will need to hold up to 256 operands, and memory will
need to be able to store up to 256 words. You'll need to make space
in your data segment for these areas. Note that you'll need to keep
track of the JVM's internal stack pointer in order to simulate execution.
.data
instruction_count:
.word
<your array program size>
bytecode:
.byte
<your array bytecode program>
array_size:
.word
14
array_values:
.word
1 2 3 4 5 6 7 8 9 99 100 101 500 999
In your main function, you should load the instruction count
and the bytecode for your array program to appropriate parameters for your
jvm function. The array size should be loaded as the first
word in JVM's local memory and should be followed by all the array values.
Once all this is done, you can call your jvm function to simulate
this program.
Turn in a hardcopy (double-sided printout) of your program, as well as an electronic submission using the turnin program. In case you are using Ashish's sample solution, you also need to hand in written answers on Monday.