Macro correctness

(instructions, reset, WDT, specifications...) PIC12F6xx, PIC16Fxxx, PIC16F6x, PIC16F7x

Macro correctness

Postby include12f675 » Sat May 26, 2018 7:09 am

Hi forum, I'm new here. I'd like to ask a question about these macro.
Code: Select all
; 16 bit compare by Y with X
; subtraction X to Y, X should be the greatest
; if X=Y then now Z=1
; if Y<X then now C=0
; if X<=Y then now C=1

cmp16       macro   Y,X,FAR
            local       NEAR
            clrc
            movf        high X,W
            subwf       high Y,W
            bnc         FAR
            bnz         NEAR
            movf        X,W
            subwf       Y,W
            bnc         FAR
NEAR
            endm
; Same as above but compare a file with a constant
cmpi16      macro   Y,CONST,FAR
            local       NEAR
            clrc
            movf        high Y,W
            sublw       high (CONST)
            bnc         FAR
            bnz         NEAR
            movf        Y,W
            sublw       low (CONST)
            bc         FAR
NEAR
            endm

; Same as above but compare a constant with a file
cmpc16      macro   CONST,Y,FAR
            local       NEAR
            clrc
            movlw       high (CONST)
            subwf       high Y,W
            bnc         FAR
            bnz         NEAR
            movlw       low (CONST)
            subwf       Y,W
            bc         FAR
NEAR
            endm

Honestly I haven't yet tested on the hardware :mrgreen: , but during a test with Proteus VSM, they don't behave as expected.
I'd expect that if the second term is less than the first it will branch to FAR.
include12f675
 
Posts: 12
Joined: Sat May 26, 2018 6:50 am
PIC experience: Experienced Hobbyist

Re: Macro correctness

Postby ric » Sat May 26, 2018 11:38 am

What family PIC (or even better, which precise PIC) are you testing this on?
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 433
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Macro correctness

Postby include12f675 » Sat May 26, 2018 12:38 pm

Well, is a 12F675. But it won't matter as much as it's one of those that need to test the carry flag in between two sustractions, which isn't propagated.
Likewise 12F18xx they might not need such a stress, then the check it would be just at the macro end. But that's a different macro.
include12f675
 
Posts: 12
Joined: Sat May 26, 2018 6:50 am
PIC experience: Experienced Hobbyist

Re: Macro correctness

Postby ric » Sun May 27, 2018 12:02 pm

Just a quick sanity check here.
Y is the first parameter
X is the second parameter.
After a subtraction, the Carry flag is the opposite of what you get in Intel style processors.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 433
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Macro correctness

Postby include12f675 » Sun May 27, 2018 4:04 pm

Well, I haven't started to write program on PC. I'd like to set a number of macros to semplify the programming task in assembly. Even that I'm less keen to use assembly, rather I opt for some higher programming level, like basic or C. Only for optimization case I fold the sleeves to do the hard way.
include12f675
 
Posts: 12
Joined: Sat May 26, 2018 6:50 am
PIC experience: Experienced Hobbyist

Re: Macro correctness

Postby ric » Sun May 27, 2018 11:04 pm

A grounding in assembly is a good way to become familiar with the strengths and weaknesses of the hardware.
If you are able to learn C, then it is an excellent way to become more productive.
It's easy to insert small sequences of assembly language into a C program if you have very tight timing on any particular processes.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 433
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to 14-Bit Core

Who is online

Users browsing this forum: No registered users and 0 guests