# Test for clz .org 0 # Provide program starting address to linker .global _start .extern clz .extern tohex /* newlib system calls */ .set SYSEXIT, 93 .set SYSWRITE, 64 .section .rodata inputs: .word 0 .word 1 .word 2 .word 3 .word 0xF .word 0xFF .word 0xFFF .word 0xFFFF .word 0xFFFFF .word 0xFFFFFF .word 0xFFFFFFF .word 0xFFFFFFFF .word 0x80000000 .word 0x00008000 inputs_end: .section .bss buf: .skip 9 .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) # input value jal clz 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