user3657279
user3657279

Reputation: 188

Mips instructions mthi and mtlo into hex?

I am in the process of writing a utility to convert a mips instruction into its hex (4 bytes) format. Everything was going ok with instructions such as ADD, etc. But with mthi and mtlo, there is a different in the output I am getting compare to what is expected. I am not sure what exact version of mips this is.

Here is what I am getting:

mthi    $t2  = 01400011
mthi    $s0  = 02000011
mtlo    $t8  = 03000013
mtlo    $a3  = 00e00013

Here is what I am getting:

mthi $t2

1010 00000 00000 00000 010001

Does anyone know how the inner bits are being calculated and what version of mips that is? Thanks.

Upvotes: 0

Views: 1763

Answers (2)

markgz
markgz

Reputation: 6266

The MIPS 32R2 encoding of MTHI rs is binary 000000 sssss 000 0000 0000 0000 010001.

So MTHI $t2 is binary 000000 01010 000 0000 0000 0000 010001

Upvotes: 0

D'Nabre
D'Nabre

Reputation: 2262

Information from "See MIPS Run", for all MIPS ISA it covers (up through MIPS IV) there is no difference in the MIPS32 instruction.

This is the format for mfhi, mtlo, mfhi, mtlo (mfhi/mflo included for comparison and completeness)

bit:     31-26  25-21  20-16   15-11  10-6  5-0 
mfhi rd    0      0      0      rd     0     16 
mthi rs    0      rs     0      0      0     17 
mflo rd    0      0      0      rd     0     18 
mtlo rs    0      rs     0      0      0     19 

So mthi $t2 (register #10)

mthi $t2   000000 01010 00000 00000 00000  01001 

Upvotes: 1

Related Questions