OpenCores
Issue List
SUBLW and Carry flag #1
Open ocghost opened this issue almost 18 years ago
ocghost commented almost 18 years ago

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.

ocghost commented almost 18 years ago

I've traced this down to the ALU input. This bug happens on all literal operations;

The literal is provided on the B input and the working register is provided on the A input. In case of a SUBLW instruction the ALU preforms working register - literal instead of literal - working register.


Assignee
No one
Labels
Bug