Silver_Smoulder icon

[ASM] Project 1 Complete - No EC 'VSlobodovP1.asm'

Silver_Smoulder | PRO | 10/31/19 03:18:51 PM UTC | 0 ⭐ | 477 👁️ | Never ⏰ | []
text |

3.37 KB

|

None

|

0 👍

/

0 👎

#Name: VSlobodovP1.asm
 #1) Prompt user for sentinel value
 #2) Store sentinel in t0.
 #3) Begin loop. 
	#a) prompt user for integer value
	#b) store it in t3 #skip this step, as the program instructions ask us not to save the number. we can just keep it in v0 until we're done with it
	#c) If t3>0 add 1 to s0, if t2<0 add 1 to s1, if t2 = 0 add 1 to s2. 
	#d) If t3>0 add it to t1, if t3<0 add it to t2. We can combine this with 3c. 
	#e) Set t3 = 0.
	#f) go back to the start of the loop
	#g) exit the loop if sentinel is entered	
 #4) Output
	#a) Output sums 
	#b) Output counters
	#c) Comparison and ouput phases
	#	i) Compare positive and negative, if positive go to ii, else go to iii
	#	ii) compare positive and zeroes, output 
	#	iii) compare negative and zeroes, output
 #5) Terminate
 .text
.globl main
 main:
 prompt: 
	#prompt user for the sentinel value and store
	li $v0, 4
	la $a0, prompt_sentinel
	syscall 
 	li $v0, 5
	syscall #see 1
 	move $t0, $v0 #see 2
 	#initialize our values
	li $s0, 0
	li $s1, 0
	li $s2, 0
	li $t1, 0
	li $t2, 0
 loop:
	li $v0, 4
	la $a0, prompt_integer
	syscall
 	li $v0, 5
	syscall #see 3a
 	beq $v0, $t0, output #see 3g
	bgtz $v0, adds0 
	bltz $v0, adds1
	beqz $v0, adds2 #see 3c
 adds0:
	add $s0, $s0, 1 #see 3c
	add $t1, $t1, $v0 #see 3d
	li $t3, 0 #see 3e
	j loop #see 3f
 adds1:
	add $s1, $s1, 1 #see 3c
	add $t2, $t2, $v0 #see 3d
	li $t3, 0 #see 3e
	j loop #see 3f
 adds2:
	add $s2, $s2, 1 #see 3c, 3d unnecessary, snce adding 0 is superfluous
	li $t3, 0 #see 3e
	j loop #see 3f
 output:	
	li $v0, 4
	la $a0, output_sums_posi
	syscall
 	move $a0, $t1
	li $v0, 1
	syscall #see 4a
 	li $v0, 4
	la $a0, output_sums_nega
	syscall
 	move $a0, $t2
	li $v0, 1
	syscall #see 4a
 	li $v0, 4
	la $a0, output_counter_posi
	syscall
 	move $a0, $s0
	li $v0, 1
	syscall #see 4b
 	li $v0, 4
	la $a0, output_counter_nega
	syscall
 	move $a0, $s1
	li $v0, 1
	syscall #see 4b
 	li $v0, 4
	la $a0, output_counter_zero
	syscall
 	move $a0, $s2
	li $v0, 1
	syscall #see 4b
 #testing phase 4c
	bgt $s0, $s1, output_ii
	j output_iii #see 4ci
 output_ii:
	bgt $s0, $s2, output_posi
	j output_zero#see 4cii
 output_iii:
	bgt $s1, $s2, output_nega
	j output_zero #see 4ciii
 #output phase 4c
output_posi:
	li $v0, 4
	la $a0, posi_big
	syscall	
	j exit
 output_nega:
	li $v0, 4
	la $a0, nega_big
	syscall
	j exit
 output_zero:
	li $v0, 4
	la $a0, zero_big
	syscall
	j exit
 exit:
	li $v0, 4
	la $a0, terminate
	syscall
 	li $v0, 10
	syscall #see 5
 .data
prompt_sentinel:
	.asciiz "Please input the sentinel for this program: "
prompt_integer:
	.asciiz "Please input your integer: "
output_sums_posi:
	.asciiz "\nThe sum of the positive numbers is: "
output_sums_nega:
	.asciiz "\nThe sum of the negative numbers is: "
output_counter_posi:
	.asciiz "\nThe number of positive numbers entered is "
output_counter_nega:
	.asciiz ", the number of negative numbers entered is "
output_counter_zero:
	.asciiz ", and the number of zeroes entered is "
posi_big:
	.asciiz ".\nThe majority of the numbers entered were positive."
nega_big:
	.asciiz "\nThe majority of the numbers entered were negative."
zero_big:
	.asciiz "\nThe majority of the numbers entered were zeroes."
terminate:
	.asciiz "\nThe program is now closing. Have a nice day."

Comments