.global u64hex .global u32hex .global u8hex .macro hexnibble src, shift, dest slli t1, \src, 64-\shift-4 # put high nibble of s7 in t1 srli t1, t1, 64-4 addi t2, t1, 0x30 # convert to decimal digit bgt t5, t1, 0f # if digit >= 10, switch to alpha addi t2, t1, 0x61-10 0: # copy digit to writebuf sb t2, \dest .endm .macro hexbyte src, shift, dest hexnibble \src, (\shift+4), \dest hexnibble \src, \shift, 1+\dest .endm # arguments: # a0 - buffer (8, 16 bytes) # a1 - int (32, 64 bits) # # clobbers: t1, t2, t5 # leaves a0 and a1 unchanged u64hex: li t5, 10 hexbyte a1, 56, 0(a0) hexbyte a1, 48, 2(a0) hexbyte a1, 40, 4(a0) hexbyte a1, 32, 6(a0) hexbyte a1, 24, 8(a0) hexbyte a1, 16, 10(a0) hexbyte a1, 8, 12(a0) hexbyte a1, 0, 14(a0) ret u32hex: li t5, 10 hexbyte a1, 24, 0(a0) hexbyte a1, 16, 2(a0) hexbyte a1, 8, 4(a0) hexbyte a1, 0, 6(a0) ret u8hex: li t5, 10 hexbyte s7, 0, 6(a0) ret