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

后端 未结 3 550
轻奢々
轻奢々 2020-12-19 04:53

If a 32-bit processor is, indeed, really only 32 bits in length, then how can math operations work on 64-bit numbers? For example:

long lngTemp1 = 1234567891         


        
相关标签:
3条回答
  • 2020-12-19 05:11

    32 bit instruction set of x86 can be used for 64 bit arithmetic, see Extended Precision Multiplication.

    0 讨论(0)
  • 2020-12-19 05:15

    They use the carry bit for add and subtract. The assembler ops for "add with carry" and "subtract with carry" (or "borrow") can be used for arbitrary bit length extended precision addition and subtraction.

    For multiply, if you only have a 32-bit result from multiply, you can break it into 16-bit value pairs and multiply and then shift and add (with carry) to get a full 64-bit result from 32-bit multiply. Basically, doing the long-hand version (any two 16-bit multiplies fit in a 32-bit result) can be used to generate arbitrary bit-length multiplies using a more limited precision.

    FWIW, the Intel 32-bit asm "mul" instruction can put a 64-bit result in EDX:EAX so you can actually do multiplies in 32-bit chunks (with 64-bit values to add) rather than 16-bit chunks (with 32-bit values to shift and add).

    0 讨论(0)
  • 2020-12-19 05:27

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

    More generally, however, 64-bit floating point could be accomplished even if the underlying processor only allows 8-bit integer operations. However, the compiler or programmer would have to insert sufficient code in order to virtualize the effect.

    0 讨论(0)
提交回复
热议问题