Created
November 21, 2020 04:47
-
-
Save shouc/18227f6848b080fa48799d98f3959d44 to your computer and use it in GitHub Desktop.
DecodeCode.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DecodeCode.h" | |
mipsinstruction decode(int value) | |
{ | |
mipsinstruction instr; | |
unsigned int v = (unsigned int) value; | |
instr.funct = v & 0b111111; | |
instr.immediate = value & 0b1111111111111111; | |
unsigned short is_signed = instr.immediate >> 15; | |
if (is_signed){ | |
instr.immediate &= 0b01111111111111111; | |
instr.immediate ^= 0b01111111111111111; | |
instr.immediate++; | |
instr.immediate = 0 - instr.immediate; | |
} | |
instr.rd = v >> 11 & 0b11111; | |
instr.rt = v >> 16 & 0b11111; | |
instr.rs = v >> 21 & 0b11111; | |
instr.opcode = v >> 26 & 0b111111; | |
return instr; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment