As there is no header file for STM8, I was trying to create my own using 2 different approaches. They each produce different -though correct- outputs.
Code Sample 1: typedef struct { unsigned char PIN0:1 ; unsigned char PIN1:1 ; unsigned char PIN2:1 ; unsigned char PIN3:1 ; unsigned char PIN4:1 ; unsigned char PIN5:1 ; unsigned char PIN6:1 ; unsigned char PIN7:1 ; } _BITS_ ; typedef union { _BITS_ sbits ; unsigned char _sfrByte_ ; } _SFR_ ; //-------------------------------- volatile _SFR_ __at (0x500F) _PD_ODR_ ; //--------------------------------- #define PD_ODR _PD_ODR_._sfrByte_ #define PD1 _PD_ODR_.sbits.PIN1 //--------------------------------- void main(void) { PD_ODR |= 1<<1 ; PD1 = 1 ; } //--------------------------------- This produces (main.asm): .globl _main .globl __PD_ODR_ ;-------------------------------------------------------- ; ram data ;-------------------------------------------------------- .area DATA __PD_ODR_ = 0x500f ...... some instructions ...... _main: ; main.c: 26: PD_ODR |= 1<<1 ; ld a, __PD_ODR_+0 or a, #0x02 ld __PD_ODR_+0, a ; main.c: 28: PD1 = 1 ; bset __PD_ODR_+0, #1 ; main.c: 29: } ret ======================================== Code sample 2: #define _SFR_(mem_addr) (*(volatile unsigned char *)(0x5000 + (mem_addr))) /* PORT D */ #define PD_ODR _SFR_(0x0F) void main(void) { PD_ODR |= 1 << 1 ; } //------------------------------------------- Produces: _main: ; main.c: 9: PD_ODR |= 1 << 1 ; bset 20495, #1 ; main.c: 10: } ret This does seem more efficient. Its curious why the "PD_ODR |= 1<<1" produced the "ld a ...." in the 1st example, while just the 'bset ...' in the second, when both cases were absolute addresses. The 1st sample did produce "bset" for "PD1=1",(which is essentially "PD_ODR = 1 <<1" ). Best Regards, - Royce Pereira, T-Star Instrumentation, 102, Creative Industries, Sunder Nagar Road # 2, Kalina, Santacruz-East, Mumbai- 400098, INDIA Cell: +91 9820061636 *GSTIN*: 27AAFFT2843M1ZS P *Let's care for our Environment. * *Please don't print this e-mail unless you really need to.*
_______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user