Commit 0d427996 authored by kjc015's avatar kjc015
Browse files

Exercise 3 Complete

parent 97e837f9
# 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
#
# data segment -------------------------------------
.data
.align 2
save:
.word 0,0,0,0,7,0,0,0,0,0 # array save[.]
ivar:
.word 0 # int i
kvar:
.word 0 # int k
donestring:
.asciz "i= "
prompt:
.asciz "Enter the value to search for: "
errorstring:
.asciz "value not found."
# code segment --------------------------------------
.text
init:
la a0, prompt
li a7, 4
ecall
li t4, 0
li t3, 10
li s3, 0 # store 0 in i
la t1, ivar
sw s3, 0(t1)
li s5, 7 # store 7 in k
la t1, kvar
sw s5, 0(t1)
la s4, save # put the address of save[0] in $s4
addi t0, zero, 7 # t0=7
li a7, 5
ecall
mv t0, a0
test:
# reserve t1 for byte offset of save array
add t1, zero, s3 # t1 = i
slli t1, t1, 2 # cnvert index to byte addres (multiply t1 by 4)
add t1, t1, s4 # t1 = &save[0] + t1 (byte address of save[i])
lw t2, 0(t1) # t2 = save[i]
addi t4, t4, 1
beq t4, t3, error
beq t2, t0, terminate
addi s3, s3, 1
j test
terminate:
la a0, donestring
li a7, 4
ecall
add a0, zero, s3 # print value of i
li a7, 1
ecall
li a7, 10 # terminate program
ecall
error:
la a0, errorstring
li a7, 4
ecall
li a7, 10
ecall
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