Silver_Smoulder icon

[ASM] Upper to Lower by prof

Silver_Smoulder | PRO | 10/24/19 03:11:49 PM UTC | 0 ⭐ | 405 👁️ | Never ⏰ | []
text |

1.82 KB

|

None

|

0 👍

/

0 👎

#Input 2 digits, each as a character, convert them to numbers, add and output
 	.text
	.globl main
 main:
	la $a0, m1                  #what to output (contents of m1)
	li $v0, 4                      # Display a message.
	syscall
 	la $a0, Instr	#where to put input
	li $a1, 4                      # Length in a1-last must be enter (this actually                                                        #   gets 3 digits).
	li $v0, 8                       # Read Input string.
	syscall                 
                   li $t1, 0                #get address of input
                  li $t2,32                      # amount to add to make lower case
                  addi $a1,$a1,-1                #since actually got 3 digits set counter to 3
getdigit:    
                  lb $t0, Instr($t1)                 # Load from the address in t1
                  add $t0, $t0,$t2         #make it a lower case
                  sb $t0,Instr($t1)
  	         addi $t1,$t1,1                 #go to next digit
                  addi  $a1,$a1,-1              #is it  a digit
                  bgt $a1, $0, getdigit        #if not done continue
         la $a0, m6 #Prints message.
        li $v0 4
        syscall
        la $a0,Instr
        li $v0 4
        syscall
end:	
         la $a0, m8 #Prints Goodbye.
        li $v0 4
        syscall
         la $v0,10
	syscall	   # au revoir...
 ###########################################################
#			data segment				
###########################################################
 	.data
m1:	.asciiz "Enter a 3 letter word in all upper case \n "
m6:	.asciiz "\nIn lower case is: \n "	
m8:           .asciiz "\nGoodbye!\n" #For exiting.
                   .align 2
Instr:	.space 10       # Space for in string.
 ## end of file.

Comments