Silver_Smoulder icon

[ASM] Input and Store an Integer [Functional]

Silver_Smoulder | PRO | 04/02/19 02:52:32 PM UTC | 0 ⭐ | 402 👁️ | Never ⏰ | []
text |

2.88 KB

|

None

|

0 👍

/

0 👎

##write a program that prompts the user for input (integer), and stores it#
 .globl main
.text
 main:
		li $v0, 4 #we're telling the program that we are going to be outputting a string and loading it immediately
		la $a0, prompt #we're telling the program where to look for our message that we defined at the bottom of the program
		syscall #go do it
 		#now theoretically, we should read in an integer as done by the user, with syscall 5
		li $v0, 5 #syscall for code 5 (reading in an integer)
		syscall #go do it
 		move $t0, $v0 #moving the stored integer from $v0 to $t0 so that we can free up the space for the termination code 10
		li $v0, 4 #tell the system we are going to load a string
		la $a0, spit #tell it that the address of the string is in $a0
		syscall #go do it
 		move $a0,$t0 #move the value stored $t0 to $a0
   		li $v0,1     #tell it we're about to print an integer
    		syscall      #go do it
     		li $v0, 10 #terminate the program
		syscall #go do it
   	.data	
prompt: 	
	.asciiz 		"\nPlease input an integer.\n" #this is going to be our prompt
spit:
	.asciiz			"\nYour integer is: " #We will now need to append the integer to this.
 		#get rid of this weak shit 
		#li $a0, $v0 #print the integer stored in $v0, but it needs to print it from $a0???
		#syscall #go do it
 		#move $t0, $v0 #moving the stored integer from $v0 to $t0 so that we can free up the space for the termination code 10
		#syscall #go do it
		#in this case, the syscall is unnecessary as the system will not recognize the code that's currently being stored in $v0; and since we are not doing anything to the integer we are storing, it doesn't actually need to be syscalled (though if we did want to do something to it, we'd need to)
 		#li $v0, 4 #tell the system we are going to load a string
		#la $a0, spit #tell it that the address of the string is in $a0
		#li $t0, 1 #tell it to print the integer stored in $t0
		#syscall #go do it
 		#move $a0, $t0 #move the integer to where it can be output from
		#la $a0, 1 #print the integer theoretically on the same line as the 'spit' message
		#lw $a0, int #tell it to convert an integer to a word? 
		#syscall #go do it
 		#code copied from Quora: https://www.quora.com/How-do-you-print-integers-in-MIPS
		#li $v0,1     #tell it we're about to print an integer
      		#li $v0, 4 #tell the system we are going to load a string
		#la $a0, spit #tell it that the address of the string is in $a0
		#li $t0, 1 #tell it to print the integer stored in $t0
		#syscall #go do it
 		#li $a0, #tell the code to print the integer
		#syscall # go do it
 		li $v0, 10 #terminate the program
		syscall #go do it
   	.data	
prompt: 	
	.asciiz 		"\nPlease input an integer.\n" #this is going to be our prompt
spit:
	.asciiz			"\nYour integer is: " #We will now need to append the integer to this.

Comments