SUBLW and Carry flag
Information:
Type :: BUG
Status :: OPENED
Assigned to ::
Description:
Hi all,
I was experimenting with the PPX16 core and found a bug. I've also
contacted the author of this core, Daniel Wallner.
The problem I've came across has to do with the Carry flag and the
SUBLW command. It seems that the carry flag is not set correctly, i'll
explain:
The instruction description for SUBLW from the PIC16F84 datasheet
says; When the result is positive or zero the carry flag should be '1';.
When the result is negative the carry flag should be '0'.
The PPX16 core is doing the opposite; When the result is positive the
carry flag is '0', when the result is negative or zero the carry flag is '1'.
Here's a code snippet to give an example:
MOVLW 6
MOVWF main_w_L0
MOVF main_w_L0, 0
SUBLW 5
BTFSS STATUS, C ; Carry flag is set; not correct
MOVLW 5
MOVWF main_w_L0
MOVF main_w_L0, 0
SUBLW 5
BTFSS STATUS, C ; Carry flag is set; correct
MOVLW 4
MOVWF main_w_L0
MOVF main_w_L0, 0
SUBLW 5
BTFSS STATUS, C ; Carry flag is not set; not correct
I've tested this by outputting the current opcode on the seven segment
display and used a switch to manually create the clock for the core so I
could single step through the opcodes.
Workaround: Only use the SUBWF command which works correct.
Comments:
No comments yet...
Post a comment:
Login to post comments!
