Intel ARCHITECTURE IA-32 User Manual

Page 413

Advertising
background image

64-bit Mode Coding Guidelines

8

8-5

IMUL RAX, RCX

The 64-bit version above is more efficient than using the following
32-bit version:

MOV EAX, DWORD PTR[X]

MOV ECX, DWORD PTR[Y]

IMUL ECX

In the 32-bit case above, EAX is required to be a source. The result ends
up in the EDX:EAX pair instead of in a single 64-bit register.

Assembly/Compiler Coding Rule

Use the 64-bit versions of multiply for 32-bit integer multiplies that require

a 64 bit result.

To add two 64-bit numbers in 32-bit legacy mode, the add instruction
followed by the addc instruction is used. For example, to add two 64-bit
variables (X and Y), the following four instructions could be used:

MOV EAX, DWORD PTR[X]

MOV EDX, DWORD PTR[X+4]

ADD EAX, DWORD PTR[Y]

ADC EDX, DWORD PTR[Y+4]

The result will end up in the two-register EDX:EAX.

In 64-bit mode, the above sequence can be reduced to the following:

MOV RAX, QWORD PTR[X]

ADD RAX, QWORD PTR[Y]

The result is stored in rax. One register is required instead of two.

Assembly/Compiler Coding Rule

Use the 64-bit versions of add for 64-bit adds.

Advertising