On Sun, 10 Sep 2000, Wojtek Zabolotny wrote: > On Sun, Sep 10, 2000 at 11:40:17AM +0200, Wojtek Zabolotny wrote: > > > I have a problem with setting of global symbols in macros in gpasm. > > It seems that each macro is evaluted TWICE =:-( ?! > > I've just found a very dirty workaround for the problem stated above > It is based on the assumption, that each macro is evaluated EXACTLY TWICE, > so it works with gpasm, but doesn't work with mpasm (my original source > works with mpasm and dosn't work with gpasm). > However it may be a solution, until the weird behaviour of gpasm gets > fixed... > > The "counter" macro should be redefined in the following way: > > counter macro > x_cnt_tmp1 set x_cnt + 1 > x_cnt set x_cnt_tmp > x_cnt_tmp set x_cnt_tmp1 > movlw x_cnt > endm > > Very dirty trick, but at least works... I spent two hours just trying to figure out why this is happening. I then spent another hour trying to fix it (before giving up :( ). And then I went back and spent another three hours. and now it's nearly midnight. Now I'm pissed... The problem is, as you correctly assumed, due to the macro being evaluated twice. However, this double evaluation is necessary because gpasm is designed as a `two-pass' assembler. In many cases, a single pass is sufficient. However, if there's a local label that is forward referenced, two passes are needed. In many cases, two passes are not needed, but it doesn't hurt. The exception is when a global variable is changed in the macro. What is needed is a way to differentiate local and global variables and only allow the latter to change during the second pass through the macro. Unfortunately, I'm not too familiar with this part gpasm (James Bowman wrote that part and I've heard from James for several months). Scott -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.