	.data
					# Declaring Data Values
prompt:	.asciiz "\nEnter a string of numbers up to 8 characters: "
newln:	.asciiz "\n"
str:	.asciiz "ZZZZZZZZZZ"		# Creating a memory space for 
					# input

	.text
	.globl main

main:    				# Beginning of main section
	li	$v0, 4			# Load print string syscall 
					# code into v0 
	la	$a0, prompt		# Load address of string into a0
	syscall				# Perform system call to print
					# string
					# Input characters from the user
	li	$v0, 8			# Load read string syscall code 
					# into v0
	li	$a1, 10			# Load the length to be read
					# into a1
	la	$a0, str		# Load address where input is to 
					# be stored
	syscall				# Perform system call to read 10
					# characters

	li	$v0, 4			# Load print string syscall 
					# code into v0 
	la	$a0, str		# Load address of string into a0
	syscall				# Perform system call to print
					# string

	jal ascii_loop			# Branch to loop to convert ascii 
					# character
					# into integer values
					# Display final results
	li	$v0, 1			# Load print string syscall code
					# into
	syscall				# vo. perform system call to print 
					# string
        li      $v0, 10                 # exit program service 
        syscall 

ascii_loop:				# Ascii to integer loop
	li	$t4, 10			# Load 10 into temporary register
	addi	$t2, $0, 0		# t4. Init t2 to 0
	move	$t0, $a0		# move contents of a0 into t0
					# a0 is the address in memory that
					# contains the characters we 
					# read in
loop:	lb	$t1, ($t0)		# Load first byte into t1

	la      $t3,newln		# Load address of line character \n
	lb	$t3, 0($t3)		# Load contents of line character \n 
					# into t3

	beq	$t1, $t3, ascii_end	# Check if the character read is
					# the same as \n.  If so, branch
					# to the end of the loop.
	li	$t3, 48  		# Load the integer value of the
					# ASCII character 0 into register
					# t3
	blt	$t1, $t3, ascii_error	# Check if value in t1 is less 
					# then the value in t3.  If it is
					# then something is wrong, go to
					# error routine
	li	$t3, 57 		# Load the integer value of the
					# ASCII character 9 into register
					# t3
	bgt	$t1, $t3, ascii_error	# check if value in t1 is greater
					# then the value in t3.  If it is
					# then something is wrong, go to
					# error routine
	addi	$t3, $t1, -48		# Convert from ascii to integer
	mul	$t2, $t2, $t4		# Multiply to put integer in 
					# right place
	add	$t2, $t3, $t2		# Adding total together
	addi	$t0, $t0, 1		# Increment to next byte in memory
	b	loop			# Branch back to loop to work on 
					# next char
ascii_error:				# error handling routine
					# in this case if there is an error
					# we simply put a negative value
					# into register t2 and then end
					# the program
	li	$t2, -1			# Load -1 into t2
	
ascii_end:
	move	$a0, $t2		# Move final value into a0
	jr	$ra			# Return to main program to print 
					# result

