[英]How to get the decimal number from ASCII code in MIPS?
I want to read a character and I'm using bascially this code:我想读一个字符,我基本使用这个代码:
main:
li $v0, 12
syscall
li $v0, 10
syscall
So, the ASCII code is saved in $v0 as a HEX number, but is there some way to get this correspondent ASCII code in decimal?所以,ASCII 码作为十六进制数保存在 $v0 中,但是有什么方法可以得到这个对应的十进制 ASCII 码?
Hex is a text serialization format for binary integers. Hex 是二进制整数的文本序列化格式。 The value in $v0
is a 32-bit binary number, not hex or decimal. $v0
的值是一个 32 位二进制数,而不是十六进制或十进制。
eg 32
(decimal) and 0x20
(hex) are two ways to describe the value of the same bit pattern ( 0b0000...00100000
).例如32
(十进制)和0x20
(十六进制)是描述相同位模式( 0b0000...00100000
)值的两种方式。 All of these are different ways to express the ASCII code for a space, like you'd get from li $v0, ' '
.所有这些都是表达空格的 ASCII 代码的不同方式,就像你从li $v0, ' '
。
You can view it as hex or as decimal using your debugger, or using different MARS print-number system calls if you're running your MIPS code on the MARS emulator.如果您在 MARS 模拟器上运行 MIPS 代码,您可以使用调试器将其查看为十六进制或十进制,或者使用不同的 MARS 打印编号系统调用。 (SPIM only has a print integer
system call, but MARS has ones for print in hex, print in decimal, and print in binary. http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html ) (SPIM只有一个print integer
的系统调用,但火星有那些在十六进制打印,打印在十进制和二进制打印。 http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html )
move $a0, $v0 # $a0 = integer to print
li $v0, 1 # $v0 = system-call number
syscall # print_integer($a0) in decimal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.