Compile errors within macro....


Closed Thread
Results 1 to 7 of 7
  1. #1
    forgie's Avatar
    forgie Guest

    Default Compile errors within macro....

    This code displays a number thats in "1/2 cm" units. I want it to pad the number displayed with spaces, not with zeros.

    Code:
    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?

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    EDIT: sorry had bad on this one
    Last edited by mister_e; - 4th September 2005 at 19:26.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i'm guessing on PBP IF-THEN. so what about
    Code:
    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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.
    Code:
    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
    DT

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Also after checking my code, it won't work... MPASM IF ... ENDIF don't work like that... sorry.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    forgie's Avatar
    forgie Guest


    Did you find this post helpful? Yes | No

    Smile

    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

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Talking

    The following
    Code:
    IF A<20 THEN A=0
    will compile something like this
    Code:
    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
    Code:
    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Unable to pass a variable to LCDOUT without getting compile errors
    By Ferroto Baggins in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th February 2010, 16:43
  2. USB PBPL Compile errors
    By Rob in forum USB
    Replies: 11
    Last Post: - 7th April 2008, 08:18
  3. USB Mpasm Compile errors
    By JBrannan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st December 2007, 18:13
  4. Try to Compile 18F4550 Macro missing
    By Denicou in forum USB
    Replies: 7
    Last Post: - 28th January 2007, 22:24
  5. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts