```## LSU EE 4720 Computer Architecture Spring 2014
#
#  Classroom example for review of MIPS:  Convert int to hex string.
#  As covered in class 17 January 2014.

.text
###############################################################################
#
# Unsigned Integer to Hexadecimal String
#

itos:
## Register Usage
#
# CALL VALUES:
#  \$a0: Unsigned integer, to convert.
#       Initialized to null-terminated string of blanks.
#  \$a2: Length of storage.
#
# RETURN:
#       There is no return register value ..
#       .. instead write storage at \$a1 with hex representation of \$a0.
#
# NOTE: Registers \$a0-\$a4 and \$t0-\$t7 can be modified.
# NOTE: 'a' = 97, 'z' = 122,  'a' - 'A' = 32
# NOTE: '0' = 48 = 0x30

LOOP:
andi \$t0, \$a0, 0xf

slti \$t2, \$t0, 10

bne \$t2, \$0, SKIP
nop
# a-f

SKIP:
sb \$t1, -1(\$t3)

srl \$a0, \$a0, 4
bne \$a0, \$0, LOOP
nop

DONE:
jr \$ra
nop

###############################################################################
#
##  Test Code
#
#  This code calls the hex to string routine multiple times using
#  data appearing below.
#

.data
msg:
.asciiz "The value of %/s4/5d = 0x%/s4/x is %/a1/s\n"
str:
.align 4
.space 12
values:
.word 1234
.word 0x1234
.word 0xa9
.word 0x0
.word 0xf
.word 0xf00d
.word -1

.text
.globl __start
__start:
la \$s2, values
MLOOP:
lw \$a0, 0(\$s2)
la \$a1, str
lui \$t0, 0x2020
ori \$t0, \$t0, 0x2020
sw \$t0, 0(\$a1)
sw \$t0, 4(\$a1)
sw \$t0, 8(\$a1)
sb \$0, 11(\$a1)
jal itos