Skip to content

Instantly share code, notes, and snippets.

@shouc
Created November 21, 2020 04:47
Show Gist options
  • Save shouc/18227f6848b080fa48799d98f3959d44 to your computer and use it in GitHub Desktop.
Save shouc/18227f6848b080fa48799d98f3959d44 to your computer and use it in GitHub Desktop.
DecodeCode.c
#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