occs-compilers-2014-spring / discussion

A place for discussion
0 stars 0 forks source link

Fully implementing 64-bit ints. #11

Open dan-f opened 10 years ago

dan-f commented 10 years ago

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 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.

Dan