jeudi 3 janvier 2019

finding sum of random numbers in a loop mips

I Created a random numbers generator which generate 8 numbers I am trying to add these numbers up and that's what I did : .data dice : .asciiz " -8 dice are thrown and they fall randomly face up as follows: : "

output : .asciiz " the sum of these numbers : "

.text
li $v0,4        #print out the string 

la $a0,dice #pass the address of the variable to $a0 syscall #Pass Control to OS

addi $t1,$zero,0 addi $t2,$zero,8 loop :

beq $t1,$t2,EXIT add $t1,$t1,1

li $v0, 42 # 42 is system call code to generate random int li $a1, 8 # $a1 is where you set the upper bound syscall

add $a0, $a0, 1 # your generated number will be at $a0

li $v0, 1 syscall

j loop      


EXIT:

add $t5,$a0,$a0

li $v0,4 #print out the integer that user entered la $a0,output #pass the address of the variable to $a0 syscall li $v0,1 #print out the integer(result) add $a0,$zero,$t5 #Move computed value into $a0 with putting ASCII value as well syscall

so its supposed to sum the all 8 numbers but it sums only the last digit with it self. any Ideas how I can add these numbers.




Aucun commentaire:

Enregistrer un commentaire