/* * oHex: * Output 32-bit number in hexadecimal * Entry: Number in a0/x10 * Uses t0-t3 ********************************************************************************* */ oHex: mv t0,a0 # Store copy in t0 lla t1,printSpace+8 # Get end+1 address of buffer in t1 li t3,8 # Do this 8 times oHexLoop0: dec t1 # Next buffer location, working backwards mv t0,a0 # Number to t0 andi t0,t0,0xF # Bottom 4 bits sb t0,(t1) # Store in buffer srli a0,a0,4 # Move right 4 bits dec t3 bnez t3,oHexLoop0 # Print section # t1 has start of printBuffer at this point lla t0,hexTable # Get address of hexTable in t0 li t3,8 # 8 times oHexLoop1: lbu a0,(t1) # Fetch digit from buffer add t2,a0,t0 # t2 := digit + hexTable lbu a0,(t2) # Fetch ascii digit putchar a0 inc t1 # Next digit in buffer dec t3 # Loop counter bnez t3,oHexLoop1 ret hexTable: .ascii "0123456789ABCDEF" printSpace: .fill 8,1,0