Maker Pro
Maker Pro

What is a good way to compare register values in a PIC assembly

Dwnld_pwm

Apr 9, 2019
2
Joined
Apr 9, 2019
Messages
2
Hello everyone.

I'm using a PIC16F887 with the PICkit2.
There doesn't seem to be a compare instruction so I'm wondering how one would go about comparing the values of two registers.

For example let's say Register REG1 has a value b'00100010' and REG2 has b'000000000' but the value of REG2 increases by 1 every loop iteration. I want the loop to stop when REG2 = REG1.
Is there a way of comparing them?

It's easy in C, but how do I implement it in assembly?
I'll leave a mixture of Assembly and C for reference.

Cheers,

MOVLW b'00100010'
MOVWF REG1

CLRF REG2

Loop:
INCF REG2
;(if REG2 == REG1){
goto stop
}
else{
goto Loop
 

Dwnld_pwm

Apr 9, 2019
2
Joined
Apr 9, 2019
Messages
2
Think I've just figured it out, here's the solution for whoever stumbles upon this in the future


MOVLW b'00100010'
MOVWF REG1

CLRF REG2

Loop:
INCF REG2, F
MOVFW REG2
SUBWF REG1, W
BTFSS STATUS, Z ;If REG1 = REG2 then REG1 - REG2 = 0 setting Z = 1
goto Loop
goto Stop
 

Minder

Apr 24, 2015
3,337
Joined
Apr 24, 2015
Messages
3,337
Also the logic instructions can be used in different ways to compare. notably the AND, XOR AND IOR.
M.
 
Top