??? 02/07/06 22:15 Read: times |
#109461 - About 25 bytes with SDCC Responding to: ???'s previous message |
unsigned int Mask; void right_fill (unsigned char RightMostBits) { unsigned char i=RightMostBits; unsigned int tmp=1; if( i ) { do{ Mask |= tmp; tmp <<= 1; } while(--i); } } is about 25 bytes with SDCC: 84 ;Allocation info for local variables in function 'right_fill' 85 ;------------------------------------------------------------ 86 ;RightMostBits Allocated to registers r2 87 ;i Allocated to registers r2 88 ;tmp Allocated to registers r3 r4 89 ;------------------------------------------------------------ 90 ;rightmost.c:3: void right_fill (unsigned char RightMostBits) 91 ; ----------------------------------------- 92 ; function right_fill 93 ; ----------------------------------------- 0000 94 _right_fill: 0000 AA 82 104 mov r2,dpl 105 ;rightmost.c:6: unsigned int tmp=1; 0002 7B 01 107 mov r3,#0x01 0004 7C 00 108 mov r4,#0x00 109 ;rightmost.c:8: if( i ) 0006 EA 111 mov a,r2 0007 60 0F 113 jz 00106$ 114 ;rightmost.c:10: do{ 0009 116 00101$: 117 ;rightmost.c:11: Mask |= tmp; 0009 EB 119 mov a,r3 000A 42*00 120 orl _Mask,a 000C EC 121 mov a,r4 000D 42*01 122 orl (_Mask + 1),a 123 ;rightmost.c:12: tmp <<= 1; 000F EC 127 mov a,r4 0010 CB 128 xch a,r3 0011 25 E0 129 add a,acc 0013 CB 130 xch a,r3 0014 33 131 rlc a 0015 FC 132 mov r4,a 133 ;rightmost.c:14: while(--i); 0016 DA F1 135 djnz r2,00101$ 0018 136 00112$: 0018 137 00106$: 0018 22 138 ret (25 Bytes are including RET and MOV R2,DPL) |
Topic | Author | Date |
Right Filling n x Rightmost Bits with 1' | 01/01/70 00:00 | |
wrong approach | 01/01/70 00:00 | |
Wrong Approach ? | 01/01/70 00:00 | |
why not just |= bits_to_be_added | 01/01/70 00:00 | |
|= bits_to_be_added | 01/01/70 00:00 | |
ah | 01/01/70 00:00 | |
bang on | 01/01/70 00:00 | |
Try an Array | 01/01/70 00:00 | |
|= 2^RightMostBits -1; // sure? | 01/01/70 00:00 | |
You are correct about ^ != pow() | 01/01/70 00:00 | |
If only | 01/01/70 00:00 | |
About 25 bytes with SDCC | 01/01/70 00:00 | |
Thankyou | 01/01/70 00:00 | |
Why not use a table? | 01/01/70 00:00 | |
codesize | 01/01/70 00:00 | |
Yes, But..![]() | 01/01/70 00:00 |