# Linux Kernel Module Cheat

#### 29.3.3. x86 CQTO and CLTQ instructions

Examples:

- userland/arch/x86_64/cqto.S CQTO

- userland/arch/x86_64/cltq.S CLTQ

Instructions without E suffix: sign extend RAX into RDX:RAX.

Instructions E suffix: sign extend withing RAX itself.

Common combo with IDIV 32-bit, which takes the input from EDX:EAX: so you need to set up EDX before calling it.

Has some Intel vs AT&T name overload hell:

- https://stackoverflow.com/questions/6555094/what-does-cltq-do-in-assembly/45386217#45386217

- https://stackoverflow.com/questions/17170388/trying-to-understand-the-assembly-instruction-cltd-on-x86/50315201#50315201

- https://sourceware.org/binutils/docs/as/i386_002dMnemonics.html

GNU GAS accepts both syntaxes, see: Table 5, “CQTO and CLTQ family Intel vs AT&T”.

Table 5. CQTO and CLTQ family Intel vs AT&T
Intel | AT&T | From
--- | --- | ---
To | CBW | CBTW
AL | AX | CWDE
CWTL | AX | EAX
CWD | CWTD | AX
DX:AX | CDQ | CLTD
EAX | EDX:EAX | CDQE
CLTQ | EAX | RAX
CQO | CQTO | RAX