Jump to content

Xor Results Incorrect

Recommended Posts

Bug description:

XOR does not produce correct results (inconsistent with other operators).


Steps to reproduce:

#include <system.h>

#define CONST1 0x780
#define CONST2 (0xF * 0x80) //0x780
#define CONST3 (0xA0 ^ 0x720) //0x780
#define CONST4 (0x7F80 & 0x7FF) //0x780

typedef unsigned char uint8;
typedef unsigned int uint16;

void main(void)
 volatile uint8 var8;
 volatile uint16 var16;

 var8 = CONST1; //0x80; this is the correct lower byte value
 var8 = CONST2; //0x80
 var8 = CONST3; //0x80
 var8 = CONST4; //0x80

 var16 = CONST1; //0x780; this is the correct 2-byte value
 var16 = CONST2; //0x780
 var16 = CONST3; //0x780
 var16 = CONST4; //0x780

 var8 = (CONST1 >> 1) & 0xff; //0xC0; this is the expected result
 var8 = (CONST2 >> 1) & 0xff; //0xC0
 var8 = (CONST3 >> 1) & 0xff; //0x40 INCONSISTENT
 var8 = (CONST4 >> 1) & 0xff; //0xC0

 var8 = (CONST1 >> 7) & 0xff; //0xF; this is the expected result
 var8 = (CONST2 >> 7) & 0xff; //0xF
 var8 = (CONST3 >> 7) & 0xff; //0x1 INCONSISTENT
 var8 = (CONST4 >> 7) & 0xff; //0xF


Expected behaviour:

Preserve upper byte of intermediate results so the result is consistent with other operators. (If this is a 16-bit vs. 8-bit issue, then the issue should exist for other operators besides XOR).


Is the problem 100% reproduceable:






Compiler version:

7.10, 7.051, maybe earlier as well.


Target device:

PIC16F1827, '1823, '688, etc.



Windows XP




Edited by djulien
Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...