Searching \ for 'How to set macro argument default?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=how+set+macro+argument
Search entire site for: 'How to set macro argument default?'.

Truncated match.
PICList Thread
'How to set macro argument default?'
1998\01\26@174130 by Morgan Olsson

picon face
Like if I create
macro PRINT character,iterations
       default iterations=1         <- How to make this?
       <code to print character iterations of times>
       endm

So if i call it using
       PRINT 'A',3     ; it will print "AAA"
       PRINT 'A'       ; it will print "A"

Is it possible to make the assembler compile without all arguments are
defined, and let the macro detect and act on missing arguments? Like this:
(Following macro loads a literal to W and optionally stores it in one or
two registers)
LL      macro literal,r1,r2  ;macro name L_oad L_iteral
       movlw literal
       if not defined r1 exitm   <- How to make this?
       movwf r1
       if not defined r1 exitm   <- How to make this?
       movwf r2
       endm

Invocations:
       LL ff,ADTMRL,ADTMRH             ;sets PIC14000 A/D timer to max.
       LL 0F,PORTA                     ;sets PORTS...
       LL 24,PORTB                     ;
       LL e0                           ;=movlw e0

The clarity is one main reason to use macros!
       

Anyone know how to do this?
I mean setting default arguments and/or sensing if they are defined.
(I«ve tried some methods but did«nt get the expected results...)
(I«m using MPLAB 3.30)

Thanks in advance
/Morgan

Morgan Olsson, MORGANS REGLERTEKNIK, Sweden, ph: +46 (0)414 70741; fax 70331
============================================================================

1998\01\26@183113 by Andrew Warren

face
flavicon
face
Morgan Olsson <spam_OUTPICLISTTakeThisOuTspamMITVMA.MIT.EDU> wrote:

> Is it possible to make the assembler compile [a parameterized
> macro] without all arguments are defined, and let the macro detect
> and act on missing arguments?

   No.

   -Andy

=== Andrew Warren - .....fastfwdKILLspamspam@spam@ix.netcom.com
=== Fast Forward Engineering - Vista, California
=== http://www.geocities.com/SiliconValley/2499

1998\01\29@010633 by STEENKAMP [M.ING E&E]

flavicon
picon face
Hi,

{Quote hidden}

I think this will work:
LL      macro literal,r1,r2
         movlw literal
         ifdef r1
           movwf r1    ;Do only if r1 is defined
         endif
         ifdef r2
           movwf r2    ;Do only if r2 is defined
         endif
       endm

Invocations:
       LL 0fh, PORTA,
       or
       LL 10,,

You need to specify three parameters, always.  Even if they are empty -
hence the commas.

Your furst example might be done like this:

macro PRINT character,iterations
       ifndef iterations
         iterations=1
       endif
       <code to print character iterations of times>
       endm

Calling:
       PRINT 'A',3     ; it will print "AAA"
       PRINT 'A',      ; it will print "A"


Hope this helps!
Niki

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