Help with routine inc / dec in ASM 16 bit PIC16f877

Status
Not open for further replies.

aless2056

Member level 1
Joined
May 11, 2020
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
338
Guys, I made this code in asm for a PIC 16F877 that decreases Value (high and low) to 0x00 and increases to 0x64. Does anyone see something wrong with this code, or do you think it could be improved?

Code:
DEC

    MOVF    VALUE_HIGH,W
    SUBLW    B'00000000'
    BTFSS    STATUS,C
    GOTO    DC_DEC
    MOVF    VALUE_LOW,W
    SUBLW    B'00000000'
    BTFSC    STATUS,C
    GOTO    EXIT

DC_DEC
    DECF    VALUE_LOW,F
    MOVLW    .255
    XORWF    VALUE_LOW,W
    BTFSC    STATUS,Z
    DECF    VALUE_HIGH,F
    GOTO    EXIT




INC

    MOVLW    B'00000011'
    SUBWF    VALUE_HIGH,W
    BTFSS    STATUS,C
    GOTO    DC_INC
    MOVLW    B'11101000'
    SUBWF    VALUE_LOW,W
    BTFSC    STATUS,C
    GOTO    EXIT

DC_INC
    INCF    VALUE_LOW,F
    BTFSC    STATUS,Z
    INCF    VALUE_HIGH,F
    GOTO    EXIT
 
Last edited by a moderator:

Hi,

I'm not familiar with PIC and the ASM instructions.

But usually one starts with the LOW byte ... and in case of Carry one processes the HIGH byte.
With your solution it seems to be the other way around. Don't know if it's right or wrong.

Don't know what you do with the values 0b00000000, 0b00000011, 0b11101000 .... they don't match your text.

What about drawing a flow chart?
What about running a real world test or simulation?

Klaus
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…