Pensando Ando
Pensando Ando

Reputation: 19

Storing more than 32 bits in MIPS

I've had a lot of trouble with MIPS for storing values in registers (not div or mult operations). I need to store or hold data with 5 and 8 bytes, for example. How can I obtain a value such as 0x1235343036 (5 bytes) in the $t3 register?

If I do the operation as

li $t3,0x1234
li $t4,0x567812
sll $t3,$t3,24

the register $t3 only contains 0x34000000. (12 is lost. I want something like 0x1234000000, after doing an "or" operation with $t4 to obtain something like 0x1234567812 in the $t3 register.)

I want registers larger than 32 bits. How can I achieve this?

Upvotes: 1

Views: 2802

Answers (1)

Zuljin
Zuljin

Reputation: 2640

I'm not a MIPS assembler expert, but I don't think it is possible to have larger register(unless your CPU has some SIMD instruction unit). You have to workaround this by using 2 registers to emulate 64-bit operations. Here is some pseudo code how you can do this:

# t1 is high dword of first variable, t2 is low dword of first variable
# t3 is high dword of second variable, t4 is low dword of second variable
# lets assign values to both variables
t1 = 0
t2 = 0x1234
t3 = 0
t4 = 0x567812
#now shift left first by 24 bits
t1 = (t1 << 24) + (t2 >> (32 - 24))
t2 = t2 << 24
#now lets or with second
t1 = t1 | t3
t2 = t2 | t4

Upvotes: 1

Related Questions