将整数转换为其十六进制值以进行打印 [英] Convert integer to its hexidecimal value to print
问题描述
假设我将一个分配给$ a0的整数用作整数,该如何以十六进制格式打印该整数?
Say I take an integer assigned to $a0, how do I go about and print the integer in its Hexadecimal form?
推荐答案
使用syscall 34. MARS系统调用
Use syscall 34. MARS syscalls
如果您使用的模拟器没有该系统调用,或者您只想查看必要的字节,则需要手动进行.最简单的方法是迭代.获取一个10字节的字符串(8个十六进制值和前导0x).
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)按位和$ a0的常量为15.
1) Bitwise and $a0 with constant 15.
2)将结果转换为ASCII形式的等效十六进制值.查找表将是干净高效的.
2) Convert result to equivalent hex value in ASCII. A lookup table would be clean and efficient.
3)将等效的十六进制值存储在字符串的空间中.请记住一点点字节序问题.
3) Store equivalent hex value in space for string. Keep in mind little endian issues.
4)逻辑右移$ a04.
4) Logical right shift $a0 by 4.
5)转到1.
执行该操作,直到$ a0为0,并且您应该在字符串中包含十六进制值,然后可以打印该值.
Do that until $a0 is 0 and you should have the hex value in a string, which you can then print.
这篇关于将整数转换为其十六进制值以进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!