#1778 [PIC14] bitwise operations on uncomplete registers

open
nobody
PIC14
5
2013-07-16
2011-04-11
Anonymous
No

Bitwise shifts on assignments to ports shouldn't be applied to port registers, as they may not be able to set/read some of they bits.

Example;
On pic16f877, PORTE register has only 3 bits (RE3:RE0), the rest (RE7:RE4) are non-writable, readed as 0.

On attached exaple program, compiled this way:
sdcc -mpic14 -p16f877a -V --debug -c shifted.c

The C code:

unsigned char tmp;
while(1){
tmp = PORTA;
PORTE = tmp >> 6;
}

Gets compiled to .asm code:

SWAPF r0x1001,W
ANDLW 0x0f
BANKSEL _PORTE
MOVWF _PORTE
BCF STATUS,0
RRF _PORTE,F
BCF STATUS,0
RRF _PORTE,F

Wich gets a wrong value in PORTE, for example:

if tmp = 0xff; tmp>>6 shoud be 0x03. but with that code:

SWAPF r0x1001,W ; W = 0xff
ANDLW 0x0f; W = 0x0f
BANKSEL _PORTE
MOVWF _PORTE ; PORTE = 0x07!! as RE7:RE3 are non-writable!!
BCF STATUS,0
RRF _PORTE,F ; PORTE = 0x03
BCF STATUS,0
RRF _PORTE,F; PORTE = 0x01!! should be 0x03!!

Discussion

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-04-11

    Example program with various approaches getting the same problem

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-04-11
    • summary: Bitwise shifts applied to ports on assignments --> Assignment of bitwise operations on uncomplete ports
     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-04-11
    • summary: Assignment of bitwise operations on uncomplete ports --> []Assignment of bitwise operations on uncomplete ports
     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-04-11
    • summary: []Assignment of bitwise operations on uncomplete ports --> [PIC14]Assignment of bitwise operations on uncomplete ports
     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-04-11
    • summary: [PIC14]Assignment of bitwise operations on uncomplete ports --> [PIC14] bitwise operations on uncomplete ports
     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-04-11
    • summary: [PIC14] bitwise operations on uncomplete ports --> [PIC14] bitwise operations on uncomplete registers
     
  • Gál Zsolt

    Gál Zsolt - 2011-04-12

    I tried this example with the freshest version of sdcc and I get almost the same result. This file has three version about bit shifting. The first is compiled well for me. The second and third gave the same result as I can read above. I tried some compiler options with no effect ( one by one and combined together also ):
    --nogcse
    --no-pcode-opt
    --noinvariant

    SDCC : pic16/pic14 3.0.2 #6420 (Apr 11 2011) (Linux)

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-04-13

    Sorry, I forgot to mention the version i used.

    $ sdcc -v
    SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Jan 10 2010) (UNIX)

     
  • Philipp Klaus Krause

    • Category: --> PIC14
     

Log in to post a comment.