How to convert MIPS instructions to machine code?

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.

41k 15 15 gold badges 175 175 silver badges 508 508 bronze badges asked Jun 27, 2014 at 21:46 user3754212 user3754212 31 2 2 silver badges 9 9 bronze badges

3 Answers 3

The encoding depends on the instruction type.

For relative branch like beq , the immediate is the offset so you need to specify the distance between the current instruction and the branch target. For example to skip next 3 instructions you need beq $s0, $s1, +3 which encodes as

opcode $s0 $s1 +3 000100 10000 10001 0000 0000 0000 0011 

For absolute jump you need to make sure that the target and the current instruction's high 6 bits are the same. The immediate address is the target's low 26 bits shifted by 2. The j instruction's format is 0000 10ii iiii iiii iiii iiii iiii iiii so j 0x00400000 will be encoded as

0000 1000 0001 0000 0000 0000 0000 0000 

You can read more about the encoding in this question as well as the courses here:

The instruction encoding is also available here

But why do you use both conditional branch and jump to Lab1 right beside each other? It's useless because eventually it will jump without doing anything