本文介绍了处理器如何计算大于其寄存器值的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我了解到处理器具有寄存器,对于32位处理器
,它们是32位,对于64位,它们是64位。那么有人可以解释
的问题,如果我给处理器一个大于寄存器
大小的值,会发生什么?

So far I learned that a processor has registers, for 32 bit processorthey are 32 bits, for 64 bit they are 64 bits. So can someone explainwhat happens if I give to the processor a larger value than its registersize? How is the calculation performed?

推荐答案

这取决于。

假设为了便于讨论,x86仍然可以在32位体系结构上本地处理64位整数。在这种情况下,程序通常使用一对32位寄存器来保存64位值。例如,值 0xDEADBEEF2B84F00D 可能存储在 EDX:EAX 寄存器对中:

Assuming x86 for the sake of discussion, 64-bit integers can still be handled "natively" on a 32-bit architecture. In this case, the program often uses a pair of 32-bit registers to hold the 64-bit value. For example, the value 0xDEADBEEF2B84F00D might be stored in the EDX:EAX register pair:

eax = 0x2B84F00D
edx = 0xDEADBEEF

在某些情况下,CPU实际上会以这种格式期望 64位数字(。

The CPU actually expects 64-bit numbers in this format in some cases (IDIV, for example).

数学运算是通过多条指令完成的。例如,在32位x86 CPU上进行64位加法时,先对较低的DWORDs进行 add ,然后再进行的高位DWORD,其中考虑了进位标志

Math operations are done in multiple instructions. For example, a 64-bit add on a 32-bit x86 CPU is done with an add of the lower DWORDs, and then an adc of the upper DWORDs, which takes into account the carry flag from the first addition.

对于更大的整数,请使用(或 big int)库。在这里,使用动态大小的字节数组来表示整数,并带有附加信息(例如使用的位数)。 是一个受欢迎的选择。

For even bigger integers, an arbitrary-precision arithmetic (or "big int") library is used. Here, a dynamically-sized array of bytes is used to represent the integer, with additional information (like the number of bits used). GMP is a popular choice.

对大整数的数学运算迭代地完成,可能一次用本机字大小值完成。有关详细信息,建议您浏览以下这些开放源代码库之一的源代码。

Mathematical operations on big integers are done iteratively, probably in native word-size values at-a-time. For the gory details, I suggest you have a look through the source code of one of these open-source libraries.

所有这些的关键在于,数字运算是在易于管理的部分中进行的,并结合起来产生最终结果。

The key to all of this, is that numeric operations are carried out in manageable pieces, and combined to produce the final result.

这篇关于处理器如何计算大于其寄存器值的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 19:50