Silver_Smoulder icon

[ASM} Memory Management by Prof

Silver_Smoulder | PRO | 10/23/19 03:13:46 PM UTC | 0 ⭐ | 423 👁️ | 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, 3                      # Length in a1-last must be enter (this actually                                                        #   gets 3 digits).
	li $v0, 8                       # Read Input string.
	syscall                 
                   la $t1, Instr                 #get address of input
                  li $t2,48                      # amount to subtract to make ASCII decimal
                  addi $a1,$a1,-1                #since actually got 3 digits set counter to 3
getdigit:    
                  lb $t0, ($t1)                 # Load from the address in t1
                  sub $t0, $t0,$t2         #make it a digit
                   la $a0, m6                # print a newline.
                  li $v0 4
                  syscall
 	move $a0,  $t0 
	li $v0 1                        #print number
	syscall
 	addi $t1,$t1,1                 #go to next digit
                  addi  $a1,$a1,-1              #is it  a digit
                  bgt     $a1, $0, getdigit        #if not done continue
end:	
        la $a0, m8 #Prints Goodbye.
        li $v0 4
        syscall
         la $v0,10
	syscall	   # au revoir...
 ###########################################################
#			data segment				
###########################################################
 	.data
m1:	.asciiz "Enter a Number \n "
m6:	.asciiz "\nThe digit is: \n "	
m8:           .asciiz "\nGoodbye!\n" #For exiting.
                   .align 2
Instr:	.space 10       # Space for in string.
 ## end of file.

Comments