I figured out today how to fully implement 64-bit integers if anyone's interested. The only "tricky" part is division. Basically you just put the 64-bit dividend into the accumulator and then issue a cqto (skipping the cltq from Bob's example), which sign extends the accumulator into rdx. When doing an idiv, the 128-bit dividend represented by rdx:rax is divided by the divisor argument.
The other thing you have to do is replace the "%d" in your format string for printf with "%lld" for a signed long long.
I've found that things like variable, array, and assignment expressions are less irritating when you don't have to choose between 32 and 64-bit instructions based on the types of the operands.
Hey everyone,
I figured out today how to fully implement 64-bit integers if anyone's interested. The only "tricky" part is division. Basically you just put the 64-bit dividend into the accumulator and then issue a
cqto
(skipping thecltq
from Bob's example), which sign extends the accumulator intordx
. When doing anidiv
, the 128-bit dividend represented byrdx:rax
is divided by the divisor argument.The other thing you have to do is replace the "%d" in your format string for printf with "%lld" for a signed long long.
I've found that things like variable, array, and assignment expressions are less irritating when you don't have to choose between 32 and 64-bit instructions based on the types of the operands.
Dan