Help us get a faster server
FAQ page: massmind.org/techref/method/math.htm?key=math

Truncated match.
1995\10\10@223225 by

Hello All,
I'm trying to find commonly used math expressions in my PIC
programming.  How do the majority accomplish the following:

if a>b call greater_than
if a<b call less_than
if a=>b call eq_or_gr
if a=<b call eq_or_less

and also:
if a>b AND c>d then call _and_
if a>b OR c>d then call _or_

What I'm using right now is a rather terse method of writing a
single bit then refering to it to check for 'and'/'or'.  Could
someone please mail me some code explaining the above?
Gerry
>I'm trying to find commonly used math expressions in my PIC
>programming.  How do the majority accomplish the following:

I use the Parallax assembler, which has codes to do what you are after.
(They don't have compare-and-call, but they do have compare-and-jump
and compare-and-skip instructions.  A compare-and-skip followed by a
call works exactly backwards... but the result is what you want.)

>if a>b call greater_than         <->   CSA (compare and skip if above)
>if a<b call less_than            <->   CSB (compare and skip if below)
>if a=>b call eq_or_gr            <->   CSAE (comp and skip if above or equal)
>if a=<b call eq_or_less          <->   CSBE (comp and skip if below or equal)

>and also:
>if a>b AND c>d then call _and_

CJBE A,B,SKIPME
CJBE C,D,SKIPME
CALL _and_
SKIPME [...]

>if a>b OR c>d then call _or_

CJBE A,B,CALLIT
CJBE C,D,CALLIT
JMP  SKIPIT
CALLIT CALL _or_
SKIPIT [...]

Note:  I haven't tried compiling the above fragments, but they "should"
work.  If you don't use the Parallax assembler, you can convert the
extended instructions directly into Microchip instructions.  (The compare
and jump instructions translate into four words; the compare and skip
translate into three.)  Grab a copy of the Parallax documentation from
their ftp site, and print out the chip instruction section.

Gerry Smith <LIUKBKIRK.NORTHERNC.ON.CA> wrote:

>I'm trying to find commonly used math expressions in my PIC
>programming.  How do the majority accomplish the following:

Gerry:

I have no idea how "the majority" do it (although I suspect that
most of them do it badly)... Here's how I would do it:

>if a>b call greater_than
MOVF    A,W
SUBWF   B,W
SKPC
CALL    GREATER_THAN

>if a<b call less_than
MOVF    B,W
SUBWF   A,W
SKPC
CALL    LESS_THAN

>if a=>b call eq_or_gr
MOVF    B,W
SUBWF   A,W
SKPNC
CALL    EQ_OR_GR

>if a=<b call eq_or_less
MOVF    A,W
SUBWF   B,W
SKPNC
CALL    EQ_OR_LESS

>if a>b AND c>d then call _and_
MOVF    A,W
SUBWF   B,W
SKPNC
GOTO    \$+5
MOVF    C,W
SUBWF   D,W
SKPC
CALL    _AND_

>if a>b OR c>d then call _or_
MOVF    A,W
SUBWF   B,W
SKPC
GOTO    \$+4
MOVF    C,W
SUBWF   D,W
SKPC
CALL    _OR_

As usual, I haven't tested or even assembled the code I'm
posting.

-Andy

--
Andrew Warren - fastfwdix.netcom.com
Fast Forward Engineering, Vista, California

* This message contains the file '16bitcmp.asm', which has been
* uuencoded. If you are using Pegasus Mail, then you can use
* the browser's eXtract function to lift the original contents
* out to a file, otherwise you will have to extract the message
* and uudecode it manually.

end
Attachment converted: wonderlandtwo:16bitcmp.asm (????/----) (00003B15)

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