??? 03/26/08 19:21 Read: times |
#152581 - OT: shifting 32 bit Responding to: ???'s previous message |
Andy Peters said:
shifting a 32-bit value in an 8-bit machine is what it is, but that code may still be smaller than that which detects which byte to shift into. Yes - shifting the 32 bit is probably smaller (and gives a more stable timing if you need that). Maybe try this: #include <8052.h> unsigned long f () { unsigned long t; /* no need to clear */ unsigned char i = 32; do { t <<= 1; if (P0_1) t |= 0x00000001; } while (--i); return t; } passed over "sdcc -c 32bit_shift.c" gives: <PRE> 330 ;Allocation info for local variables in function 'f' 331 ;------------------------------------------------------------ 332 ;t Allocated with name '_f_t_1_1' 333 ;i Allocated to registers r2 334 ;------------------------------------------------------------ 335 ; 32bit_shift.c:3: unsigned long f () 336 ; ----------------------------------------- 0000 339 _f: 348 ; 32bit_shift.c:8: do 0000 7A 20 349 mov r2,#0x20 0002 350 00103$: 351 ; 32bit_shift.c:10: t <<= 1; 0002 E5*00 352 mov a,_f_t_1_1 0004 25*00 353 add a,_f_t_1_1 0006 F5*00 354 mov _f_t_1_1,a 0008 E5*01 355 mov a,(_f_t_1_1 + 1) 000A 33 356 rlc a 000B F5*01 357 mov (_f_t_1_1 + 1),a 000D E5*02 358 mov a,(_f_t_1_1 + 2) 000F 33 359 rlc a 0010 F5*02 360 mov (_f_t_1_1 + 2),a 0012 E5*03 361 mov a,(_f_t_1_1 + 3) 0014 33 362 rlc a 0015 F5*03 363 mov (_f_t_1_1 + 3),a 364 ; 32bit_shift.c:11: if (P0_1) 0017 30 81 03 365 jnb _P0_1,00104$ 366 ; 32bit_shift.c:12: t |= 0x00000001; 001A 43r00 01 367 orl _f_t_1_1,#0x01 001D 368 00104$: 369 ; 32bit_shift.c:13: } while (--i); 001D DA E3 370 djnz r2,00103$ 371 ; 32bit_shift.c:15: return t; 001F 85*00 82 372 mov dpl,_f_t_1_1 0022 85*01 83 373 mov dph,(_f_t_1_1 + 1) 0025 85*02 F0 374 mov b,(_f_t_1_1 + 2) 0028 E5*03 375 mov a,(_f_t_1_1 + 3) 002A 22 376 ret Good luck with your project!) Frieder |
Topic | Author | Date |
24 bit number comparison in a 8 bit mc | 01/01/70 00:00 | |
assembler or C | 01/01/70 00:00 | |
How about this? (union, C-compiler, assembler) | 01/01/70 00:00 | |
helpful! | 01/01/70 00:00 | |
OT: shifting 32 bit | 01/01/70 00:00 | |
re: OT: shifting 32 bit | 01/01/70 00:00 | |
Thanks![]() | 01/01/70 00:00 |