Reputation: 75
I'm trying to translate the following command to Hex:
beq $s1,$t3,label
It's also given that the command address is 0x1500, and the label address is 0x1000.
So far i know that beq equals 4(hex) and the binary values of the registers.
I know that at first I need to convert to binary and then to Hex, but i can't understand what to do with the label address. Do i need to divide it by 4 to get the value?
Upvotes: 1
Views: 1423
Reputation: 22585
BEQ
opcode is 000100
(binary).
The instruction format for BEQ
is:
OpCode|SR|DR|Offset
where
000100
10001
for $s1
01011
for $t3
1111111010111111
You can now concatenate the bit fields and write them in hexadecimal if you wish:
0001 0010 0010 1011 1111 1110 1011 1111
which is 0x122BFEBF
[edit: added explanation of how to compute the offset]
To compute the offset you have to subtract the value of PC+4 (where PC stands for the address of the branch instruction) and the address of the target location. Then divide that address by 4 (or shift right two times). As the offset is encoded in A2 compliment, if the result of the operation is negative you have to apply A2's compliment to get the encoded value.
Upvotes: 1