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
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to