开发者

Convert integer to its hexidecimal value to print

Say I take an inte开发者_运维技巧ger assigned to $a0, how do I go about and print the integer in its Hexadecimal form?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜