#	This program permutes the order of twenty numbers by doing
#	five reversals of portions of the array numbers.  It prompts
#	five times for how many numbers, n,  are to be reversed then 
#	calls a procedure to do the reversal of the first n numbers.
#	After each reversal, the twenty numbers are displayed.

	.text
	.globl	main
main:
	addi	$sp, $sp, -8		# Save std registers
	sw	$fp, 4($sp)
	sw	$ra, 0($sp)
	addi	$fp, $sp, 4

	li	$s0, 5			# Loop counter
outer:
	li	$v0, 4			# Prompt for count of numbers
	la	$a0, prompt
	syscall
	li	$v0, 5			# Get count
	syscall
	sw	$v0, count		# Save it
				# Set up and call function
	
	
	li	$t0, 20			# Set loop counter
	la	$t1, values		# Start at beginning of array
again:
	lw	$a0, 0($t1)		# Display a value
	li	$v0, 1
	syscall
	li	$v0, 4			# Make a space
	la	$a0, blank
	syscall
	addi	$t1, $t1, 4		# Move to next number
	addi	$t0, $t0, -1		# Decrement counter
	bnez	$t0, again		# Do it again if not done
	li	$v0, 4			# Go to next line
	la	$a0, newline
	syscall
	addi	$s0, $s0, -1		# Decrement outer loop counter
	bnez	$s0, outer		# Ask again if not done
	lw	$fp, 4($sp)		# Restore registers
	lw	$ra, 0($sp)
	addi	$sp, $sp, 8
	jr	$ra

	.data
	.align	2
count:		.word		0
values:		.word		1, 2, 3, 4, 5, 6, 7, 8, 9, 10
		.word		11, 12, 13, 14, 15, 16, 17, 18, 19, 20
prompt:		.asciiz		"Use how many numbers? "
blank:		.asciiz		" "
newline:	.asciiz		"\n"


	
