how does most compilers implement operations on 64 bit operands (e.g long int) in 32 bit environments ? in other words, is there a way to implement these operations in a single step or we need to access multiple memory locations to implement these operations ?
They use two registers to hold a 64-bit value. One for the lower 32-bits and one for the upper 32-bits.
For x86, 64-bit Addition/subtraction is done using add-with-carry and subtract-with-borrow instructions:
add %eax, (lower 32-bits of operand)
adc %edx, (upper 32-bits of operand)
64-bit multiplication is much more complicated, but also done using a combination of 32-bit multiplies and 32-bit add-with-carry instructions. (in a way similar to long-multiplication with 2 digits)
For loads and stores, yes, two 32-bit values need to be loaded/stored into/from two registers.
Similarly, 128-bit integers can be implemented on 64-bit hardware. GCC supports this as an extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With