如何计算在装配一个负数 [英] How to calculate a negative number in assembly

查看:117
本文介绍了如何计算在装配一个负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在组装一个新手,我有一个关于如何重新present负数的问题
我有三个变量DWORDS,让说:

I'm a newbie in assembly and I have a question about how to represent negative numbers I have three DWORDS variable, let say:

result DWORD 0
i DWORD 3
j DWORD 5

和我想要计算公式为:结果= I - J + 8
但是,当我做I-J,其结果将是,因为符号的一个非常高的数字
所以我怎么做的结果到底好不好?

and I want to calculate this formula: result = i - j + 8 but, when i do the i-j, the result will be a very high number because of the sign so how do I make the result ok in the end?

推荐答案

有关32位DWORD整数范围是从-2147483648到2147483647或十六进制-0x80000000为0x7FFFFFFF。

For 32 bit DWORD the integer range is from –2147483648 to 2147483647 or in hex -0x80000000 to 0x7FFFFFFF.

所以数-1就像0xFFFFFFFF的present。 (像计数器下溢)

So the number -1 is present like 0xFFFFFFFF. (Like counter underflow)

如果设置为高(31)位则数是负的。为了使由负(反)正数,你必须做出一些compement加1。

If the high (31) bit is set then the number is negative. To make positive number from negative (negation) you must make compement of number and add 1.

示例:

    0xFFFFFFFE   //-2
xor 0xFFFFFFFF   //binary complement 
---------------
    0x00000001   //result of complement
+   0x00000001   //add 1
---------------
    0x00000002   //Result of negation is 2

这篇关于如何计算在装配一个负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆