User's Manual

Push Memory Data Carefully 75
22007E/0November 1999 AMD Athlon Processor x86 Code Optimization
variable that starts with a negative value and reaches zero when
the loop expires. Note that if the base addresses are held in
registers (e.g., when the base addresses are passed as
arguments of a function) biasing the base addresses requires
additional instructions to perform the biasing at run time and a
small amount of additional overhead is incurred. In the
examples shown here the base addresses are used in the
displacement portion of the address and biasing is
accomplished at compile time by simply modifying the
displacement.
Example 3 (Preferred):
int a[MAXSIZE], b[MAXSIZE], c[MAXSIZE], i;
for (i=0; i < MAXSIZE; i++) {
c [i] = a[i] + b[i];
}
MOV ECX, (-MAXSIZE) ;initialize index
$add_loop:
MOV EAX, [ECX*4 + a + MAXSIZE*4] ;get a element
MOV EDX, [ECX*4 + b + MAXSIZE*4] ;get b element
ADD EAX, EDX ;a[i] + b[i]
MOV [ECX*4 + c + MAXSIZE*4], EAX ;write result to c
INC ECX ;increment index
JNZ $add_loop ;until index==0
Push Memory Data Carefully
Carefully choose the best method for pushing memory data. To
reduce register pressure and code dependencies, follow
example 2 below.
Example 1 (Avoid):
MOV EAX, [MEM]
PUSH EAX
Example 2 (Preferred):
PUSH [MEM]