Question: 1 . Write a C program that decodes an input machine code. Your program should be able to decode the R , I, S ,

1. Write a C program that decodes an input machine code. Your program should be able to decode the R, I, S, SB, and UJ type instructions listed below. We will only test the following instructions.
add addi
and andi
beq bge
blt bne
jal jalr
lb lh
lw
or ori
sb sh
sll slli
slt slti
sltiu sltu
sra srai
srl srli
sub sw
xor xori
When the program is started, your program will print Enter an instruction: and receive one 32-bit machine code from user. Then, the program will decode the machine code and print the information (type and values of individual fields of the instruction format) of the instruction. The following is the example execution of the program. The program must produce the following sample results in the exact same format.
Example1 :
Enter an instruction:
00000000001100100000001010110011
Instruction Type: R
Operation: add
Rs1: x4
Rs2: x3
Rd: x5
Funct3: 0
Funct7: 0
Example 2:
Enter an instruction:
00000000101001100111011010010011
Instruction Type : I
Operation: andi
Rs1: x12
Rd: x13
Immediate: 10(or 0xA)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!