#-------------------------------------------------------------------------------
# Tables Common Marking File
#
# Author:            Taylor Lloyd
# Date:              Jul 06, 2012
# RISC-V Conversion: Zachary Selk
# Date:              May 07, 2019
#-------------------------------------------------------------------------------
.data

inputLine:	.space 256
mainNlStr:	.asciz "\n"
oxStr:		.asciz "0x"

.text
main:

    jal createCountTable

    mainLoop:
	# Read in a line from standard input
	la	a0, inputLine
	li	a1, 256
	li	a7, 8
	ecall

	# Check its first character
	lb	t0, 0(a0)

	li	t1, 'q'
	beq	t0, t1, mainDone

	li	t1, 'r'
	beq	t0, t1, mainCheckRead

	li	t1, 'w'
	beq	t0, t1, mainCheckWrite

	li	t1, 'c'
	beq	t0, t1, mainCheckCount

	li	t1, '#'
	li	a7, 4
	ecall

	j	mainLoop

mainCheckRead:
	la	a0, inputLine
	addi	a0, a0, 1
	jal	readHex

	# Print the result
	beq	a1, zero, printValue

	# Invalid input
	li	a0, -1

printValue:
	li	a7, 1
	ecall
	la	a0, mainNlStr
	li	a7, 4
	ecall
	j	mainLoop

mainCheckWrite:
	la	a0, inputLine
	addi	a0, a0, 1
	jal	readHex

	# Print the result using student code
	jal	printHex

	la	a0, mainNlStr
	li	a7, 4
	ecall
	j	mainLoop

mainCheckCount:
	la	a0, inputLine
	addi	a0, a0, 1
	jal	readHex

	# Count the number using student code
	jal	countIntegerAccess

	# Print out the number
	li	a7, 1
	ecall

	la	a0, mainNlStr
	li	a7, 4
	ecall
	j	mainLoop

mainDone:
	li	a7, 10
	ecall

