View Full Version : Compile errors within macro....
forgie
- 4th September 2005, 18:31
This code displays a number thats in "1/2 cm" units. I want it to pad the number displayed with spaces, not with zeros.
Dist_To_Print var word system
@Print_Distance macro arg
@ MOVE?WW arg, Dist_To_Print
if dist_to_print < 200 then
lcdout " "
endif
if dist_to_print < 20 then
lcdout " "
endif
lcdout #(dist_to_print / 2), ".", dec1 ((Dist_To_Print // 2) * 5), "cm"
@ endm
I get compile errors this macro, but they go away and it works if I remove the If statements. The error says "Address label duplicated or different in second pass (L00001)"
Any suggestions?
mister_e
- 4th September 2005, 19:20
EDIT: sorry had bad on this one
mister_e
- 4th September 2005, 19:24
i'm guessing on PBP IF-THEN. so what about
Dist_To_Print var word SYSTEM
@Print_Distance macro arg
@ MOVE?WW arg, Dist_To_Print
@ if Dist_To_Print < 200
lcdout " "
@ endif
@ if Dist_To_Print < 20
lcdout " "
@ endif
lcdout #(dist_to_print / 2), ".", dec1 ((Dist_To_Print // 2) * 5), "cm"
@ endm
Darrel Taylor
- 4th September 2005, 19:28
Any labels in a macro have to be declared with a "local" directive to keep from creating duplicates. Since you have no control over which labels are assigned by PBP, all you can do is let the compiler find them, and then add the labels that cause a problem to a local directive.
@Print_Distance macro arg
@ local L00001, L00003
As the program changes, so will the labels that automatically get generated. So you will be constantly changing the "local" statement to match the current label usage. Also, as Steve and I have already pointed out. You shouldn't put that much code in a macro to begin with.
Create a subroutine with the heavy duty PBP code in it, and just use the macro's to pass the paramters to it. It not only saves on code space, but it also solves the label problem.
Dist_To_Print var word system
;------------------------------
Print_Distance_code:
if dist_to_print < 200 then
lcdout " "
endif
if dist_to_print < 20 then
lcdout " "
endif
lcdout #(dist_to_print / 2), ".", dec1 ((Dist_To_Print // 2) * 5), "cm"
return
;------------------------------
ASM
Print_Distance macro arg
MOVE?WW arg, Dist_To_Print
L?CALL _Print_Distance_code
endm
ENDASM
mister_e
- 4th September 2005, 20:22
Also after checking my code, it won't work... MPASM IF ... ENDIF don't work like that... sorry.
forgie
- 5th September 2005, 04:28
Thanks Darrel,
I will change the structure of the macro to eliminate this problem, but in the meantime, can you be a bit more specific about the labelling problem? I can't be content with a problem until I understand it!
And mister_e, I think your example would end up comparing the address of Dist_To_Print with 200, not the variable itself.... the macro assembly stage can't make decisions based on realtime variables :)
mister_e
- 5th September 2005, 19:08
The following
IF A<20 THEN A=0
will compile something like this
CMPGE?BCL _A, 014h, L00001
MOVE?CB 000h, _A
LABEL?L L00001
It call CMPGE?BCL =>Compare Greater/Equal a Byte Against a constant and jump to L00001 if False
As previously said, when you call a macro it duplicate the whole code. Something like
CMPGE?BCL _A, 014h, L00001
MOVE?CB 000h, _A
LABEL?L L00001
'/////////////////// blah blah blah here \\\\\\\\\\\\\\\\\\\\\\\\\\\\
CMPGE?BCL _A, 014h, L00001
MOVE?CB 000h, _A
LABEL?L L00001
You have two L00001 generated and unfortunately we/you have no control on that.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.