Starting from:
$35

$29

Project 0 Decoder Solution

Note that this extra project is optional. If you decide not to work on this project, your midterm score will remain the same. If you decide to work on this project, 4 or 7 points will be added to your midterm as follows:




Part I (4 points) Part II (3 points)




Note that you midterm score is maxed at 55 points.




Part I: What is that instruction (4 Points)




What you need to do is to implement a program named mc2instr.asm that decode a 32-bit machine code (in hexadecimal) back to instruction. Simply put, your program will ask user to enter a 32-bit machine code in a form of an 8-digit hexadecimal number and prints out the instruction associated with the given machine code as shown below:







Please enter a machine code (hexadecimal): 00028020 add




Please enter a machine code (hexadecimal): 00108e82 srl




Please enter a machine code (hexadecimal): 2008ffff addi




Please enter a machine code (hexadecimal): 3211003f andi




Please enter a machine code (hexadecimal): 11020027 beq




Please enter a machine code (hexadecimal): 08100086 j




Please enter a machine code (hexadecimal): 0c1000bd jal




Please enter a machine code (hexadecimal): afbf0000 sw




Please enter a machine code (hexadecimal): 03e00008 jr










Once your program prints the name of the instruction, simply asks a user again. For simplicity, you do not need to check whether a user enter a valid 8-digit hexadecimal string and we will only test with instructions listed in Table 1.




1


Instruction
op (Hex)
op (Bin)
funct (Hex)
funct (Bin)










add
00hex
000000
20hex
100000
addi
08hex
001000
N/A
N/A
and
00hex
000000
24hex
100100
andi
0Chex
001100
N/A
N/A
sub
00hex
000000
22hex
100010
or
00hex
000000
25hex
100101
ori
0Dhex
001101
N/A
N/A
nor
00hex
000000
27hex
100111
slt
00hex
000000
2Ahex
101010
slti
0Ahex
001010
N/A
N/A
sll
00hex
000000
00hex
000000
srl
00hex
000000
02hex
000010
beq
04hex
000100
N/A
N/A
bne
05hex
000101
N/A
N/A
j
02hex
000010
N/A
N/A
jal
03hex
000011
N/A
N/A
jr
00hex
000000
08hex
001000
lw
23hex
100011
N/A
N/A
sw
2Bhex
101011
N/A
N/A
lh
21hex
100001
N/A
N/A
sh
29hex
101001
N/A
N/A
lb
20hex
100000
N/A
N/A
sb
28hex
101000
N/A
N/A






Table 1: Instructions and Control Values




Note that you program needs to print only the instruction mnemonic. It does not have to print the complete instruction in this part.




Part II: Operands (3 Points)




This part is an extension to the Part I. Simply make your program prints a complete instruction associated with the given 8-digit hexadecimal machine code as shown below:







Please enter a machine code (hexadecimal): 00028020




add $s0, $zero, $v0




Please enter a machine code (hexadecimal): 00108e82




srl $s1, $s0, 26




Please enter a machine code (hexadecimal): 2008ffff




addi $t0, $zero, -1




Please enter a machine code (hexadecimal): 3211003f




andi $s1, $s0, 63




Please enter a machine code (hexadecimal): 11020027




beq $t0, $v0, Label




Please enter a machine code (hexadecimal): 08100086




j Label




2



Please enter a machine code (hexadecimal): 0c1000bd jal Label




Please enter a machine code (hexadecimal): afbf0000 sw $ra, 0($sp)




Please enter a machine code (hexadecimal): 03e00008 jr $ra







Note that for instructions that need a label (beq, bne, j, and jal), simply print the string Label as shown above. All immediate values should be printed in decimal (using system call 1) for simplicity. The MIPS Reference Data can be found on the next page.




Submission




The due date of this project is stated on the CourseWeb. Late submissions will not be accepted. You should submit the le mc2instr.asm via CourseWeb. Again, we will only test your program with valid hexadecimal and instructions listed above. No need to perform error checking.





































































































































3





More products