How is 64-bit math performed on a 32-bit machine?

If a 32-bit processor really has a length of only 32 bits, then how can mathematical operations work on 64-bit numbers? For example:

long lngTemp1 = 123456789123; long lngTemp2 = lngTemp1 * 123; 

According to MSDN, the longest in C # is a signed 64-bit number: http://msdn.microsoft.com/en-us/library/ctetwysk(VS.71).aspx

How is it that the 32-bit Intel microprocessor can execute code, as above, without overflow?

+6
long-integer c # types overflow
source share
3 answers

They use the carry bit to add and subtract. Assembler operations for "add with hyphenation" and "subtract with hyphenation" (or "borrow") can be used to add and subtract with the addition and subtraction of an arbitrary bit length.

For multiplication, if you only have a 32-bit multiplication result, you can split it into 16-bit value pairs and multiply, then shift and add (with a carry) to get the full 64-bit result from the 32-bit multiply. In principle, using a long version (any two 16-bit multiplications corresponding to a 32-bit result) can be used to generate arbitrary bit length multiplications using more limited precision.

FWIW, Intel's 32-bit ASM "mul" command can put a 64-bit result in EDX: EAX so that you can actually multiply in 32-bit fragments (with the addition of 64-bit values) rather than 16- (with 32- bit values ​​for offset and add).

+3
source share

The x86 32-bit instruction set can be used for 64-bit arithmetic, see Advanced Precision Multiplication .

0
source share

Even 32-bit processors often came with a 64-bit floating point unit, but the data could only be connected 32-bit at a time.

In general, however, a 64-bit floating point can be performed even if the core processor allows only 8-bit integer operations. However, the compiler or programmer will need to insert enough code to virtualize the effect.

0
source share

All Articles