Searching \ for 'Macro Gotcha' 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=macro+gotcha
Search entire site for: 'Macro Gotcha'.

Truncated match.
PICList Thread
'Macro Gotcha'
1996\10\17@173209 by Bob Fehrenbach

picon face
I spent way too much time chasing this one down today.  Perhaps
I'm a little slow and this situation is intuitively obvious to
others.  OTOH, maybe the experience will save someone else some time.
The actual case was considerably more complex than this but the problem
distills down to this example.

 ----------------------------------------------------
  list p = 16C62a, n = 0, c = 132, r = dec,

  cblock h'a0'
  test
  endc

gotcha:    macro aaa
  movwf   aaa + 1
  endm

          ;This does NOT expand in the manner you might expect:

  gotcha test + 1 ^h'80'

          ;Expands to:

;(0000 00A0               M    movwf   test + 1 ^h'80' + 1)
;         ^
;         Not where we were aiming

          ;Much better:

no_gotcha: macro aaa
  movwf   (aaa) + 1
          endm

  no_gotcha test + 1 ^h'80'

          ;Expands to:

;(0001 00A2               M    movwf   (test + 1 ^h'80') + 1)
;         ^
;         Expected address

   end
 ----------------------------------------------------


Two lessons: use parentheses around macro variables and don't
forget to check the list file to see if the assembler did what
you intended!



--
Bob Fehrenbach    Wauwatosa, WI     spam_OUTbfehrenbTakeThisOuTspamexecpc.com

1996\10\17@182858 by fastfwd

face
flavicon
face
Bob Fehrenbach <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU> wrote:

> I spent way too much time chasing this one down today.  Perhaps I'm
> a little slow and this situation is intuitively obvious to others.
> OTOH, maybe the experience will save someone else some time.
>
> [example deleted]
>
> Two lessons: use parentheses around macro variables and don't
> forget to check the list file to see if the assembler did what
> you intended!

Bob:

Don't feel bad... EVERYONE makes this mistake until, sooner or
later, he's bitten by it.

For C programmers, omitting parentheses from around the parameters of
a "#define" macro is an EXTREMELY popular bug... In fact, there's at
least one commercially-available application that GENERATES C source
code containing this bug.

-Andy

=== Andrew Warren - fastfwdspamKILLspamix.netcom.com                 ===
=== Fast Forward Engineering - Vista, California          ===
===                                                       ===
=== Custodian of the PICLIST Fund -- For more info, see:  ===
=== http://www.geocities.com/SiliconValley/2499/fund.html ===

1996\10\17@192516 by Gerhard Fiedler

flavicon
face
At 16:17 17/10/96 -0500, you wrote:
>Two lessons: use parentheses around macro variables and don't
>forget to check the list file to see if the assembler did what
>you intended!
>--
>Bob Fehrenbach    Wauwatosa, WI     .....bfehrenbKILLspamspam.....execpc.com

You can _never_ put too many parentheses in macros; put all the variables in
parentheses, and, where applicable (as with arithmetic expressions, e.g. in
C), the whole macro, too.

1996\10\18@172916 by robin.abbott

flavicon
face
Another good one with Macro's is to write a recursive macro,
that is one that calls itself, watch your PC go down! (This is why
some of us write our own simulators!)

RObin

+-----------------------------------------------------------------------+
|                                                                       |
|   EraseMErobin.abbottspam_OUTspamTakeThisOuTdial.pipex.com                                         |
|                                                                       |
|  PIC programmers and BASIC development systems from                   |
|    FOREST Electronic Developments. Visit our home page at             |
|                                                                       |
|      http://www.ibmpcug.co.uk/~gmwarner/fed.htm                       |
+-----------------------------------------------------------------------+

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