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 On Thu, Mar 6, 2008 at 8:47 PM, sergio masci wrote: > > > > > > On Thu, 6 Mar 2008, Tamas Rudnai wrote: > > > > No 'general truth' is true in all corner cases, but the consensus in > > > literature (and this agrees with my experience) is that programming > > > takes the same amount of time per line of code *regardless of the > > > language used*. In most cases a HLL will produce more per line, so it > > > will be more productive. > > > > While this is true, I am not sure if there is anything about Assembly or > > HLL. The fact is that you get more pre-made libs for C or Basic (even for > > JAL), So that if you have a decent library for virtually everything, like > > LCD module, FAT driver, I2C SPI etc even a configurable PID controller then > > it is more productive, as you just have to use those libs/modules. So it > > "generates more code in a single line". But it could be done for Assembly > > too. Probably Olin has the most complex asm lib and I can imagine that he > > can produce a code just as fast as any HLL developer. > > > > In the other hand I agree with that part that with an HLL is is probably > > easier to thinking a problem in a bit "higher level". But still most of the > > C code I've seen tickling the bits (TRISA = 0x34 and stuff) well, that is > > not a high level. High level would be something like: > > > > def PORTB.0 as digital out; > > def LED1 as PORTB.0; > > > > LED1.on; > > wait(100); > > LED1.off; > > > > (Before you ask, I do not know what language is that, it was only in my > > imagination) > > > > "digital" could be a class... out is just a parameter for the constructor, > > maybe would be better to be written as > > > > def PORTB.0 as digital(out); > > > > ... so that's why LED1.on (as a method) can be used later on as LED1 was > > instantiated from the PORTB object - something like that :-) > > > > Is there any language something like this for PIC, which still can produce a > > fairly compact code? > > > In XCSB you would write: > > const LED1 = (&PORTB << 3) | 0 > > proc inline turnon(int arg1) > > *((char *)(arg1 >> 3)) |= 1 << (arg1 & 7) > > endproc > > proc inline turnoff(int arg1) > > *((char *)(arg1 >> 3)) &= ~(1 << (arg1 & 7)) > > endproc > > proc main() > > turnon(LED1) > > wait(100) > > turnoff(LED1) > > endproc > > > ignoring wait() the compiler would generate the following single > instructions in place of the function calls: > > ; turnon(LED1) > bsf 5,0 > > ; turnoff(LED1) > bcf 5,0 > > > if you then wanted to add a shadow register ONLY for PORTA you could > change turnon() and turnoff() to: > > const LED3 = (&PORTA << 3) | 1 > > proc inline turnon(int arg1) > > if (arg1 >> 3) == (int)(&PORTA) then > > shadow_a |= 1 << (arg1 & 7) > > *((char *)(arg1 >> 3)) = shadow_a > else > *((char *)(arg1 >> 3)) |= 1 << (arg1 & 7) > endif > > endproc > > proc inline turnoff(int arg1) > > if (arg1 >> 3) == (int)(&PORTA) then > > shadow_a &= ~(1 << (arg1 & 7)) > > *((char *)(arg1 >> 3)) = shadow_a > else > *((char *)(arg1 >> 3)) &= ~(1 << (arg1 & 7)) > endif > endproc > > > this would then still only generate ONE instruction for LED1: > > ; turnon(LED1) > bsf 5,0 > > ; turnoff(LED1) > bcf 5,0 > > but for LED3 would generate: > > ; for turnon(LED3) > bsf shadow_a,1 > movf shadow_a,w > movwf PORTA > > ; for turnoff(LED3) > bcf shadow_a,1 > movf shadow_a,w > movwf PORTA > > > Regards > Sergio Masci > -- > > > > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- Rudonix DoubleSaver Did You Know that DoubleSaver is Smaller and More Powerful FailSafe Device than Any Other You can Get? http://www.rudonix.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist