简体   繁体   English

ARM程序集中的负数

[英]Negative numbers in ARM assembly

I'm currently struggling with how to use negative numbers in ARM assembly. 我目前正在努力在ARM汇编中使用负数。 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? R0显然将存储值0xFFFFFFFF ,但是SWI似乎没有将其视为有符号整数,因此显示的数字为4294967295。如何打印-1?

As I understand it, SWI 4 invokes some number displaying routine in the OS or whatever execution environment there is. 据我了解, SWI 4在OS或存在的任何执行环境中调用一些数字显示例程。 If there's an appropriate SWI some other number for displaying signed integers, use that. 如果有适当的SWI some other number来显示带符号的整数,请使用该数字。 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. 如果没有SWI 4的带符号的对号,请计算负数的绝对值(例如,从0减去它),然后分别显示负号和绝对值。 Negative values have the most significant bit set to 1. 负值的最高有效位设置为1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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