How to check if the character I typed is a letter or number in MIPS

Asked

Viewed 328 times

-1

I am a beginner in MIPS programming (I use MARS), my teacher asked us to do a program where given 9 digits of a CPF he calculates the last two digits of this CPF. The program is working, but my program crashes when I enter a letter, my teacher wants the program to treat when the user enters with a letter, but I don’t know how to do this, how do I compare the value typed by the user with all the letters of the alphabet? I could make a condition for each letter of the lower or upper case alphabet, but I don’t think this is the best way to do it.

The initial problem is that I use a "function" to read integers in the program, so if a letter is typed it gives a direct error.

li $v0, 5            #comando para ler um inteiro
syscall              #chamando o sistema para executar as instruções
la $t2, 0($v0)

I use the above code, the check would come after it and I would compare the $t2 to know if it is a letter or not, but this code only works to read whole, so if I type a letter it stops immediately!

Thanks in advance for any tips you have to give me!

1 answer

-2

I work with python, but the idea is the same, take face character one by one and turn it into ASCII code, each character has a sequence, for example of the number 0-9, in ASCII represents of ex:"60-69" then make a test, if the chosen character transformed into ASCII is greater than 60 and less than 69, it is integer number.

This method can be used for various tests, whether it is string or not, is if special character etc...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.