I thought I could check if there's an overflow, but not sure what register will hold a flag. I need to inform the user that the value is too large and to insert again.
I have this code :
.data
binBuffer: .space 20
.text
main:
addu $t0, $t0, 4294967298
li $v0, 36
move $a0, $t0
syscall
But when I print it, it shows the number 2, however, I thought I could compare the original number with 2 but then I couldn't even store that large number.
Any thoughts how to inform the user if the number is too large?
The above code is just a minimum application, what I'm doing is taking the user input from console as decimal strings, and then convert them into hex and binary. and also the decimal taken from the user is stored into a string and then is also converted into a decimal number with base 10
Detecting a string that represents an integer to see if it fits in 32 bits is not a MIPS specific problem.
Here are sone basic approches.
Do string compare for max values.
Use extended precision arithmetic, such as 64 bit arithmetic. With that, check for either too many digits (e.g. 12), or a 64-bit number that doesn't fit in 32-bits.
Check for overflow in all arithmetic operations, here ×10, and addition. Since these are such simple operations, can check for overflow before the operation! For example in 8 bits unsigned, 25 × 10 will not overflow (250), but 26 × 10 will (260), so can check for > 25 before multiplying, Otherwise, if easy (i.e x86) check after.