Lesha
Lesha

Reputation: 182

32-bit signed words in mips

I am trying to write a simple mips program and I'm stuck on declaring a 32-bit signed integer.

I've written the following simple code:

.data
max: .word 11111111111111111111111111111111

I expect the value of max to be -1 but my IDE tells me that the number is being interpreted as -954437177. I am using MARS 4.4 as my IDE.

What am I doing wrong? How do I get mips to actually recognize the value as -1?

Upvotes: 0

Views: 1551

Answers (1)

Luo Sen
Luo Sen

Reputation: 74

.word puts the number into decimal, and when you convert it, since its 32-bit, you will only get last 32 bit. 11111111111111111111111111111111(10)= 10001100001111011110111110110001111011011011100110000100111111100010101011000111000111000111000111000111(2)

last 32-bit: 11000111000111000111000111000111(2) = -954437177 If you want to store -1 as 32-bit, try .word 0xFFFFFFFF which has a value of -1

Upvotes: 1

Related Questions