Commit ebe3c9df authored by kjc015's avatar kjc015
Browse files

Exercise 5 Complete

parent 0b435889
# Student name: Kyle Chrysler
#
# This program calculates the sum of the square of the first 100 values
.data
A: .space 400
ivar:
.word 0
sum:
.word 0
string1:
.asciz "squares["
string2:
.asciz "]= "
string3:
.asciz "\n"
string4:
.asciz "sum of squares from 0 to 99 = "
.globl main
.text
main:
li s3, 0
la t1, ivar
sw s3, 0(t1)
li s2, 0
la t1, sum
sw s2, 0(t1)
li t0, 100
j while1
while1:
bge s3, t0, reset
add t1, zero, s3
mul t2, s3, s3
la t4, A
slli t5, t1, 2
add t1, t5, t4
sw t2, 0(t1)
add s2, s2, t2
addi s3 , s3, 1
j while1
reset:
li s3, 0
li t1, 0
li t2, 0
li t3, 0
li t4, 0
li t5, 0
j while2
while2:
bge s3, t0, terminate
add t1, zero, s3
la a0, string1
li a7, 4
ecall
la t4, A
slli t5, t1, 2
add t1, t5, t4
lw t2, 0(t1)
add a0 zero, s3
li a7, 1
ecall
la a0, string2
li a7, 4
ecall
add a0, zero, t2
li a7, 1
ecall
la a0, string3
li a7, 4
ecall
addi s3, s3, 1
j while2
terminate:
la a0, string4
li a7, 4
ecall
add a0, s2, zero
li a7, 1
ecall
li a7, 10
ecall
ebreak
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment