Professional Documents
Culture Documents
#
-----------------------------------------------------------------------------------
----------
# EXERCISE-1
# 1) Run this code and Observe the values of all registers and memory used in this
program
# 2) Modify this code to include your name in the display console (this is
mandatory).
# 3) Take screenshots of the registers, memory, Mips Assembly code and console and
paste into a
# word document for submision in Blackboard.
# EXERCISE-2
# 1) As a separate exercise, compute and print the square for each loop count and
# finally print the sum of the squares
# 2) Ensure your name appears in the output console as part of the output
# 3) Take screenshots of the registers, memory, Mips Assembly code and console and
paste into a
# word/pdf document for submision in Blackboard.
#
-----------------------------------------------------------------------------------
----------
# The example main initializes the n to arbitrary value 10 to match the example.
# ---------------------------------------------
# Data Declarations
.data
n: .word 10
sumOfSquares: .word 0
msg: .asciiz "Sum of Squares"
# ------------------------------------------
#text/code section
.text
.globl main
main:
# -----------------------------------------
#Compute sum of squares from 1 to n.
lw $t0, n #
li $t1, 1 # loop index (1 to n)
li $t2, 0 # sum
sumLoop:
mul $t3, $t1, $t1 # index^2
add $t2, $t2, $t3
add $t1, $t1, 1
ble $t1, $t0, sumLoop # Note pseudo-instruction
sw $t2, sumOfSquares
# -----------------------------------------
# Done, terminate program.
li $v0, 10 # call code for terminate
syscall # system call
.end main