Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Basically I\'ve created this to let the user input 4 integers and then showing t

ID: 3628866 • Letter: B

Question

Basically I've created this to let the user input 4 integers and then showing the results that was inputted. Most of it are done, but im having trouble to ouput the sum of the 4 integers inputted..HELP!!

# initialize integer array from user input
# display integer array
###################################################

.data # store string in data segment

inp: .asciiz "Please input integer: "
str: .asciiz "The result is "
array1: .word 0 0 0 0 #declare storage to hold array of integers
space: .asciiz " "

########################################################################

.text
.globl main

main:
la $t0, array1 # load address of array into register $t0
move $t3, $t0 # copy address of the array

li $t1, 4
li $t2, 0

loop_input:
beq $t2, $t1, out_put

li $v0,4 # system call to print_inp
la $a0,inp
syscall

li $v0,5 # system call code for read_int
syscall # read a integer from the console

sw $v0, 0($t3) # save number into current array slot

addi $t3, $t3, 4
addi $t2, $t2, 1 # increase index by 1

j loop_input

out_put:
li $v0,4 # system call to print_string
la $a0,str
syscall

li $t1, 4
li $t2, 0

loop_output:
beq $t2, $t1, exit

lw $t4,0($t0)

li $v0,1 # system call to print_int
move $a0,$t4
syscall

li $v0,4 # system call to print_space
la $a0,space
syscall

addi $t0, $t0, 4
addi $t2, $t2, 1

j loop_output

exit:
li$v0, 10
syscall

#########################################################################

Explanation / Answer

please rate - thanks

you did the hard part

# initialize integer array from user input
# display integer array
###################################################

.data # store string in data segment

inp: .asciiz "Please input integer: "
str: .asciiz "The result is   "
equal: .asciiz " = "
array1: .word 0 0 0 0 #declare storage to hold array of integers
space: .asciiz " "

########################################################################

.text
.globl main

main:
la $t0, array1 # load address of array into register $t0
move $t3, $t0 # copy address of the array

li $t1, 4
li $t2, 0

loop_input:
beq $t2, $t1, out_put

li $v0,4 # system call to print_inp
la $a0,inp
syscall

li $v0,5 # system call code for read_int
syscall # read a integer from the console

sw $v0, 0($t3) # save number into current array slot

addi $t3, $t3, 4
addi $t2, $t2, 1 # increase index by 1

j loop_input

out_put:
li $v0,4 # system call to print_string
la $a0,str
syscall

li $t1, 4
li $t2, 0
li $t3,0                         #sum=0
loop_output:
beq $t2, $t1, exit

lw $t4,0($t0)
add $t3,$t3,$t4               #sum=sum+array[$t0]
li $v0,1 # system call to print_int
move $a0,$t4
syscall

li $v0,4 # system call to print_space
la $a0,space
syscall

addi $t0, $t0, 4
addi $t2, $t2, 1

j loop_output

exit:
li $v0,4                       #output =
la $a0,equal
syscall
li $v0,1                      #output sum
move $a0,$t3
syscall
li$v0, 10
syscall

#########################################################################

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote