简体   繁体   中英

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?

Hex is a text serialization format for binary integers. The value in $v0 is a 32-bit binary number, not hex or decimal.

eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM