0% found this document useful (0 votes)
8 views2 pages

T3 New

This document is an assignment for AST10201 Computer Organization, due on October 6, 2023. It includes tasks for binary and hexadecimal addition, as well as completing a MIPS assembly program to calculate the sum of an array of integers. The assignment provides instructions for filling in missing code to achieve the desired functionality and print the result.

Uploaded by

xymc8k9kqj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

T3 New

This document is an assignment for AST10201 Computer Organization, due on October 6, 2023. It includes tasks for binary and hexadecimal addition, as well as completing a MIPS assembly program to calculate the sum of an array of integers. The assignment provides instructions for filling in missing code to achieve the desired functionality and print the result.

Uploaded by

xymc8k9kqj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

AST10201 Computer Organization – Assignment 2

(Due 6 Oct, 23:30)


Name: Talha Student ID: H10007867

1. Perform binary addition.

(a) (b)

101 1110 110 110 110

+ 1101 1111 100 100 101


0100111101
+ 1 111 111 111
011011011010

2. Perform hexadecimal addition.

(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

loop: lw $t3, 0($t0)


Load the current element from the array into $t3

# FILL IN THE CODE: Add the current element to the sum in $t2

addi $t0, $t0, 4 # Move to the next element in the array


addi $t1, $t1, -1 # Decrement the loop counter
bgtz $t1, loop # Continue the loop if there are more elements

# Print the result


li $v0, 4
la $a0, result
syscall

Print the sum stored in $t2


li $v0, 1
move $a0, $t2
syscall

# Exit the program


li $v0, 10
syscall

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy