Texts: My code loops, but it is printing zero at the end, not the sum. Please help!
Program Spec:
The Program Spec
Write a program to compute the value of the sum 1*2 + 2*3 + … + 20*21. Use the designated register to fetch the 32-bit product result. Print the final result.
Here are some tips and REQUIREMENTS:
1. The first thing your program needs to do is to print out your family (last name) and your student ID. Create strings and use the print_string syscall to display this information to the MARS Run I/O window.
2. Use $t1 to hold the result sum.
3. Print the result to the Run I/O window.
--------------------------------------------------------------------------------------------
.data
last_name: .asciiz "Bird"
student_id: .asciiz "123456789"
.text
main:
# Print last name and student ID
la $a0, last_name
li $v0, 4
syscall
la $a0, student_id
li $v0, 4
syscall
# Initialize sum
li $t1, 0
# Loop from 1 to 20
li $t0, 1
loop:
# Multiply current number by next number
mul $t1, $t1, $t0
# Increment current number
addi $t0, $t0, 1
# Check if we have reached the end of the loop
blt $t0, 21, loop
# Print the sum
li $v0, 1
move $a0, $t1
syscall
# Exit the program
li $v0, 10
syscall