Завершение программы на языке ассемблера SPIM loop2.s.
Программа рассчитает сумму элементов в «числах»
чье значение меньше или равно 1000.
Я пытался запрограммировать код, однако вывод идет, в то время как мне нужно, чтобы он был 11
Название программы: loop2.s
t0 - указывает на элементы массива по очереди
t1 - содержит количество элементов
t2 - содержит сумму
t3 - каждое слово из массива "цифр" по очереди
#################################################
# #
# text segment #
# #
#################################################
.text
.globl __start
__start: # execution starts here
# Put your answer between dashed lines.
#
#------------------Your code starts next line---------------
la $t0, numbers
lw $t1, count
li $t2, 0
process:
lw $t3, ($t0) # load word from the array
add $t2, $t2, $t3 # add it to sum
add $t0, $t0, 4 # increment the pointer / get the next element of the array
sub $t1, $t1, 1 # decrement the counter
beqz $t1, done # if counter = 0, then it's done
j process
done:
la $a0, ans1
li $v0, 4
syscall
move $a0, $t2
li $v0, 1
syscall
la $a0, endl
li $v0, 4
syscall
li $v0, 10
syscall
#-----------------Your code ends above this line----------------
la $a0,endl # syscall to print out
li $v0,4 # a new line
syscall
li $v0,10 # Exit
syscall # Bye!
#################################################
# #
# data segment #
# #
#################################################
.data
numbers:
.word 3,2000,2,6,3000
count: .word 5
ans1: .asciiz "sum = "
endl: .asciiz "\n"
##
## end of file loop2.s