From: SourceForge.net <no...@so...> - 2012-02-11 23:22:08
|
Bugs item #2986039, was opened at 2010-04-12 11:10 Message generated for change (Comment added) made by tecodev You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=2986039&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: pic14 target >Group: fixed >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Jim Paris (jimatjtan) Assigned to: Nobody/Anonymous (nobody) Summary: PIC14: bit operations with wrong value in W register Initial Comment: Attached code miscompiles on pic14. sdcc -v: SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Jan 10 2010) (UNIX) compile with: sdcc --std-c89 -mpic14 -p16f628a --opt-code-speed -c -o bug.o bug.c In the .lst file, you can see four occurances like this one: 00192 ; .line 11; "bug.c" RB6 = (c & 8) ? 1 : 0; 001E 0000 0000 00193 BANKSEL r0x1001 0020 0C00 00194 RRF r0x1001,W 0021 1803 00195 BTFSC STATUS,0 0022 2800 00196 GOTO _00001_DS_ 0023 0000 0000 00197 BANKSEL _PORTB_bits 0025 1300 00198 BCF _PORTB_bits,6 0026 00199 _00001_DS_ 0026 1C03 00200 BTFSS STATUS,0 0027 2800 00201 GOTO _00002_DS_ 0028 0000 0000 00202 BANKSEL _PORTB_bits 002A 1700 00203 BSF _PORTB_bits,6 002B 00204 _00002_DS_ but the "W" register (used in "RRF r0x1001,W") is a stale value, in this case 0x7B. ---------------------------------------------------------------------- >Comment By: Raphael Neider (tecodev) Date: 2012-02-11 15:22 Message: Fixed for PIC14 and PIC16 in r7302. ---------------------------------------------------------------------- Comment By: Jim Paris (jimatjtan) Date: 2010-04-13 13:07 Message: Sorry for the misdiagnosis, been dealing with too many assembly language architectures lately :) Your description sounds right and the workaround does the right thing. Thanks for looking into it. ---------------------------------------------------------------------- Comment By: Raphael Neider (tecodev) Date: 2010-04-12 15:28 Message: OK, I see the problem now: RB6 = (c & 8) ? 1 : 0; is handled incorrectly (also for c&4, c&2, and c&1). Instead of implicitly doing RB6 = (0 != (c & 8)) ? 1 : 0; sdcc executes struct { uint8_t b0:1; } temp; temp.b0 = (c & 8); // THIS ALWAYS CLEARS temp.b0 RB6 = ((uint8_t)temp.b0) ? 1: 0; by mistaking the logic bit test on bit 3 for an assignment to a bitfield of width 1, for which only bit 0 of the expression is relevant... As a workaround, you can use RB6 = (0 != (c & 8)) ? 1 : 0; I'll try to fix this. Best regards, Raphael ---------------------------------------------------------------------- Comment By: Raphael Neider (tecodev) Date: 2010-04-12 14:02 Message: I do not see the problem: "RRF r0x1001, W" does not READ W at all -- it overwrites W with "r0x1001 >> 1" and updates STATUS, extracting the least signicant bit of r0x1001 (prior to shifting). Could you give any more details? Observed vs. expected output? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=2986039&group_id=599 |