Silver_Smoulder icon

[ASM] Addition/Subtraction/Comparison

Silver_Smoulder | PRO | 10/17/19 03:24:15 PM UTC | 0 ⭐ | 423 👁️ | Never ⏰ | []
text |

1.63 KB

|

None

|

0 👍

/

0 👎

.globl main
.text
 main:
	li $v0, 4 #output the string
	la $a0, first_int
	syscall
 	li $v0, 5 #read in the number 
	syscall 
 	move $t0, $v0 #store first integer in t0
 	li $v0, 4 #output the string
	la $a0, second_int
	syscall
 	li $v0, 5 #read in the number 
	syscall 
 	move $t1, $v0 #store second integer in t1
 	bge $t0, $t1, bigger_m
	bge $t1, $t0, bigger_n
	beq $t0, $t1, equivalence
 bigger_m:
	li $v0, 4 #output the string
	la $a0, m_big
	syscall
	j calc
 bigger_n:
	li $v0, 4 #output the string
	la $a0, n_big
	syscall
	j calc
 equivalence:
	li $v0, 4 #output the string
	la $a0, equality
	syscall
	j calc
 calc:
	add $s0, $t0, $t0 #add m+m
	sub $s1, $t0, $t1 #subtract m-n
	sub $s2, $t0, 3 #subtract m-3
	add $s3, $t1, 4 #add n+4
   #print out the line, then store the integer from the 's' registers to a0,
#then print integer, then repeat
	li $v0, 4 #iteration 1 
	la $a0, newline
	syscall
	move $a0, $s0 
	li $v0, 1 
	syscall
 	li $v0, 4 #iteration 2
	la $a0, newline
	syscall
	move $a0, $s1
	li $v0, 1 
	syscall
 	li $v0, 4 #iteration 3 
	la $a0, newline
	syscall
	move $a0, $s2
	li $v0, 1 
	syscall
 	li $v0, 4 #iteration 4 
	la $a0, newline
	syscall
	move $a0, $s3
	li $v0, 1 
	syscall
 	li $v0, 10 #end the program
	syscall	
  .data
first_int:
	.asciiz "Please enter your first integer, M: "
second_int: 
	.asciiz "Please enter your second integer, N: "
result:
	.asciiz "The sum of your integers is: "
newline:
	.asciiz "\n"
m_big:
	.asciiz "M is bigger than N"
n_big:
	.asciiz "N is bigger than M"
equality:
	.asciiz "M and N are equal"

Comments