#####################################################################
#	Title:   CSCI 221 - Print the Integers from 0 to N
#	Author:  Bary W Pollack
#	File:    Nums.asm
#	Date:    Jan. 13, 2002 - 23:00
#####################################################################
#	Register - Variable Cross Reference
#		v0: N
#		v1: Counter:  counts from N down to 0
#		t1: number to be displayed, ranges from 0..N
#####################################################################

	.data

titl:	.ascii	"\n  **** Print Integers Program ****\n\n"
	.ascii	"  Author: Bary W Pollack\n"
	.ascii	"  File:   nums.asm\n"
	.asciiz	"  Date:   Jan. 13, 2002\n"
prmt:	.asciiz	"\n\n  Print the integers up to N = "
bye:	.asciiz	"\n  **** Fin ****\n"
sp2:	.ascii	" "
sp:	.asciiz	" "

#####################################################################

	.globl	main

	.text
main:
	li	$v0, 4 		# code for Print String
	la	$a0, titl		# load address of titl into $a0
	syscall			# print the title message

lup:
	li	$v0, 4            # code for Print String
	la	$a0, prmt         # load address of prmt into $a0
	syscall                 # print the prompt message

	li	$v0, 5		# code for Read Integer
	syscall			# reads the value of N into $v0
	move	$v1, $v0		# copy N into $v1
	addi	$v1, 1		# increment N by one

	blez	$v0, end		# branch to end if $v0 < = 0
	li	$t1, 0		# clear register $t1

	li	$v0, 4		# code for Print String
	la	$a0, sp2		# load address of sp2 into $a0
	syscall

loop:
	move	$a0, $t1		# copy N to $a0
	li	$v0, 1		# code for Print Integer
	syscall			# print integer

	li	$v0, 4		# code for Print String
	la	$a0, sp		# load address of sp into $a0
	syscall			# print space

	addi	$t1, $t1, 1		# increment number to be displayed by one
	addi	$v1, $v1, -1	# decrement Counter by one
	bnez	$v1, loop		# branch to loop if $v1 is != 0
	b 	lup			# branch to lup

end:
	li	$v0, 4		# code for Print String
	la	$a0, bye		# load address of "bye" message into $a0
	syscall			# print the string

	li	$v0, 10		# terminate program and
	syscall			# return control to the system

	.end

#####################################################################
