Convert integer to its hexidecimal value to print

后端 未结 1 1145
轮回少年
轮回少年 2021-01-07 14:42

Say I take an integer assigned to $a0, how do I go about and print the integer in its Hexadecimal form?

相关标签:
1条回答
  • 2021-01-07 15:15

    Use syscall 34. MARS syscalls

    If you are using a simulator which does not have that syscall, or you want to see only the necessary bytes, you will need to do it manually. The easiest approach would be iterative. Get a string of 10 bytes (8 hex values and leading 0x).

    1) Bitwise and $a0 with constant 15.

    2) Convert result to equivalent hex value in ASCII. A lookup table would be clean and efficient.

    3) Store equivalent hex value in space for string. Keep in mind little endian issues.

    4) Logical right shift $a0 by 4.

    5) Goto 1.

    Do that until $a0 is 0 and you should have the hex value in a string, which you can then print.

    0 讨论(0)
提交回复
热议问题