Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
768 B
1
Indexable
Never
countNumbers :
	addi $sp, $sp, -12		#create stack	
	sw $a0, 0($sp)			#stores a0, original argument in stack
	sw $a1, 4($sp)		        #stores $ra in stack 	
	sw $ra, 8($sp)			#stores a1, original argument in stack
	addi $v0, $zero, 0		#set return value to 0
	addi $t0, $zero, 0		#t0 stores i = 0
	loop:
		bge $t0, $a1, endloop	# i >= cnt --> end for loop
		sll $t1, $t0, 2		#shifts i
		add $t1, $t1, $a0       #t1 stores input[i]
		lw $a3, 0($t1)		#load value of input[i] into a3, so a3 is num in increaseCnt()
		jal increaseCnt		#calls increaseCnt 
		add $t0, $t0, 1 	# i++;
		j loop
	endloop:
		lw $a0, 0($sp)			#restorting old address in stack after you call function
		lw $a1, 4($sp)			
		lw $ra, 8($sp)
		addi $sp $sp, 12		#pop stack
	
	jr $ra