home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,907 of 4,675   
   Steve to Robert Prins   
   Re: Converting some way to clever PL/I c   
   04 Aug 17 12:03:34   
   
   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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca