From: Bogus@Embarq.com   
      
   Hi,   
      
    Robert Prins writes:   
   >I've recently come across some really clever/very nasty PL/I code, that would,   
   >theoretically, save CPU by eliminating a conditional jump. It relies on   
   >initializing a BCD-encoded ***integer*** variable ("sum") with -0.1, which   
   >results, on IBM mainframes, the last nibble of the BCD encoded value to   
   contain   
   >0xD (rather than the normal 0xC). The author uses this to avoid a costly   
   >(Phuleeze, pass me a bucket!) test, so rather than coding:   
      
    If I understand Terje's answer, he might have a typo   
      
    add edx,eax   
      
   should be   
      
    add edx, edi   
      
   Or maybe I missed something.   
      
    Anyway, why not something like:   
    MOV [Sum],-1 ; Set sum to illegal value.   
    MOV ECX,[WhatEver] ; Your loop count.   
    MOV ESI, OFFSET a ; Your data array.   
      
   Label1:   
    LODSD ; EAX is an array value.   
    TEST EAX,EAX   
    JL Label2 ; Skip unwanted values.   
      
    MOV [Sum],EAX ; Sum initial value   
    JMP Label3 ; Go process the rest   
      
   Label2:   
    LOOP Label1   
    JMP Label5 ; No valid data, Sum still -1.   
      
   Label3:   
    LODSD ; EAX is an array value.   
    TEST EAX,EAX   
    JL Label4 ; Skip unwanted values.   
      
    ADD [Sum],EAX ; Update Sum.   
      
   Label4:   
    LOOP Label3   
      
   Label5: ; No valid data, Sum still -1.   
    ; Valid data, Sum not -1.   
      
   Regards,   
      
   Steve N.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|