> Hi, does anyone have any macros for 'IF THEN' statements and also a compare
> function.
>
I have written a collection of macros for often needed
IF A < > <= >= == B THEN GOTO ...
constructions.
How to use:
1. Load the W-reg with value 'A'
2. Choose the right Compare-and-Branch macro
An example:
MOVLW d'10'
CFWBG B,LABEL ; compare fileregister B with W-register,
; branch to LABEL if fileregister is greater than w-register
Attention!
I have not tested all macros
under all combinations of data values. So, think twice about any
macro before you use it! Any helpful comments are welcome.
Some macros will not work on 16C5x because of the SUBLW command.
Here they are:
nolist
; sublw l ; w := l - w
;
; C Z result
; --------------
; 0 0 l < w
; 0 1 illegal
; 1 0 l > w
; 1 1 l = w
;
; Carry only:
; 1 . l >= w
; 0 . l < w
CLWBG macro lit, addr ; Compare Literal to Work, Branch if Greater
local theend ; if lit > W then GOTO addr
SUBLW lit
bz theend
bc addr
theend
endm
CLWBGE macro lit, addr ; Compare Literal to Work, Branch if Greater
or Equal
; if lit >= W then GOTO addr
SUBLW lit
bc addr
endm
CLWBL macro lit, addr ; Compare Literal to Work, Branch if Less
; if lit < W then GOTO addr
SUBLW lit
bnc addr
endm
CLWBLE macro lit, addr ; Compare Literal to Work, Branch if Less or
Equal
; if lit <= W then GOTO addr
SUBLW lit
bz addr
bnc addr
endm
CLWBE macro lit, addr ; Compare Literal to Work, Branch if Equal
; if lit == W then GOTO addr
SUBLW lit
bz addr
endm
CLWBNE macro lit, addr ; Compare Literal to Work, Branch if Not
Equal
; if lit != W then GOTO addr
SUBLW lit
bnz addr
endm
CFWBG macro file, addr ; Compare File to Work, Branch if Greater
local theend ; if file > W then GOTO addr
SUBWF file,W
bz theend
bc addr
theend
endm
CFWBGE macro file, addr ; Compare File to Work, Branch if Greater or
Equal
; if file >= W then GOTO addr
SUBWF file,W
bc addr
endm
CFWBL macro file, addr ; Compare File to Work, Branch if Less
; if file < W then GOTO addr
SUBWF file,W
bnc addr
endm
CFWBLE macro file, addr ; Compare File to Work, Branch if Less or
Equal
; if file <= W then GOTO addr
SUBWF file,W
bz addr
bnc addr
endm
CFWBE macro file, addr ; Compare File to Work, Branch if Equal
; if file == W then GOTO addr
SUBWF file,W
bz addr
endm
CFWBNE macro file, addr ; Compare File to Work, Branch if Not Equal
; if file != W then GOTO addr
SUBWF file,W
bnz addr
endm
list
Siegfried Grob |
student of electrical engineering at the University of Ulm |
e-mail: spam_OUTsiegfried.grobTakeThisOuTstudent.uni-ulm.de |
phone&fax: +49-7304-921372 |
------------------------------------------------------------'
Clewer,Brian wrote:
>
> Hi, does anyone have any macros for 'IF THEN' statements and also a compare
> function.
>
> Thanks in advance,
> Brian.
I have some nice macros that are short ans sweet, I will post them when I get
to work. As I am at home not.. I should be today. Not exactly what you are
asking for, but I think you will like them.
At 01:53 PM 11/19/96 PST, you wrote:
>Hi, does anyone have any macros for 'IF THEN' statements and also a compare
>function.
>
>Thanks in advance,
> Brian.
>
>
Try including this in your source:
; -------------------------------------------------------------------------
; COMPARE.INC
;
; Macros to compare and branch/skip/call
;
; -------------------------------------------------------------------------
; Usage Description
; ---------------------------------- ----------------------------------
; clskpe label1, label2 Compare literal and skip if equal
; clskpne label1, label2 Compare literal and skip if not equal
; clje label1, label2, address Compare literal and jump to if equal
; cljne label1, label2, address Compare literal and jump to if not
equal
; clcalle label1, label2, address Compare literal and call if equal
; clcallne label1, label2, address Compare literal and call if not equal
; cskpe label1, label2 Compare and skip if equal
; cskpne label1, label2 Compare and skip if not equal
; cje label1, label2, address Compare and jump to if equal
; cjne label1, label2, address Compare and jump to if not equal
; ccalle label1, label2, address Compare and call if equal
; ccallne label1, label2, address Compare and call if not equal
;
; -------------------------------------------------------------------------