Hey, I've been working on this code for a little over a week. I admit, I just can't understand assembly. It feels like bashing my face against broken glass. And it's due tomorrow night now.
Anyway. This needs to take the input of up to 20 integers from a person. Then it will get the sum of those integers.
The user can specify if they want to put in, 5, 8, 10, any number of integers, as long as it's less than 20.
My issue? I have some code, but it just keeps asking for more integers. I tried putting in a variable for a counter, but now it just freaks out and demands why there are actual legible words in my code.
Any help would be great, code's here. v
.data
Prompt1: .asciiz "\n How many integers (20 or less) will you input? " #gets number of integers
Prompt2: .asciiz "\n Enter the integers (one per line): " #Elements of array A entered from keyboard
A: .space 80 #Array A can store 20 integers (each 4 bytes)
Output: .asciiz "\n The sum of the values entered is: "
counter: .space 8
.text
main:
howMany:
li $v0, 4 #system call code for print string
la $a0, Prompt1 #load address of prompt1 into $a0
syscall #print the prompt1 message
li $v0, 5 #system call code for read integer
syscall #reads the value of N into $v0
move counter, $v0 #moves value to counter variable to free up $v0
bge counter, 20, howMany #makes sure it's less than 20 integers, or re-prompts
getNumbers:
li $v0, 4 #system call code for print string
la $a0, Prompt2 #load address of prompt2 into $a0
syscall #print the prompt2 message
li $v0, 5 #system call code for read integer
syscall #reads 1st array value into $v0
move $t1, $v0 #moves first array value to $t1 from $v0
sw $t1, A #stores value in first array in base address
la $s1, A
li counter, 1 #initializes counter to one
addi counter, counter, 1 #should add one to the counter
ble $t0, counter, getNumbers
li $v0, 4
la $a0, Output
syscall