Question: Using the skeleton code, implement the decode_instruction function. The only input parameter is the memory address of the instruction. The function decodes the memory and
Using the skeleton code, implement the decode_instruction function. The only input parameter is the memory address of the instruction. The function decodes the memory and prints each field. .data returned: .asciiz "The function returned " .text .globl main main: # Decode the first instruction in function "func" (addi v0, zero, 0x1337) la a0, func jal decode_instruction # Encode the instruction addi v0, zero, 0x1234 li a0, 8 li a1, 0 li a2, 2 li a3, 0x1234 jal encode_instruction # Print string la a0, returned li v0, 4 syscall # Call function jal func # Print return value move a0, v0 li v0, 34 syscall # Exit li v0, 10 syscall func: addi v0, zero, 0x1337 jr ra # Prints the different fields of an I-type instruction # decode_instruction(a0: memory address of instruction) decode_instruction: # Implement B.1 here jr ra # Encodes the fields of an I-type instruction and returns it # encode_instruction(a0: opcode, a1: rs, a2: rt, a3: immediate) encode_instruction: # Implement B.2 here jr ra
Output:
opcode = 8 rs = 0 rt = 2 immediate = 0x00001337
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
