Created
May 23, 2022 17:55
-
-
Save yuvve/a87b1c39dbef0d6ec8690a80c725bae5 to your computer and use it in GitHub Desktop.
Makes it easier to read machine code by splitting the bits depending on the MIPS instruction
This file contains 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
def i_type(s): | |
op = s[0:6] | |
rs = s[6:11] | |
rt = s[11:16] | |
imm = s[16:] | |
return f"{op} {rs} {rt} {imm}" | |
def r_type(s): | |
op = s[0:6] | |
rs = s[6:11] | |
rt = s[11:16] | |
rd = s[16:21] | |
shamt = s[21:26] | |
funct = s[26:] | |
return f"{op} {rs} {rt} {rd} {shamt} {funct}" | |
def j_type(s): | |
op = s[0:6] | |
addr = s[6:] | |
return f"{op} {addr}" | |
def main(): | |
bits = input("bitar: ") | |
mode = input("i for I-type, r for R-type, j for J-type: ") | |
match mode.lower(): | |
case "i": | |
print(i_type(bits)) | |
case "r": | |
print(r_type(bits)) | |
case "j": | |
print(j_type(bits)) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment