ams
ams

Reputation: 1

How to go from mips to Machine Code?

For example if I am given j label, where the label is at 0x004000b0 how would I convert it to machine code?

opcode of x02 and the target address is 26 bits. I tried to simulated and got the machine code as 0810002c but I can't calculate it by hand.

Upvotes: 0

Views: 1330

Answers (1)

Jeff
Jeff

Reputation: 7674

From the MIPS instruction reference, page 129:

This is a PC-region branch (not PC-relative); the effective target address is in the “current” 256 MB-aligned region. The low 28 bits of the target address is the instr_index field shifted left 2bits. The remaining upper bits are the corresponding bits of the address of the instruction in the delay slot (not the branch itself).

So if you're jumping to 0x4000B0, you shift it to the right by two bits, giving you 0x10002C. This forms the lower 26 bits of the jump instruction, with the upper 6 bits as 0b000010, giving an overall opcode of 0x810002C.

Upvotes: 1

Related Questions