macro with lables

johnlong

Senior Member
Hi All
Had another read of Hippys excillent work on explainig #macros and there use.
Noticed using multiple lables in the macro but could not fathom out how to send serrxd info
in the simulator so I had a think and came up with the following using 2 difrent lables 2 difrent variable and the first bits of the respective
variables
Code:
#macro bit_supply(var,var1,lable)'var is bit0 of b0 or bit8 of b1 var1 is b0 or b1
    if var=0 then:sertxd(" EVENS "):gosub declare:sertxd(#var1,lf,cr):endif
    if var=1 then:pause 15:sertxd(" ODDS "):gosub decbit:sertxd(#var,lf):goto lable:endif
    #endm
    
    do
    
    do while b0<10
        
    sup:
        b0=b0+1
        bit_supply(bit0,b0,sup)
    loop 
    b0=0
    do while b1<10
    pus: 
        b1=b1+1
        bit_supply(bit8,b1,pus)
    loop 
        b1=0
    loop 
declare:
 if b0>0 and b0<11 then
     sertxd("b0 ")
     elseif b1>0 and b1<11 then
         sertxd("b1 ")
         endif
         return
decbit:
    if bit0=1 then
        sertxd("bit0 ")
        elseif bit8=1 then
        sertxd("bit8 ")
    endif
    return
it just desplays the even values of the variables if the first bit is 0
regards
john
 

inglewoodpete

Senior Member
I copied your code into PE6 but found it too time-consuming to try and diagnose so much code that has so few comments to indicate what you are actually trying to do.

Something that you will find useful is to display the expanded code after any defines/macros are implemented by the preprocessor. Refer and select File menu>Options>Diagnostics>Pre-Processor>Display Pre-processor Output
 

Aries

New Member
I put your code (untouched) into PE6 and ran the simulator. The output is what I would have expected:

Code:
 ODDS bit0 1 EVENS b0 2
 ODDS bit0 1 EVENS b0 4
 ODDS bit0 1 EVENS b0 6
 ODDS bit0 1 EVENS b0 8
 ODDS bit0 1 EVENS b0 10
 ODDS bit8 1 EVENS b1 2
 ODDS bit8 1 EVENS b1 4
 ODDS bit8 1 EVENS b1 6
 ODDS bit8 1 EVENS b1 8
 ODDS bit8 1 EVENS b1 10
 ODDS bit0 1 EVENS b0 2
The program flow is something like:
Code:
do
bitsupply(odd number) ;skips EVENS, goes to decbit and internally does a goto sup, so next command is ...
bitsupply(even number) ; executes EVENS, skips ODDS and this time falls through to end of loop and repeats until loop is exhausted
loop .....
I'm not sure what you say your problem is. If it is that you are not getting the value of var1 printed for odd numbers, that is because you haven't asked it to. Your "declare" call is only in the ODDS conditional statement.
 

techElder

Well-known member
John, every time that you want to use a macro ask yourself this question, "Am I going to call this macro more than once in my program?"

If the answer is "YES!", then don't put a label into your macro. Macros are inserted as-is into your total program code. If you call it more than once with a label inside, then the label is inserted each time, too. That's where you'll get an error code about using a label more than once.

Your program, as presented here, would be better developed as a subroutine. You could then call it with a macro that could pass the variable values to the subroutine.

Passing parameters is the one key value to using a macro.
 
Top