John Payson wrote: > [btw, in an early draft of this post, I included a routine > to send a byte uart-style out a PIC port pin at a rate of > one bit per three clocks as an example of something I think > could not be done at all reasonably in C [not that the assembly > version reads all that much better. It didn't really fit > my main points, but it's sorta clever so I'll put it below] John, After seeing only a little challenge in the comment I recoded the routine in C. The result isn't that much of a surprise since C's roots are that of a structured assembler. The listing fragment that follows generates the same code as the assembler source you posted. Walter Banks http://www.bytecraft.com void Payson (bits Data) 001C { 0005 009C MOVWF 1C 0006 1006 BCF PORTB,0 PORTB.0 = 0; 0007 1C1C BTFSS 1C,0 if(Data.0 == 0) 0008 2820 GOTO 0020h goto Clr1; 0009 1406 BSF PORTB,0 PORTB.0 = 1; Set1: 000A 189C BTFSC 1C,1 if(Data.1 == 1) 000B 2823 GOTO 0023h goto Set2; 000C 1006 BCF PORTB,0 PORTB.0 = 0; Clr2: 000D 1D1C BTFSS 1C,2 if(Data.2 == 0) 000E 2826 GOTO 0026h goto Clr3; 000F 1406 BSF PORTB,0 PORTB.0 = 1; Set3: 0010 199C BTFSC 1C,3 if(Data.3 == 1) 0011 2829 GOTO 0029h goto Set4; 0012 1006 BCF PORTB,0 PORTB.0 = 0; Clr4: 0013 1E1C BTFSS 1C,4 if(Data.4 == 0) 0014 282C GOTO 002Ch goto Clr5; 0015 1406 BSF PORTB,0 PORTB.0 = 1; Set5: 0016 1A9C BTFSC 1C,5 if(Data.5 == 1) 0017 282F GOTO 002Fh goto Set6; 0018 1006 BCF PORTB,0 PORTB.0 = 0; Clr6: 0019 1F1C BTFSS 1C,6 if(Data.6 == 0) 001A 2832 GOTO 0032h goto Clr7; 001B 1406 BSF PORTB,0 PORTB.0 = 1; Set7: 001C 0000 NOP NOP(); 001D 1F9C BTFSS 1C,7 if(Data.7 == 0) 001E 1006 BCF PORTB,0 PORTB.0 = 0; 001F 2836 GOTO 0036h goto Ending; Clr1: 0020 1C9C BTFSS 1C,1 if(Data.1 == 0) 0021 280D GOTO 000Dh goto Clr2 ; 0022 1406 BSF PORTB,0 PORTB.0 = 1; Set2: 0023 191C BTFSC 1C,2 if(Data.2 == 1) 0024 2810 GOTO 0010h goto Set3 ; 0025 1006 BCF PORTB,0 PORTB.0 = 0; Clr3: 0026 1D9C BTFSS 1C,3 if(Data.3 == 0) 0027 2813 GOTO 0013h goto Clr4 ; 0028 1406 BSF PORTB,0 PORTB.0 = 1; Set4: 0029 1A1C BTFSC 1C,4 if(Data.4 == 1) 002A 2816 GOTO 0016h goto Set5 ; 002B 1006 BCF PORTB,0 PORTB.0 = 0; Clr5: 002C 1E9C BTFSS 1C,5 if(Data.5 == 0) 002D 2819 GOTO 0019h goto Clr6 ; 002E 1406 BSF PORTB,0 PORTB.0 = 1; Set6: 002F 1B1C BTFSC 1C,6 if(Data.6 == 1) 0030 281C GOTO 001Ch goto Set7 ; 0031 1006 BCF PORTB,0 PORTB.0 = 0; Clr7: 0032 0000 NOP NOP(); 0033 1B9C BTFSC 1C,7 if(Data.7 == 1) 0034 1406 BSF PORTB,0 PORTB.0 = 1; 0035 2836 GOTO 0036h goto Ending // Waste the extra cycle Ending: 0036 1406 BSF PORTB,0 PORTB.0 = 1; // End of routine 0037 0008 RETURN }