T3 New
T3 New
(a) (b)
(a) (b)
face C0ffee
+ b00c + f00d
1AADA C1EFFB
3. In this exercise, you will complete a MIPS assembly language program that calculates the sum of elements
in an array.
Problem Statement:
Given an array of integers, your task is to fill in the missing parts of the provided MIPS assembly
code to calculate the sum of all elements in the array.
Instructions:
Complete the MIPS assembly code by filling in the missing slots denoted by # FILL IN THE CODE.
The array numbers contains 5 integers: 10, 20, 30, 40, and 50.
The program should calculate the sum of all elements in the array and store the result in register
$t2.
After completing the code, the program should print the calculated sum using the appropriate
system call.
.data
numbers: .word 10, 20, 30, 40, 50
size: .word 5
result: .asciiz "The sum of the array elements is: "
.text
.globl main
main:
la $t0, numbers # Load the base address of the array into $t0
lw $t1, size # Load the size of the array into $t1
li $t2, 0 # Initialize the sum to 0
# FILL IN THE CODE: Add the current element to the sum in $t2
Hint:
After filling in the missing code slots, the program will:
1. Load the base address of the array and its size into registers $t0 and $t1, respectively.
2. Initialize the sum to 0 in register $t2.
3. Loop through the array elements, loading each element into $t3 and adding it to the sum in
$t2.
4. After the loop ends, print the result message using the appropriate system call.
5. Print the sum stored in $t2 using the system call for printing an integer.
6. Exit the program.
7. The completed program will calculate the sum of the array elements (10 + 20 + 30 + 40 + 50
= 150) and print the result.
You can try to enter the code in MARS and try to run it.