CPS 104, Fall 1999                 Homework Assignment #5

Due: Wednesday, 27 October 1999


Write a C or C++ program that disassembles (a subset of) MIPS instructions. Your program should read a "binary" file with hexadecimal list of MIPS instructions. The file has one instruction per line. (See an example below). Your program should translate the file back into a MIPS assembler file. All constants must be printed out in hexadecimal format.

Register names should be the symbolic names and NOT the register number, except register $0. Your program should generate labels for the "jump" and "branch" instructions. Your program should flag illegal or unimplemented instructions (instructions not in the list).

Instruction List
Below is the complete list of MIPS instruction that your program must decode.
Instruction Example
Store Word sw $fp,0x0008($sp)
Load word lw $t5,0x0000($t3)
Load upper immediate lui $t0,0x5555
Add add $t0,$s0,$a0
Subtract sub $t6,$s0,$a0
Subtract unsigned subu $sp,$sp,$a0
Add unsigned addu $fp,$sp,$a0
Add immediate addi $t0,$0,0x0001
Add immediate unsigned addiu $t0,$v0,0xfff1
AND and $t0,$t3,$t6
OR or $t5,$t2,$t5
NOR (not OR) nor $t3,$t1,$t4
XOR xor $s2,$t6,$t0
OR immediate ori $t4,$t0,0x5555
AND immediate andi $s6,$s6,0x3333
XOR immediate xori $t2,$t2,0x5678
Branch equal beq $s5,$0, label
Branch not equal bne $s1,$t0, label
Branch greater-equal 0 bgez $s3, label
Branch less than 0 bltz $s4, label
Branch GE 0 and link bgezal $t0, label
Branch less equal 0 blez $t1, label
Branch greater than 0 bgtz $t1, label
Jump j label
Jump register jr $ra
Jump and link jal label
Jump and link register jalr $t1
Shift left logical sll $v1,$a0,1
Shift left logical variable sllv $t0,$t0,$t4
Shift right logical srl $t6,$a2,1
Shift right logical variable srlv $s6,$s6,$t1
Shift right arithmetic sra $t7,$a1,1
Shift right arithmetic variable srav $s6,$s6,$t1
Set less than slt $t2,$t0,$t1
Set less than unsigned sltu $t3,$t0,$t1
Set less than immediate slti $t4,$t0,0xfffb
Set less than immediate unsigned sltiu $t5,$t0,0xfffb
System call syscall
The instructions format and codes are in the textbook in Appendix A. Please note that the text segment starts at 0x00400000, that is the first instruction is at location 0x00400000. You will need this information to figure out labels' locations. You can assume that the file you read has no more than 2000 instructions.
Generating test files
A test assembler file with a list of assembler instructions and the corresponding "binary" file are provided on-line (See class Web Page) to help you debug your program. Also, you can use the program asmr2000 on the acpub Sun machines to generate test files. Use:
asmr2000  file.s 
Where file.s has a list of assembly instructions you want to convert to "binary". The command will generate a file called hex.out with a sequence of hex values, one value per instruction.
What to submit
You must submit a program that gets a file-name as a formal argument. The file is a "binary" file with a list of assembler instructions in hexadecimal format. Your program should translate and output a file of assembler instructions. Submit to hw5 your source code, a Makefile, and a README file that has a description of what the program is doing, instruction on how to compile the program and instructions on how to run the program.
Please note!
This assignment is the first part of a two-part sequence. You will need to use the code you write for this assignment in order to complete the next. Please start early and make sure that you have a complete working assignment to hand-in.