1 Replies - 7431 Views - Last Post: 20 November 2012 - 05:43 AM

#1 wannabe1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-November 12

MIPS uppercase

Posted 18 November 2012 - 03:28 PM

I am trying to convert a string to uppercase. However, if the string contains illegal characters such as ? then the output should be the same as the input and returning a 1 instead of a 0.

So for example if the input is Hello, the output should be HELLO and return 0.
but if the input is Hello?, then the output should be Hello? and return 1.
	      li $v0, 0
		 lb $t2, 0($a0)
		 add $t1, $t2, 0 
		 beq $t2, $0, exit
 		 blt $t2, 48, error 	#$v0 < 48?
	 	 bgt $t2, 122, error 	#$v0 > 122?
		 blt $t2, 57, next 	#$v0 < 57?
		 blt $t2, 65, error 	#$v0 < 65?
		 blt $t2, 90, next 	#$v0 < 90?
		 blt $t2, 97, error 	#$v0 < 97?
		 sub $t2, $t2, 32
		 sb $t2, 0($a0)	
		 sb $t1, 0($a1) 
		 addi $a0, $a0, 1 
		 addi $a1, $a1, 1 	
		 j touppercase
		 li $v0, 1			#store 1
		 sw $a0, $a1
		 j exit
	      jr $ra

I am able to get the right return number of 1 when the input contains an illegal character but for example if the input is Hello?, ny program would return HELLO? and 1.

I believe that I need to store the input somewere, and if the program ever goes to the error branch, then set the output as the input again, but am not sure what I am doing wrong.

Thank you in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: MIPS uppercase

#2 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 168
  • View blog
  • Posts: 1,076
  • Joined: 03-April 12

Re: MIPS uppercase

Posted 20 November 2012 - 05:43 AM

I'm not sure how your environment works (input/output).
If you read the stuff in character by chatacter, you probably need
an input buffer for the original input.

Then you need an output buffer for converted output.

You read the input in first, then convert the input to the output
(just like the code does) and then - if there are no errors, you output the output buffer otherwise you output the input buffer (up to the conversion error?).

I'm a bit too lazy to check the actual conversion (numeric limits and displacements not even knowing your character set), but as soon as you see your output, you should be able to tell if there are mistakes.

Another way of conversion is make a 256-byte conversion table.
You use the input as index to the table. If value is zero, the input character is illegal or something like that.
It would be fast and not that much bigger (as a binary) than the calculating alternative.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1