Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/23/08 10:50
Read: times


 
#157684 - Language-independent method
Responding to: ???'s previous message
This is a common problem, and their matematician directly identified it. Had he been a software engineer, he would have told you to make all branches equal time, but instead suggested to slow down the loop to make the delay represent the largest time. Slowing the loop down would just have reduced the imbalance, but not removed it.

A way to do this in a high-level language with less effect by the geneated code is to replace the conditional assign with a computed assign:
unsigned char next[6] = {0x02,0x04,0x08,0x10,0x20,0x01};
unsigned char n = 0x01;
for (;;) {
    if (pressed) break;
    n = next[n];
}

If the div/modulo instructions are known to run at a fixed number of clock cycles for any numeric value, this can be done:
unsigned char n = 0;
for (;;) {
    if (pressed) break;
    n = (n+1) % 6;
}
n = 1 << n;





List of 28 messages in thread
TopicAuthorDate
8051 random numbers revisted - tested            01/01/70 00:00      
   Just Out Of Curiosity            01/01/70 00:00      
      yes casino            01/01/70 00:00      
   No fancy simulator required            01/01/70 00:00      
      Russ, great info here is MY code            01/01/70 00:00      
         Language-independent method            01/01/70 00:00      
            Oops            01/01/70 00:00      
               Head under arm            01/01/70 00:00      
                  HLL not an option            01/01/70 00:00      
                     HLL was just for example - easy to read            01/01/70 00:00      
         As always: The generation of random numbers ...            01/01/70 00:00      
          what is the need to CLR C            01/01/70 00:00      
            no need            01/01/70 00:00      
      does this solution make sense            01/01/70 00:00      
         Per's idea makes more sense            01/01/70 00:00      
         Don\'t use conditional jumps            01/01/70 00:00      
            Clever!            01/01/70 00:00      
      Converting Assembly to C            01/01/70 00:00      
   what about using the timer?            01/01/70 00:00      
      256 / 6 is a failure            01/01/70 00:00      
   One Suggestion for generating 1 to 6            01/01/70 00:00      
   try to use timer            01/01/70 00:00      
      yes a nice solution            01/01/70 00:00      
         How secure does this have to be ?            01/01/70 00:00      
            not much            01/01/70 00:00      
               Not "how safe?", but "how secure?".            01/01/70 00:00      
                  it passed!            01/01/70 00:00      
                     ALL THE BEST!!!            01/01/70 00:00      

Back to Subject List