Convert integer to its hexidecimal value to print

天涯浪子 提交于 2020-05-08 05:57:48

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4363411/convert-integer-to-its-hexidecimal-value-to-print

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!