In: Computer Science
Code:-----
.text
.globl __start
__start: la $s0, array # set $s0 to point array[0]
li $s1, 0 # $s1 = 0 (for counting the array elements)
loop1: li $v0, 4
la $a0, prompt
syscall # Print the prompt
li $v0, 5
syscall # Read an integer in $v0
lw $t0, endmark
beq $v0, $t0, exit # if $v0 = endmark then exit loop
sw $v0, 0($s0) # store $v0 into the current element
addi $s0, $s0, 4 # move to the next element
addi $s1, $s1, 1 # increment the counter
b loop1
exit: li $v0, 4
la $a0, res
syscall
add $a0, $0, $s1
li $v0, 1
syscall # Print the number of elements entered
li $v0, 4
la $a0, el
syscall
la $s0, array # set $s0 to point to array[0]
loop2: lw $a0, 0($s0) # $a0 = current element
li $v0, 1
syscall # Print $a0
li $v0, 4
la $a0, nl
syscall
add $s0, $s0, 4 # move to the next element
addi $s1, $s1, -1 # decrement element counter
bne $s1, $0, loop2
li $v0, 4
la $a0, bye # Print the end message
syscall
li $v0, 5
syscall # wait for Enter
li $v0, 10
syscall # end of program
.data
array: .word 0,0,0,0,0,0,0,0,0,0
prompt: .asciiz "Enter an integer (-999 for exit): "
endmark: .word -999
res: .asciiz "You have entered "
el: .asciiz " numbers:\n"
bye: .asciiz "Press enter to exit..."
nl: .asciiz "\n"
# array: .word 0,0,0,0,0,0,0,0,0,0