From: Ben J. <be...@be...> - 2005-08-07 07:27:36
|
Using: $ bin/sdcc -v SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.5.1 #1058 (Aug 6 2005) (UNIX) int shiftbug() { static int foo; int bar; bar = foo >> 8; return bar; } The code correctly sees that a shift by 8 involves taking the top 8 bits and then sign extending, but it tests for the sign bit in the lower word instead of the upper: BANKSEL (_shiftbug_foo_1_1 + 1) ; .line 7; bug.c bar = foo >> 8; MOVF (_shiftbug_foo_1_1 + 1), W, B MOVWF r0x00 CLRF r0x01 BANKSEL _shiftbug_foo_1_1 BTFSC _shiftbug_foo_1_1, 7, B <<< should operate on +1 SETF r0x01 ; .line 8; bug.c return bar; This is a bug in gen.c genrshTwo(), either the BTFSC should use MSB16 instead of LSB or (maybe better?) test the LSB of the new *result* instead of the lhs. -- Ben Jackson <be...@be...> http://www.ben.com/ |