I'm having trouble with my program. I believe I've figured out most of it, but there's one thing that I still have no clue about. That's how to go through a string and check whether it's a digit or letter.

I figured I could do something like this to remove whitespace (although I haven't tested it out yet... just saw this while searching other topics here):

li $t0, 32             # store a whitespace into temp variable
bne $t1, $t0, remove     # if not a whitespace branch to remove

Assuming $t1 is a character I want to check (and remove is defined later in the code).

But that doesn't handle symbols or anything. I'm thinking it may be easier to just check if the character IS a digit/letter instead of checking if it isn't. But I don't know how to do that either.

One more thing. Is there any way to take a input file as a argument? I realize I can prompt the user for input like this:

prompt:          .asciiz "Input: "
buf:             .space 100
li                 $v0, 4                           # system call code for print_string
la                 $a0, prompt

li                 $v0, 8                            # system call code for read_string
la                 $a0, buf
li                 $a1, 100

But can I actually read input from a file given as a argument?

Technically ASCII used to be 7-bit ASCII but with International characters etc. it is 8-bit so treat it as unsigned bytes.

signed and unsigned have different comparisons!

Digits is the smallest subset 10 of 255 posibilities, so checking for a digit is the better solution.

'0' 0x30 48
'9' 0x39 57

#$t1 = character

li  $t0, '0'
bltu   $t1,$t0, notdig        # Jump if char < '0'

li $t0,'9'
bltu   $t0,$t1, notdig       # Jump if '9' < char

# is digit

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.