Commit 36843b7f authored by kjc015's avatar kjc015
Browse files

Exercise 4 Done

parent 0d427996
# CSCI 206 Computer Organization & Programming
# Date: 2011-09-13
# Revised: 2019-10-31 for RISC-V
#
# Copyright (c) 2011 Bucknell University
#
# Permission is hereby granted, free of charge, to any individual or
# institution obtaining a copy of this software and associated
# documentation files (the "Software"), to use, copy, modify, and
# distribute without restriction, provided that this copyright and
# permission notice is maintained, intact, in all copies and
# supporting
# documentation.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL BUCKNELL UNIVERSITY BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
# THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#
# Student name: Kyle Chrysler
#
# This program calculates the sum of the values in array A and counts
# the number of values in the array.
#
# Similarly to a C-string, the array is terminated by sentinel value
# equal to zero.
#
# The sum is stored in $s0 and the count in $s1
.data
A: .word 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 0# declare array int A[]={5,4,3,2,4,1,0};
ivar:
.word 0
sum:
.word 0
string1:
.asciz "Number of elements = "
string2:
.asciz "\nSummation = "
.globl main
.text
main: # This symbols marks the first instruction of your program
li s3, 0
la t1, ivar
sw s3, 0(t1)
li s2, 0
la t1, sum
sw s2, 0(t1)
li t2, 0
la s4, A
li t3, 0
loop:
add t2, zero, s3
slli t2, t2, 2
add t2, t2, s4
lw t1, 0(t2)
beq t1, t3, terminate
addi s3, s3, 1
add s2, s2, t1
j loop
terminate:
la a0, string1
li a7, 4
ecall
add a0, zero, s3
li a7, 1
ecall
la a0, string2
li a7,4
ecall
add a0, zero, s2
li a7, 1
ecall
li a7, 10 # system call for exit.
ecall # Exit!
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