Title: CS231 Lab4
Date: 2017-02-06T00:00:00
Tags: CS231, Assembly
Authors: Henry Brooks

This asm program for the MIPS processor takes an array of numbers and returns it in reverse order.

## Henry Brooks

		.data
arry:		.word		0,0,0,0,0,0,0,0,0,0

space:  	.asciiz 	"\n"
header1:	.asciiz 	"======================================================================\n"
header2:	.asciiz 	"Program Description: \tThis program asks a user how many numbers they\n\t\t\tadd to an array, then returns the array in reverse order\n"
header3:	.asciiz 	"Author:              \tHenry Brooks\n"
header4:	.asciiz 	"Creation Date:       \t02/06/2017\n"
header5:	.asciiz 	"======================================================================\n"

nl:		.asciiz 	"\n"

query1:		.asciiz		"Enter the number of elements:\n"
query2:		.asciiz		"Enter number "
query3:		.asciiz		":\t"
badcount1:	.asciiz		"Error array can't have more than 10 elements, try again!!\n"
badcount2:	.asciiz		"Error array can't have less than 1 element\n"
return:		.asciiz		"The content of array in reverse order is:\n"

		.text
main:
################### Print header information
		li 			$v0, 4
		la 			$a0, header1
		syscall
		la 			$a0, header2
		syscall
		la 			$a0, header3
		syscall
		la 			$a0, header4
		syscall
		la 			$a0, header5
		syscall

################### Print query
		li			$v0, 4
		la			$a0, query1
		syscall

main2:
################### Take user input
		li			$v0, 5
		syscall

################### Check that input is valid
		ble			$v0, $0, badInputLo
		addi			$t0, $0, 10
		bgt			$v0, $t0, badInputHi			

################## If input is good set $s0 to $v0
		addi			$s0, $v0, 0		# lengthOfArray

################### Initialize $s1 to 0
		addi			$s1, $0, 0		# counter
		lw			$t1, arry		# pointer
		
################### Loop to collect inputs from user
################### if ( count == value) break
###################   else array[count] = input
###################        count++
###################        loop

read_loop:	beq			$s0, $s1, exit		# pointer is at end
		

		li			$v0, 4			# load print string
		la			$a0, query2		# load "enter number " message
		syscall						# print message
		
		li			$v0, 1			# load print intger
		add			$a0, $s1, $0		# load count
		addi			$a0, $a0, 1		# increment for printing
		syscall
		
		li			$v0, 4			# load print string
		la			$a0, query3		# load ":\t"
		syscall
		
		li			$v0, 5			# load user input program
		syscall						# get user input, (cin)
		
		addi			$t7, $v0, 0
		
		sw			$t7, 0($t1)
		
		li			$v0, 1
		la			$a0, 0($t1)
		syscall	
		
		addi			$s1, $s1, 1
		j 			read_loop		
		

#################### Loop to read off the elements of the array
#print_loop:
#		beq			$t2, $0, end	# check array end
#	
#		lw			$a0, ($t1)
#		li			$v0, 1
#		syscall
#	
#		li			$v0, 4
#		syscall
#	
#		addi			$t2, $t2, -1
#		addi			$t1, $t1, -4
#		j	print_loop	# ret


#################### User input for count is less than or equal to 0
badInputLo:	li			$v0, 4
		la			$a0, badcount2
		syscall
		
		j			main2

#################### User input for count is less than or equal to 0
badInputHi:	li			$v0, 4
		la			$a0, badcount1
		syscall
		
		j			main2
		
#################### exit from program
exit:		li			$v0, 4			# load print string
		la			$a0, header1
		syscall
		
		la			$a0, return		# load answer message
		syscall						# print answer message
		
		la			$a0, header1
		syscall
		
		li			$v0, 1			# load print int
		add			$a0, $s2, $0		# load sum
		syscall						# print sum