When and why do we sign extend and use cdq with mul/div?
I had a test todayand the only question I didn't understand involved converting a doubleword to a quad word. That got me thinking, why/when do we sign extend for multiplication or division? In addition, when do we use instructions like cdq? Use cdq / idiv for signed 32-bit / 32-bit => 32 bit division, xor edx,edx / div for unsigned. If you zero EDX/RDX instead of sign-extending into EDX:EAX before idiv , you can get a large positive result for -5 / 2, for example . Using the "full power" of 64 / 32-bit => 32-bit division is possible, but not safe unless you know the divisor is large enough so