We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I am looking for a way to write some C51 functions to set or clear bits stored in the 8051 external data memory. For example, the following code was done in the 8051 assembly language:
;******************************* SYSTEM_TROUBLE1 XDATA 1000H AC_FAIL ACC.0 LOW_BAT ACC.1 . . SYSTEM_TROUBLE2 XDATA 1001H TELCO1_FAIL ACC.0 TELCO2_FAIL ACC.1 . . ;******************************* . . MOV DPTR, #SYSTEM_TROUBLE1 MOVX A, @DPTR SETB AC_FAIL MOVX @DPTR . .
Opps, sorry, I picked the wrong flag to test. You are correct, bit fields are inefficient. It would also be great if the compiler also optimized: <bitfield> <op> <const> or <const> <op> <bitfield> Where <op> is ==, !=, <, >, <=, >=, &&, || xdata struct { char AC_FAIL :1; char LOW_BAT :1; } SYSTEM_TROUBLE1 _at_ 0x1000; void main( void ) { if( SYSTEM_TROUBLE1.LOW_BAT ) SYSTEM_TROUBLE1.AC_FAIL = 1; } ; FUNCTION main (BEGIN) 0000 901000 MOV DPTR,#SYSTEM_TROUBLE1 0003 E0 MOVX A,@DPTR 0004 FF MOV R7,A 0005 C3 CLR C 0006 13 RRC A 0007 30E004 JNB ACC.0,?C0002 000A EF MOV A,R7 000B 4401 ORL A,#01H 000D F0 MOVX @DPTR,A 000E ?C0002: 000E 22 RET ; FUNCTION main (END)
Opps, sorry, I picked the wrong flag to test. You are correct, bit fields are inefficient. Uhhhh. You only tested one case of bit-fields -- a 1-bit bit-field. I would make more tests before making such a broad, sweeping statement. Anyway, what is so inefficient about the code that was generated? Jon