Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
906 B
2
Indexable
Never
    .data
array:  .word 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
    .text
    .globl main

main:
    # Initializing variables
    li $t0, 0       # Counter for loop
    li $t1, 0       # Sum variable
    la $t2, array   # Load address of the array into $t2

loop:
    lw $t3, 0($t2)  # Load the current element of the array
    add $t1, $t1, $t3  # Add the current element to the sum
    addi $t0, $t0, 1   # Increment loop counter
    addi $t2, $t2, 4   # Move to the next element of the array
    blt $t0, 11, loop  # Loop until we've processed all elements

    # Printing the sum
    li $v0, 1       # Load appropriate system call code into $v0
    move $a0, $t1   # Move the sum to $a0 for printing
    syscall         # Print the sum

    # Exit the program
    li $v0, 10      # Load appropriate system call code into $v0 for exit
    syscall         # Exit the program
Leave a Comment