??? 06/13/07 19:24 Read: times |
#140704 - Post Mortem #1.1 Responding to: ???'s previous message |
... continuing with a different compiler (SDCC)
Here are the programs: 1. c=c/2&85|c*2&170;c=c/4&51|c*4&204;RT c>>4|c<<4; // (47 bytes) 2. UC r,i=8;WH(i--){r>>=1;r|=c&128;c*=2;}RT r; // (43 bytes) 3. UC r,i=8;WH(i--){r*=2;r|=c&1;c/=2;}RT r; // (40 bytes) 4. UC r,i=8;WH(i--){r=r*2|c&1;c/=2;}RT r; // (38 bytes) 5. UC r,i=8;WH(i--)r=r*2|c&1,c/=2;RT r; // (36 bytes) 6. UC r,i=1;WH(r+=c&i?r++:r,i+=i);RT r; // (36 bytes) 7. IN r=1;WH(r<256)r=r*2|c&1,c/=2;RT r; // (36 bytes) 8. UC r,i=1;WH(r+=r+c/i%2,i+=i);RT r; // (34 bytes) And here is a summary of the results Program Length of generated code 1 38 2 27 3 27 4 27 5 27 6 27 7 43 8 22 Here's the generated code for #8: 00E7 306 _TestFlip: 00E7 AA 82 307 mov r2,dpl 308 ; testflip.c:138: UC r,i=1;WH(r+=r+c/i%2,i+=i);RT r; 00E9 7B 01 309 mov r3,#0x01 00EB 310 00101$: 00EB 8B F0 311 mov b,r3 00ED EA 312 mov a,r2 00EE 84 313 div ab 00EF 54 01 314 anl a,#0x01 00F1 2D 315 add a,r5 00F2 2D 316 add a,r5 00F3 FD 317 mov r5,a 00F4 EB 318 mov a,r3 00F5 2B 319 add a,r3 00F6 FC 320 mov r4,a 00F7 FB 321 mov r3,a 00F8 70 F1 322 jnz 00101$ 00FA 8D 82 323 mov dpl,r5 00FC 22 324 ret As for assembly versions of the code I think one need not look further than this one by Peter Dannegger:) http://home.tiscali.de/peterd/ap.../index.htm |