From: Grissiom <cha...@gm...> - 2010-03-29 14:45:27
|
More info on this question: It seems that SDCC will generate useless asm code when the bitwise code is enclosed in for loop. If the code is not in a for loop, the asm codes are the same. Does anyone have any ideas? Thanks ;) On Mon, Mar 29, 2010 at 9:09 AM, Grissiom <cha...@gm...> wrote: > Hello, > > When I use bitwise operation to get the high/low byte of a 16bit int: > ========================================= > IAP_ADDRH = (unsigned int)src >>8; > > IAP_ADDRL = (unsigned int)src & 0x00FF; > ========================================= > SDCC gives me the following asm code: > ========================================= > 488 ; eeprom.c:21: IAP_ADDRH = (unsigned int)src >> 8;^M > > 489 mov ar0,r5 > > 490 mov ar1,r6 > > 491 mov _IAP_ADDRH,r1 > > 492 ; eeprom.c:22: IAP_ADDRL = (unsigned int)src & 0x00FF;^M > > 493 mov r1,#0x00 > > 494 mov _IAP_ADDRL,r0 > ========================================= > I think there are many useless asm code. This is the second version: > ========================================= > 2 39 IAP_ADDRH = *((unsigned char *)&dest); > > 2 40 IAP_ADDRL = *((unsigned char *)&dest + 1); > ========================================= > which gives better asm code: > ========================================= > 555 ; eeprom.c:39: IAP_ADDRH = *((unsigned char *)&dest);^M > > 556 mov _IAP_ADDRH,_memcpy_toeep_dest_1_1 > > 557 ; eeprom.c:40: IAP_ADDRL = *((unsigned char *)&dest + 1);^M > > 558 mov _IAP_ADDRL,(_memcpy_toeep_dest_1_1 + 0x0001) > ========================================= > But the C code is ugly. Is there a better way? Thanks in advance. > > -- > Cheers, > Grissiom > -- Cheers, Grissiom |