Process of Converting a MIPS Instruction to its Hex code

24,069

You need to put it together in binary, not in hex.

The little numbers in the image tell you the amount of bits of every part.

add = op code of 0, 000000 in bin
$s3 = 19 in decimal, 13 in hex, 10011 in bin
$s5 = 21 in decimal, 15 in hex, 10101 in bin
$s0 = 16 in decimal, 10 in hex, 10000 in bin
shamt = 0, 00000 in bin
funct = 20 from add, 10100 in bin

Then put everything together and convert to hexadecimal:

0b00000010011101011000000000100000 = 0x02758020

Share:
24,069
Captain Hook
Author by

Captain Hook

Updated on February 13, 2020

Comments

  • Captain Hook
    Captain Hook about 4 years

    I'm trying to find an explanation online, but everything I find seems to be a conversion program someone wrote that doesn't really explain it. Looked for questions here on SO and most of it is above my pay grade, I'm looking at the very beginning of the basics. I understand the idea (I think):

    `add $s0, $s3, $s5`
    

    Isolate them like so Green sheet snippet

    And keeping in mind "rd" needs to come from the first register, $s0, convert the pieces to hex based on the MIPS Green Sheet, giving us

    add = op code of 0  
    $s3 = 19 in decimal, 13 in hex  
    $s5 = 21 in decimal, 15 in hex  
    $s0 = 16 in decimal, 10 in hex  
    shamt = 0  
    funct = 20 from add
    

    This already has me lost, since it would be 0131510020... Not 8 bits. Nope.

    And based on this online converter, it comes out as

    `02758020` in hex
    

    How in the world does that happen? I'm even playing with the converter, just moving up one register at a time and the changes are just confusing me further. Is there a trick to this I missed or a good resource? Every video I find is talking about machine code (binary) and never goes into the hex portion of it.