User's Manual

86 Use XOR Instruction to Clear Integer Registers
AMD Athlon Processor x86 Code Optimization
22007E/0November 1999
Use XOR Instruction to Clear Integer Registers
To clear an integer register to all 0s, use XOR reg, reg. The
AMD Athlon processor is able to avoid the false read
dependency on the XOR instruction.
Example 1 (Acceptable):
MOV REG, 0
Example 2 (Preferred):
XOR REG, REG
Efficient 64-Bit Integer Arithmetic
This section contains a collection of code snippets and
subroutines showing the efficient implementation of 64-bit
arithmetic. Addition, subtraction, negation, and shifts are best
handled by inline code. Multiplies, divides, and remainders are
less common operations and should usually be implemented as
subroutines. If these subroutines are used often, the
programmer should consider inlining them. Except for division
and remainder, the code presented works for both signed and
unsigned integers. The division and remainder code shown
works for unsigned integers, but can easily be extended to
handle signed integers.
Example 1 (Addition):
;add operand in ECX:EBX to operand EDX:EAX, result in
; EDX:EAX
ADD EAX, EBX
ADC EDX, ECX
Example 2 (Subtraction):
;subtract operand in ECX:EBX from operand EDX:EAX, result in
; EDX:EAX
SUB EAX, EBX
SBB EDX, ECX
Example 3 (Negation):
;negate operand in EDX:EAX
NOT EDX
NEG EAX
SBB EDX, –1 ;fixup: increment hi-word if low-word was 0