Ritual III: Change the Case
Read until nothing.
Only the small letters change.
The path stays the same.
Write an RV64 function named uppercase. It receives a pointer to a null-terminated ASCII string in a0 and converts each lowercase letter to uppercase in place.
Leave every other byte unchanged. Return the original pointer in a0.
Reveal solution
.globl uppercase
uppercase:
mv t0, a0
.Lcase_loop:
lbu t1, 0(t0)
beqz t1, .Lcase_done
li t2, 97
bltu t1, t2, .Lcase_next
li t2, 123
bgeu t1, t2, .Lcase_next
addi t1, t1, -32
sb t1, 0(t0)
.Lcase_next:
addi t0, t0, 1
j .Lcase_loop
.Lcase_done:
ret
The half-open range [97, 123) selects lowercase ASCII. Subtracting 32 produces the corresponding uppercase byte. Because only t0 advances, a0 still holds the original address.