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,908 of 4,675    |
|    Terje Mathisen to Steve    |
|    Re: Converting some way to clever PL/I c    |
|    04 Aug 17 14:54:49    |
   
   From: terje.mathisen@nospicedham.tmsw.no   
      
   Hi Steve!   
      
   You are of course correct that I had a typo in one of the versions,   
   thanks for spotting that!   
      
   Re the idea to split the loop into first finding a valid input and then   
   handling the rest, that is of course the fastest solution as long as the   
   body of the loop isn't too complicated, i.e. like in the current case.   
      
   The only real problem is that you have to look out for the additional   
   fencepost issue, i.e. what happens if the first valid input is the last   
   entry?   
      
   You should probably do a JMP Label4 after finding that first entry, and   
   since it is perfectly possible for a bunch of additions to wrap around   
   and end up with -1 as the sum, I would also keep a separate valid flag:   
      
    sum = 0;   
    valid = 0;   
    int i = 0;   
    while (i < len && arr[i] < 0) { i++; }   
    if (i < len) {   
    valid = 1;   
    sum = arr[i++];   
    while (i < len) {   
    a = arr[i++];   
    if (a > 0) sum += a; // Don't need to add any zeroes!   
    }   
    }   
      
   Terje   
      
   Steve wrote:   
   > Hi,   
   >   
   > Robert Prins
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca