From 2209ed6b84ad1b762adcfdde1fd9081ff626a932 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Fri, 14 Feb 2020 16:56:06 +0000 Subject: [PATCH] Add extra credit input --- prj1.asm | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/prj1.asm b/prj1.asm index 6b53bbd..a6b41db 100644 --- a/prj1.asm +++ b/prj1.asm @@ -7,23 +7,33 @@ # The label 'main' represents the starting point main: + # print user input + li $v0, 4 + la $a0, enter_num + syscall + + # get input from user and set argument + li $v0, 5 + syscall + move $a1, $v0 + la $a0, arr # $a0 based address of array - li $a1, 1 # $a1 number to be found (checked) - change the value (7) to test + #li $a1, 1 # $a1 number to be found (checked) - change the value (7) to test li $a2, 6 # $a2 max array index to be checked - change the value (3) to test li $s0, 0 # set counter to 0 jal lookup # hop to lookup function + + # print newline + #li $v0, 4 + #la $a0, newline + #syscall + # print out result li $v0, 1 # print_int syscall code = 1 move $a0, $s0 # load integer into $ao syscall j exit # exit out of program -# lookup (int arr[], int num, int cnt). -# arr[] = 5 2 1 4 6 3 -# 1. lookup (arr, 5, 3) -> 0 (the index of ‘5’ in the array) -# 2. lookup (arr, 1, 3) -> 2 (the index of ‘1’ in the array) -# 3. lookup (arr, 7, 6) -> -1 (‘7’ is not found in the array) -# 4. lookup (arr, 4, 3) -> -1 (the last parameter indicates to check only first 3 values in the lookup: addi $t0, $a2, 1 # store one higher value @@ -57,7 +67,7 @@ exit: # .data assembler directive .data arr: .word 5, 2, 1, 4, 6, 3 # change array to test -#arr: .word 5, 2, 1, 4, 6, 3 # change array to test +enter_num: .asciiz "Enter number to be found: " +newline: .asciiz "\n" str_found: .asciiz "found" str_not_found: .asciiz "not_found" -nl: .asciiz "\n"