Search code examples
assemblymipsmachine-codeinstruction-set

How to convert MIPS instructions to machine code?


I'm stuck at converting the below MIPS instruction to machine code

  sb $t3, 40($s2)
  beq $s0, $s1, Lab1
  j Lab1

  jr $s0

So far, I have

101000  10010       01011       101000
000100  10000       10001       0x00400000

How do I go from here? Since 0x00400000 is address not value, I don't think I translate it into binary. And so on... I can't really find an example to go on from here.


Solution

  • Ah I think I'm getting a better idea now by looking at MIPS: Calculating BEQ into Hexadecimal Machine Code and Lưu's answer.

      beq $s0, $s1, Lab1
    =>000100 10000 10001 0x00400000
    =>0001 0010 0001 0001 (0x004000040 + 1 away instruction)
    =>0001 0010 0001 0001 0000 0000 0000 0101
    =12110001
      j Lab1
    =>0000 1000 0001 0000 0000 0000 0000 0000
    =08100000
      jr $s0
    =>0000 0000 0000 0000 0000 0000 0000 1000
    =02000008
    

    So this is what I got. If any error please let me know.