Pretty new to assembly language and I need help with this problem. I'm trying to traverse through a string and see if each character is either a number or a operand (+, -, *, /). Everytime I run the program, it doesn't work properly. I'm pretty sure the error is in the 'lb' line after my loop label but I can't figure out what is wrong. Any help would be greatly appreciated. Thank you.

.data
string1: .asciiz "Please enter a string. Make sure the string only contains RPN characters: "
string2: .asciiz "Invalid input: "
string3: .asciiz "Input is valid.\n"
string4: .asciiz "The first operator is "
string5: .asciiz "No operator found.\n"
string6: .asciiz "Please enter a single interger: \n"
string7: .asciiz "Please enter a single operator (+,-,*,/): \n"
string8: .asciiz "The result is "
input: .space 50
output: .space 3

	.text
	.globl Olu
Olu:
	la	$a0, string1
	li	$v0, 4
	syscall
	
	la	$a0, input
	li	$v0, 8
	syscall

	move $s0, $a0			 #address of input

loop:
	lb $t0, ($s0) 			     # gets a character
	beq $t0, $zero, next		# runs loop till 0 is received
	blt $t0, 48, charCheck	       # checks if char is less than 0
	bgt	$t0, 57, notValid	# checks if char is greater than 9
	add $s0, $s0, 1			 # moves along string
	j loop

notValid:
	la $a0, string2
	li $v0, 4
	syscall

	move $a0, $t0
	li $v0, 11
	syscall
	j next

charCheck:
	bne $t0, 42, notValid		#checks if char is equal to op
	bne $t0, 43, notValid
	bne $t0, 45, notValid
	bne $t0, 47, notValid
	add $s0, $s0, 1	
	j loop

next:
	li $v0, 10
	syscall

Also, if anyone knows of a decent MIPS simulator/debugger, please let me know. Thanks again!

Figured out what was wrong, really stupid mistake. The move instruction before the loop label was supposed to be from $v0 to $s0, not $a0 to $v0. However, when I make the correction and run the program, I get an address out of range error at the 'lb' instruction which is definitely not supposed to happen. Any help would greatly be appreciated. Thanks again!

Never mind, figured it out. Made a stupid error, on the 'lb' instruction. Thanks for all the "help" everyone.

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.