# Test for count_digits

.org 0
# Provide program starting address to linker
.global _start

.extern count_digits
.extern tohex

/* newlib system calls */
.set SYSEXIT,  93
.set SYSWRITE, 64

.section .rodata

inputs:
    .word 0, 1, 2, 3, 9, 10, 100, 999, 1000, 0x8000000, 0x80000000 # TODO: negative values
inputs_end:

.section .bss

buf: .skip 11

.text

_start:
    li a0, '\n'
    la a1, buf
    sb a0, 8(a1)        # append newline to buf

    la s0, inputs       # init loop variables
    la s1, inputs_end
loop:
    lw a0, 0(s0)
    jal count_digits
    la a1, buf
    jal tohex

    li t0, SYSWRITE     # "write" syscall
    li a0, 1            # 1 = standard output (stdout)
    la a1, buf          # load address of output string
    li a2, 9            # length of output string
    ecall               # invoke syscall to print the string

    addi s0, s0, 4      # increment input pointer to the next input
    bltu s0, s1, loop   # if the input address is less than inputs_end, loop

    li t0, SYSEXIT      # "exit" syscall
    la a0, 0            # Use 0 return code
    ecall               # invoke syscall to terminate the program