0
\$\begingroup\$

I'm having troubles when MPLab shows me error within a macros (with assembly language). It gives the line number of where macros is defined. That's not very helpful if the macros is working fine, but the parameters passed are wrong. Is there a way to trace the macros back? (by "trace" I don't mean "runtime debug trace")

P.S. Note that this is not a question if macros should or should not be used.

For example let's have this macro (defined in an include file macro.inc):

loadWreg   macro x
  movlw x
endm

Then use in in 3 .asm files more than 10 times. One usage is wrong:

  loadWreg 0xFFFF    ; 16 bit value can't be loaded in WREG

Microchip shows the error in macro.inc on line with movlw x. How do I know where I passed wrong parameter to the macro?

\$\endgroup\$
  • \$\begingroup\$ You immediate problem is that you tried to stuff a 16 bit value into a 8 bit register. FFFFh doesn't fit into the 8 bit W register. Also, why use a macro for something that can be done natively in a single instruction. LoadWreg does nothing additional for you. It just makes your code harder to read and dependent on the macro file you are using. \$\endgroup\$ – Olin Lathrop Oct 6 '12 at 23:19
1
\$\begingroup\$

The macro is not really "called" at run time. That's what subroutines are. The parameter is therefore not "passed" at run time. It was resolved at build time and the results hard coded into that invocation of the macro. In other words, in the general case you can't really see what parameters were passed to macro by stepping through the code after the fact. If one of the parameters happens to be used as a literal constant, then you can see what that constant ended up being.

The way to step through a macro is to do it in the program memory window. When you get to the start of a macro in the source window, make the program memory window active instead. From then on single steps will be individual instructions. You may have to open a separate window with the macro source to see what is going on.

Also try STEP INTO (F7) when you get to a macro definition. I have occasionally had it show me the macro source code in the source window, but I don't remember what exactly I did to get there. F8 should step over and F7 step into, which might just work on macros. Have you tried that?

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Well, I'm not talking about runtime. I want to find out macro "call" position when I get error at compile time. When I'm talking about "trace", I don't mean "debug trace", but to find the macro usage position. \$\endgroup\$ – NickSoft Oct 14 '12 at 11:21
0
\$\begingroup\$

Enable the disassembly listing. You will then be able to trace macro execution.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ and how exatctly do I know in which file and which line the macro was called with wrong parameter. I'll write example in question text \$\endgroup\$ – NickSoft Oct 6 '12 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.