Optional Homework Assignment
Due on Thursday 6/15
Caution: This is an extra assignment that can replace either of the first
two assignments. It cannot replace either of the final two assignments. There
is a regular assignment due on the Tuesday before this assignment and the
Tuesday after this assignment. Do not complain that you don't have enough
time, this is what is meant by "extra" credit.
You are to write a program using either C++ or Java that will translate a
file of IJVM assembler instructions into the equivalent instructions in hex.
You are not generating microcode, just machine code. For example, IADD would
be translated into 60. The output file should be a text file, not a binary
file (I want to be able to read the output file in a text editor).
Input file
-
All operands will be decimal numbers in the input file.
-
All op codes will be strings (IADD, ISUB, etc.) and can be in upper, lower,
or mixed cases.
-
Create your own input file. You might use the one from column (b) in Figure
4-14on page 226 of the text.
-
I will supply a test file at a later date.
Output file
-
All output should be in hex.
-
The output file will look like column (c) in Figure 4-14 on page 226 of the
text, except for the 0x.
-
Do not display the 0x in front of each number, just display the hex digits.
-
Be sure that byte and const operands are displayed as signed
numbers (2's complement) in two hex digits.
-
Be sure that varnum operands are displayed as unsigned numbers in
two hex digits.
-
Be sure that disp, index, and offset operands are displayed
as unsigned numbers in four hex digits.
-
Be sure that the size of the output is correct for each type of operand and
op code
-
op codes should always display as two hex digits
-
byte and const : display in two hex digits. Examples: 0 as
00, 7 as 07, -1 as FF, -35 as DD
-
varnum : display in two hex digits. Examples: 0 as 00, 7 as 07, 255
as FF
-
disp, index, and offset : display in 4 hex digits. Examples:
0 as 0000, 7 as 0007, 255 as 00FF, 65535 as FFFF
Error checking
-
Op codes can be in upper, lower, or mixed cases.
-
If an illegal operand is found, then display an error message. Continue
processing by reading strings from the file until a valid op code is found.
-
Read and display the appropriate number of operands and verify that they
are in the correct ranges
-
byte and const : -128 .. 127
-
varnum : 0 .. 255
-
disp, index, and offset : 0 .. 65535
-
If an illegal operand is found then display an error message. Continue processing
by reading strings from the file until a valid op code is found.
-
If the final instruction in the file is missing an operand, then display
an error message.