Hi Tamas, Thank you for sharing. Yes the XCSB example I gave does look like a macro until you consider that it also works when the LED ID is stored in a variable or the element of an array or is the result of a called function or some other complex expression. Mind you in those cases the generated code may or may not be reduced to a single instruction - it depends :-) Regards Sergio On Thu, 6 Mar 2008, Tamas Rudnai wrote: > That's cool Sergio, > > Looks like a macro in assembly: > > shDef macro arg1 > sh#v(arg1) res 1 > endm > > udata > shDef PORTA > > #define LED1 PORTB,0 > #define LED3 PORTA,1 > > turn macro instr,arg1,arg2 > if arg1 == PORTB > instr arg1,arg2 > else > instr sh#v(arg1),arg2 > movf sh#v(arg1),w > movwf arg1 > endif > endm > > turnon macro arg1,arg2 > turn bsf,arg1,arg2 > endm > > turnoff macro arg1,arg2 > turn bcf,arg1,arg2 > endm > > wait macro ms > movlw ms > call waitms > endm > > rst code 0 > goto main > > isr code 4 > retfie > > code > waitms > ; do a proper wait here.... > ; ...get it from your ASM library collection... > return > > main > turnon LED1 > wait .100 > turnoff LED1 > wait .100 > turnon LED3 > wait .100 > turnoff LED3 > > goto main > > So the disassembly for this: > > 57: main > 008 1406 BSF 0x6, 0 58: turnon > LED1 > 009 3064 MOVLW 0x64 59: wait .100 > 00A 2007 CALL 0x7 > 00B 1006 BCF 0x6, 0 60: turnoff LED1 > 00C 3064 MOVLW 0x64 61: wait > .100 > 00D 2007 CALL 0x7 > 00E 14A0 BSF 0x20, 0x1 62: turnon > LED3 > 00F 0820 MOVF 0x20, W > 010 0085 MOVWF 0x5 > 011 3064 MOVLW 0x64 63: wait .100 > 012 2007 CALL 0x7 > 013 10A0 BCF 0x20, 0x1 64: turnoff LED3 > 014 0820 MOVF 0x20, W > 015 0085 MOVWF 0x5 > 65: > 016 2808 GOTO 0x8 66: goto main > > > Regards, > Tamas -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist