Searching \ for 'More snippets' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=more+snippets
Search entire site for: 'More snippets'.

Truncated match.
PICList Thread
'More snippets'
1999\09\27@200152 by Tony Nixon

flavicon
picon face
Hi all,

Just following on from the previous snippets, in an effort to make
comparisons easier to understand, here are some more. The best part is,
the Z flag is ignored.

if RAMx > RAMy

movf RAMy,w
sublw 0xFF
addwf RAMx,w
btfsc status,carry
goto true

if RAMx < RAMy

movf RAMx,w
sublw 0xFF
addwf RAMy,w
btfsc status,carry
goto true

if RAMx >= RAMy

movf RAMx,w
sublw 0xFF
addwf RAMy,w
btfss status,carry
goto true

if RAMx <= RAMy

movf RAMy,w
sublw 0xFF
addwf RAMx,w
btfss status,carry
goto true


--
Best regards

Tony

http://www.picnpoke.com
Email spam_OUTsalesTakeThisOuTspampicnpoke.com

1999\09\29@213031 by Scott Dattalo

face
flavicon
face
Let's see how the 18cxxx parts compare

On Tue, 28 Sep 1999, Tony Nixon wrote:

{Quote hidden}

 movf  RAMx,w  ;wreg = RAMx
 subwf RAMy,w  ;wreg = RAMy - RAMx
 bn    true    ;Branch if negative
               ;The N bit will be cleared if RAMx == RAMy or
               ;RAMy > RAMx, and will be set if RAMy < RAMx

(or you could use the bnc [branch if no carry] to achieve the same effect.
The negative bit has a clearer meaning in this context).

18cxxx 3*16 = 48 bits of program memory
16cxxx 5*14 = 70 bits of program memory


btw, Tony's example can be shortened to:

 movf  RAMx,w
 subwf RAMy,w
 skpc
  goto true

but there are still 4*14 = 52 bits. however this works on the 12bit core,
so only 4*12 = 48 bits of program memory are required there.


>
> if RAMx < RAMy
>
> movf RAMx,w
> sublw 0xFF
> addwf RAMy,w
> btfsc status,carry
> goto true
>

 Same as above with RAMx and RAMy exchanged.

> if RAMx >= RAMy
>
> movf RAMx,w
> sublw 0xFF
> addwf RAMy,w
> btfss status,carry
> goto true
>

 movf  RAMy,w    ;wreg = RAMy
 subwf RAMx,w    ;wreg = RAMx - RAMy
 bnn   true      ;branch if not negative
                 ;The N bit will be cleared if RAMx == RAMy or
                 ;RAMx > RAMy, and will be set if RAMy < RAMx

Again, you could use the bc (branch on carry) instruction too. Also,
Tony's sequence can be reduced by an instruction.

> if RAMx <= RAMy
>
> movf RAMy,w
> sublw 0xFF
> addwf RAMx,w
> btfss status,carry
> goto true



Scott


'More snippets'
1999\10\05@180639 by frmiller
flavicon
face
Just out of curiosity, if you're using an 18C (or 17C) part,
why wouldn't you use the CPFSEQ, CPFSLT, or CPFSGT
mnemonics?


Ryan



> {Original Message removed}

1999\10\05@193222 by Scott Dattalo

face
flavicon
face
On Tue, 5 Oct 1999, Ryan Miller wrote:

> Just out of curiosity, if you're using an 18C (or 17C) part,
> why wouldn't you use the CPFSEQ, CPFSLT, or CPFSGT
> mnemonics?

Hmmm. That IS a good question. The answer: I totally forgot about them!

Now the challenge, how would you use these for an efficient 16 bit
comparison?

Say

char compare(unsigned int a, unsigned int b)
{

if(a<b)
  {
    a is less than b
  }
else
  {
    a is greater than or equal to b
  }
}


 movf    b_hi,w
 cpfslt  a_hi
  bra    a_is_ge_b
 movf    b_lo,w
 cpfslt  a_lo
  bra    a_is_ge_b
a_is_lt_b
 ...


a_is_ge_b
 ...


But this can be made faster by using subtracts:

  movf   b_lo,w
  subwf  a_lo,w
  movf   b_hi,w
  subwfc a_hi,w
  bnc    ...      (or bc ...)

Any ideas?

Scott

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...