Instructions that takes register of ASCII character value as operand in MIPS

StackOverflow https://stackoverflow.com/questions/22865069

  •  27-06-2023
  •  | 
  •  

Question

I learned that in MIPS, there are same operation for unsigned and signed numbers (such as lbu vs. lb).

And also learned that unsigned operation is useful when operating with ASCII characters. Such as using lbu instead of lb.

But I am not sure why. If $s0 has the value of '0' character, the hex value for the character is 0x30, then isn't the following two instructions have the same result? If it isn't, can you please explain me why?

lb $t1, $s0

lbu $t1, $s0

Also, is adding or subtracting operation that takes two register of ASCII character value as operands need to be unsigned operation too? (add/sub vs. addu/subu)

Thanks!

Was it helpful?

Solution

1)using lb and lbu you will get the same result when the MSB of the byte is 0, but if it is 1 then lb will fill the remaining 3 bytes with '1's while lbu will fill them with '0's

2)There is no difference in add/sub (u) except for overflow detection

You're welcome!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top