I'm struggling to figure an efficient way to check if the user entered a valid input which is only numbers (0~9), using syscall 8
the input is 4 bytes long (1 word),
and I need to check for each byte (char) if it's a number or not,
I thought of trying to run through a loop and check if its ascii value is lower than 48 ('0' ascii decimel value),
or higher than 57('9' ascii decimel value),
Is this an efficient way of doing this?
and if so, what's the right way to implement such if statement in MIPS?
for example
if (x < 48) or (x > 57) {...}
*Note: assume I do have a flag to know where to stop the loop
*Edit: this is a segment of the code, to make it clearer:
.data
number:
.word w1
.text
.globl main
main:
la $a0, number # read the number input from user
li $a1, 6 # buffer set to max of 4 bytes (32 bits),
# assuming the input is no more than the length of a word,
# + 2 reserved bytes
li $v0, 8
syscall