IA-32装配中的变量初始化

时间:2021-12-11 03:14:45

I have a question about variable initialization in MASM's assembly.

我对MASM程序集中的变量初始化有疑问。

How can I initialize 2^32 to a variable and to what kind of variable should I initialize? DWORD or REAL4?

如何将2 ^ 32初始化为变量以及应该初始化哪种变量? DWORD还是REAL4?

I try to do it like:

我尝试这样做:

val DWORD 2.0E+32

When I assign var to a register(e.g. mov eax,val) and try to write the value, I see something that is not 2^32. I also tried it with REAL4 type. Result is still same.

当我将var分配给寄存器(例如mov eax,val)并尝试写入值时,我看到的东西不是2 ^ 32。我也试过REAL4类型。结果仍然相同。

So What I am doing wrong here?

那我在这里做错了什么?

Thanks in advance...

提前致谢...

2 个解决方案

#1


3  

2^32 = 4294967296 = 0x100000000 (that's 8 zeroes).

2 ^ 32 = 4294967296 = 0x100000000(即8个零)。

2.0E+32 is 2 * 10^32 = 200000000000000000000000000000000, a completely different number. It's also a floating-point number, whereas 0x100000000 is an integer.

2.0E + 32是2 * 10 ^ 32 = 200000000000000000000000000000000,一个完全不同的数字。它也是一个浮点数,而0x100000000是一个整数。

#2


2  

2^32 is one bit bigger number than what dword supports, let me throw in some ranges:

2 ^ 32比dword支持的数字大一点,让我投入一些范围:

0 <= dword < 2^32
0 <= qword < 2^64
-2^31 <= sdword < 2^31
-2^63 <= sqword < 2^63

if REAL4 is a 4-byte floating point then it has a completely different structure than what integer has. If you use x86 then the format floating points are represented in is probably the IEEE 754. That supports 2^32 -number but you may run into precision problems.

如果REAL4是一个4字节的浮点数,那么它的结构与整数具有完全不同的结构。如果您使用x86,则表示格式浮点可能是IEEE 754.它支持2 ^ 32 - 数字,但您可能会遇到精度问题。

#1


3  

2^32 = 4294967296 = 0x100000000 (that's 8 zeroes).

2 ^ 32 = 4294967296 = 0x100000000(即8个零)。

2.0E+32 is 2 * 10^32 = 200000000000000000000000000000000, a completely different number. It's also a floating-point number, whereas 0x100000000 is an integer.

2.0E + 32是2 * 10 ^ 32 = 200000000000000000000000000000000,一个完全不同的数字。它也是一个浮点数,而0x100000000是一个整数。

#2


2  

2^32 is one bit bigger number than what dword supports, let me throw in some ranges:

2 ^ 32比dword支持的数字大一点,让我投入一些范围:

0 <= dword < 2^32
0 <= qword < 2^64
-2^31 <= sdword < 2^31
-2^63 <= sqword < 2^63

if REAL4 is a 4-byte floating point then it has a completely different structure than what integer has. If you use x86 then the format floating points are represented in is probably the IEEE 754. That supports 2^32 -number but you may run into precision problems.

如果REAL4是一个4字节的浮点数,那么它的结构与整数具有完全不同的结构。如果您使用x86,则表示格式浮点可能是IEEE 754.它支持2 ^ 32 - 数字,但您可能会遇到精度问题。