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