简体   繁体   中英

Negative numbers in ARM assembly

I'm currently struggling with how to use negative numbers in ARM assembly. Let's say I have a simple code like this:

MOV R0, #0
SUB R0, R0, #1
SWI 4

R0 will obviously store the value 0xFFFFFFFF , but SWI doesn't seem to treat it as a signed integer and so the number that gets displayed is 4294967295. How can I print out -1?

As I understand it, SWI 4 invokes some number displaying routine in the OS or whatever execution environment there is. If there's an appropriate SWI some other number for displaying signed integers, use that. You should really mention your OS.

If there's no signed counterpart to SWI 4 , compute the absolute value of the negative number (eg subtract it from 0) and then display separately the minus sign and the absolute value. Negative values have the most significant bit set to 1.

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