Truncated match.
PICList
Thread
'A couple of macros for you'
1997\02\10@155346
by
mike
Hi,
Thought I'd share a couple of macros that I have written
with you:
; Variable definition:
cblock
acca:0, acca_h, acca_l ; two two-byte accumulators (ints)
accb:0, accb_h, accb_l ; ms byte first
endc
_negint: macro aaa ; negates an integer
comf aaa+1, f
incf aaa+1, f
btfsc status, z
decf aaa, f
comf aaa, f
endm
_addint: macro aaa, bbb ; add two integers together result in bbb
movf aaa+1, w
addwf bbb+1, f
btfsc status, c
incf bbb, f
movf aaa, w
addwf bbb, f
endm
_setint: macro aaa, lll ; sets integer aaa to literal value lll
if low(lll)==0
clrf aaa+1
else
movlw low(lll)
movwf aaa+1
endif
if high(lll)==0
clrf aaa
else
movlw high(lll)
movwf aaa
endif
endm
in use:
_setint acca, h'0001'
_setint accb, h'0001'
_addint acca, accb
accb now has the result of the sum: 1+1
Comments invited.
Regards,
Mike Watson
1997\02\10@171755
by
Andrew Warren
|
Mayes uk <spam_OUTmikeTakeThisOuT
d-m-g.demon.co.uk> wrote:
> _setint: macro aaa, lll ; sets integer aaa to literal value lll
> if low(lll)==0
> clrf aaa+1
> else
> movlw low(lll)
> movwf aaa+1
> endif
>
> if high(lll)==0
> clrf aaa
> else
> movlw high(lll)
> movwf aaa
> endif
> endm
>
> ....
>
> Comments invited.
Mike:
It's trivial, I know, but you can rewrite the above macro to allow it
to generate code like the following when the high and low bytes of
"lll" happen to be equal:
MOVLW lll
MOVWF aaa+1
MOVWF aaa
To do it, the macro should look something like this:
_setint: macro aaa,lll ; sets integer aaa to literal value lll
if (low (lll) == 0)
clrf (aaa) + 1
else
movlw low (lll)
movwf (aaa) + 1
endif
if (high (lll) == 0)
clrf aaa
else
if (high (lll) != low (lll))
movlw high (lll)
endif
movwf aaa
endif
endm
-Andy
=== Andrew Warren - .....fastfwdKILLspam
@spam@ix.netcom.com ===
=== Fast Forward Engineering - Vista, California ===
=== ===
=== Custodian of the PICLIST Fund -- For more info, see: ===
=== http://www.geocities.com/SiliconValley/2499/fund.html ===
1997\02\10@175643
by
Andrew Warren
Sorry... I left out a couple of sets of parentheses. It'll hardly
ever matter, but just to be safe, here's the correct version:
_setint: macro aaa,lll ; sets integer aaa to literal value lll
if (low (lll) == 0)
clrf (aaa) + 1
else
movlw low (lll)
movwf (aaa) + 1
endif
if (high (lll) == 0)
clrf (aaa)
else
if (high (lll) != low (lll))
movlw high (lll)
endif
movwf (aaa)
endif
endm
-Andy
=== Andrew Warren - fastfwd
KILLspamix.netcom.com ===
=== Fast Forward Engineering - Vista, California ===
=== ===
=== Custodian of the PICLIST Fund -- For more info, see: ===
=== http://www.geocities.com/SiliconValley/2499/fund.html ===
1997\02\11@044943
by
mike
In message <.....199702102217.OAA11646KILLspam
.....dfw-ix1.ix.netcom.com> EraseMEPICLISTspam_OUT
TakeThisOuTMITVMA.MIT.EDU
writes:
> Mike:
>
> It's trivial, I know, but you can rewrite the above macro to allow it
> to generate code like the following when the high and low bytes of
> "lll" happen to be equal:
Andy,
Nice one. I never thought of that situation. I'll pinch it if I may.
All three macros are trivial, but they are my first(s).
I've been having a look at some of the available C compilers and
am experimenting to see if some well crafted macros can provide
things that some of the c compilers can't - like signed integer
math for one.
Regards,
Mike Watson
More... (looser matching)
- Last day of these posts
- In 1997
, 1998 only
- Today
- New search...