AMD Typewriter x86 사용자 설명서

다운로드
페이지 256
Always Pair CALL and RETURN
59
22007E/0—November 1999
AMD Athlon™ Processor x86 Code Optimization 
Example 6 — Increment Ring Buffer Offset:  
//C Code
char buf[BUFSIZE];
   int a;
   if (a < (BUFSIZE-1)) {
      a++;
   } else {
      a = 0;
   }   
;-------------
;Assembly Code
MOV     EAX, [a]          ; old offset
CMP     EAX, (BUFSIZE-1)  ; a < (BUFSIZE-1) ? CF : NC
INC     EAX               ; a++
SBB     EDX, EDX          ; a < (BUFSIZE-1) ? 0xffffffff :0
AND     EAX, EDX          ; a < (BUFSIZE-1) ? a++ : 0  
MOV     [a], EAX          ; store new offset
Example 7 — Integer Signum Function:  
//C Code
int a, s;
if (!a) {
      s = 0;
} else if (a < 0) {
      s = -1;
} else {
      s = 1;
}
;-------------
;Assembly Code
MOV     EAX, [a]         ;load a
CDQ                      ;t = a < 0 ? 0xffffffff : 0
CMP     EDX, EAX         ;a > 0 ? CF : NC
ADC     EDX, 0           ;a > 0 ? t+1 : t
MOV     [s], EDX         ;signum(x)
Always Pair CALL and RETURN
W h e n   t h e   1 2   e n t ry   re t u r n   a d d re s s   s t a ck   g e t s   o u t   o f
synchronization, the latency of returns increase. The return
address stack becomes out of sync when:
calls and returns do not match
the depth of the return stack is exceeded because of too 
many levels of nested functions calls