Reputation: 197
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?
Upvotes: 2
Views: 3098
Reputation: 365277
Hex is a text serialization format for binary integers. The value in $v0
is a 32-bit binary number, not hex or decimal.
e.g. 32
(decimal) and 0x20
(hex) are two ways to describe the value of the same bit pattern (0b0000...00100000
). All of these are different ways to express the ASCII code for a space, like you'd get from 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. (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)
move $a0, $v0 # $a0 = integer to print
li $v0, 1 # $v0 = system-call number
syscall # print_integer($a0) in decimal
Upvotes: 2