1	#####################################################################
     2	#	Title:   CSCI 221 - Print the Integers from 0 to N
     3	#	Author:  Bary W Pollack
     4	#	File:    Nums.asm
     5	#	Date:    Jan. 13, 2002 - 23:00
     6	#####################################################################
     7	#	Register - Variable Cross Reference
     8	#		v0: N
     9	#		v1: Counter:  counts from N down to 0
    10	#		t1: number to be displayed, ranges from 0..N
    11	#####################################################################

    12		.data

    13	titl:	.ascii	"\n  **** Print Integers Program ****\n\n"
    14		.ascii	"  Author: Bary W Pollack\n"
    15		.ascii	"  File:   nums.asm\n"
    16		.asciiz	"  Date:   Jan. 13, 2002\n"
    17	prmt:	.asciiz	"\n\n  Print the integers up to N = "
    18	bye:	.asciiz	"\n  **** Fin ****\n"
    19	sp2:	.ascii	" "
    20	sp:	.asciiz	" "

    21	#####################################################################

    22		.globl	main

    23		.text
    24	main:
    25		li	$v0, 4 		# code for Print String
    26		la	$a0, titl		# load address of titl into $a0
    27		syscall			# print the title message

    28	lup:
    29		li	$v0, 4            # code for Print String
    30		la	$a0, prmt         # load address of prmt into $a0
    31		syscall                 # print the prompt message

    32		li	$v0, 5		# code for Read Integer
    33		syscall			# reads the value of N into $v0
    34		move	$v1, $v0		# copy N into $v1
    35		addi	$v1, 1		# increment N by one

    36		blez	$v0, end		# branch to end if $v0 < = 0
    37		li	$t1, 0		# clear register $t1

    38		li	$v0, 4		# code for Print String
    39		la	$a0, sp2		# load address of sp2 into $a0
    40		syscall

    41	loop:
    42		move	$a0, $t1		# copy N to $a0
    43		li	$v0, 1		# code for Print Integer
    44		syscall			# print integer

    45		li	$v0, 4		# code for Print String
    46		la	$a0, sp		# load address of sp into $a0
    47		syscall			# print space

    48		addi	$t1, $t1, 1		# increment number to be displayed by one
    49		addi	$v1, $v1, -1	# decrement Counter by one
    50		bnez	$v1, loop		# branch to loop if $v1 is != 0
    51		b 	lup			# branch to lup

    52	end:
    53		li	$v0, 4		# code for Print String
    54		la	$a0, bye		# load address of "bye" message into $a0
    55		syscall			# print the string

    56		li	$v0, 10		# terminate program and
    57		syscall			# return control to the system

    58		.end

    59	#####################################################################