William Chops Westfield wrote: > > SendMorseCharA > > RLF MorseChar,f ; shift msb into carry > > movf MorseChar,f ; test to see if we're done > > bz SendMorseCharZ ; We're done, get out > > skpc ; skip if dit > > call DoDah ; go send dah - PRESERVE CARRY! > > skpnc > > call DoDit ; go send dit > > call InterCharDelay > > goto SendMorseCharA ; go send next bit, if any > > SendMorseCharZ > > return ; we're outta here! > > Speaking of C compilers, this is a good example of the sort of > code that I think it would be really difficult for a C compiler > to generate; It's what I meant by "explicit use of carry." Does > anybody want to take a shot at C code/compiler implementation > that comes close to outputting this? Following up the discussion on compilers and Bill's challange. I took the code above and directly hand translated it into C . Compiled code with MPC and a generic 14 bit header. The first thing was the clear Status C bit for the shift. The movf MorseChar,f was missed my bad registerw w = MorseChar; Couple interesting things. This compiler doesn't optimize out all one instruction jumps including these. I then recompiled the same code with a C6808 compiler. Listing follows. Ok so another small micro can embedded C compiler can compile essentially machine code. I then compiled the same code with a C compiler for an automotive engine controller. That too compiles. w.. ============================ MPC PIC 14 ======================================== 0000 #pragma regcc CC; 0017 char MorseChar; void SendMorseCharA (void) { 0017 1003 BCF STATUS,C MorseChar <<= 1; // RLF MorseChar,f ; shift msb into carry 0018 0D97 RLF 17 // movf MorseChar,f ; test to see if we're done 0019 1903 BTFSC STATUS,Z if (CC.Z == 1) return; // bz SendMorseCharZ ; We're done, get out 001A 0008 RETURN else { 001B 1C03 BTFSS STATUS,C if (CC.C == 0) // skpc ; skip if dit 001C 281E GOTO 001Eh 001D 200C CALL 000Ch DoDah(); // call DoDah ; go send dah - PRESERVE CARRY! 001E 1803 BTFSC STATUS,C if (CC.C == 1) // skpnc 001F 2821 GOTO 0021h 0020 200E CALL 000Eh DoDit(); // call DoDit ; go send dit 0021 2010 CALL 0010h InterCharDelay(); // call InterCharDelay 0022 2817 GOTO 0017h goto SendMorseCharA ; // goto SendMorseCharA ; go send next bit, if any } //SendMorseCharZ // return ; we're outta here! } ================== C6808 =========================================================== 0000 #pragma regcc CC; 0055 char MorseChar; void SendMorseCharA (void) { B08C 38 55 LSL $55 MorseChar <<= 1; // RLF MorseChar,f ; shift msb into carry // movf MorseChar,f ; test to see if we're done B08E 26 01 BNE $B091 if (CC.Z == 1) return; // bz SendMorseCharZ ; We're done, get out B090 81 RTS else { B091 25 02 BCS $B095 if (CC.C == 0) // skpc ; skip if dit B093 AD F1 BSR $B086 DoDah(); // call DoDah ; go send dah - PRESERVE CARRY! B095 24 02 BCC $B099 if (CC.C == 1) // skpnc B097 AD EF BSR $B088 DoDit(); // call DoDit ; go send dit B099 AD EF BSR $B08A InterCharDelay(); // call InterCharDelay B09B 20 EF BRA $B08C goto SendMorseCharA ; // goto SendMorseCharA ; go send next bit, if any } //SendMorseCharZ // return ; we're outta here! } ================== eTPU ============================================================ 0000 #pragma regcc CC; 0006 char MorseChar; void SendMorseCharA (void) { 022C 9FD67A02 alu p = rar ,ccs; ram 0009 = p23_0. 0230 9FEFFB01 ram p23_0 = 0005. MorseChar <<= 1; // RLF MorseChar,f ; shift msb into carry // movf MorseChar,f ; test to see if we're done 0234 93F1CA01 alu p15_8 = p15_8 <<1 , ccs;ram 0005 = p23_0 . 0238 F0C0125F if z==0 jump 0248,flush. if (CC.Z == 1) return; // bz SendMorseCharZ ; We're done, get out 023C 9FEFFB02 ram p23_0 = 0009. 0240 3BF86FD4 alu rar = p ,ccs. 0244 FFDFCCF9 return,flush. else { if (CC.C == 0) // skpc ; skip if dit 0248 F088129F if c==1 jump 0250,flush. 024C FFC010BF call 0214,flush. 0250 DoDah(); // call DoDah ; go send dah - PRESERVE CARRY! if (CC.C == 1) // skpnc 0250 F08012DF if c==0 jump 0258,flush. 0254 FFC010FF call 021C,flush. 0258 FFC0113F call 0224,flush. DoDit(); // call DoDit ; go send dit 025C InterCharDelay(); // call InterCharDelay 025C F7C0117F jump 022C,flush. goto SendMorseCharA ; // goto SendMorseCharA ; go send next bit, if any } //SendMorseCharZ // return ; we're outta here! } -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist