; CC7A Ver 1.0D, Copyright (c) B Knudsen Data ; C compiler for the PIC18 microcontrollers ; ************ 24. Feb 2011 12:28 ************* processor 17C766 radix DEC INDF0 EQU 0x00 FSR0 EQU 0x01 WREG EQU 0x0A i EQU 0x20 a EQU 0x21 b EQU 0x22 flag EQU 0 semi EQU 1 GOTO main ; FILE 17\demo-ins.c ;// Generating SINGLE instructions using C SYNTAX or INLINE ASSEMBLY ; ;#pragma chip PIC17C766 // select device ; ;char i, a, b; ;bit flag, semi; ; ;void fx1( void); ;char fx2( void); ; ; ;char singleInstr( void) ;{ singleInstr ; nop(); // NOP ; No operation NOP ; ; i = W; // MOVWF f ; Move W to f MOVWF i ; ; i = 0; // CLRF f ; Clear f CLRF i,1 ; ; W = i - W; // SUBWF f,W ; Subtract W from f SUBWF i,W ; i = i - W; // SUBWF f ; Subtract W from f SUBWF i,1 ; ; W = i - 1; // DECF f,W ; Decrement f DECF i,W ; i = i - 1; // DECF f ; Decrement f DECF i,1 ; ; W = i | W; // IORWF f,W ; Inclusiv OR W and f IORWF i,W ; i = i | W; // IORWF f ; Inclusiv OR W and f IORWF i,1 ; ; W = i & W; // ANDWF f,W ; AND W and f ANDWF i,W ; i = i & W; // ANDWF f ; AND W and f ANDWF i,1 ; ; W = i ^ W; // XORWF f,W ; Exclusiv OR W and f XORWF i,W ; i = i ^ W; // XORWF f ; Exclusiv OR W and f XORWF i,1 ; ; W = i + W; // ADDWF f,W ; Add W and f ADDWF i,W ; i = i + W; // ADDWF f ; Add W and f ADDWF i,1 ; ; W = i; // MOVF f,W ; Move f MOVFP i,WREG ; ; W = i ^ 255; // COMF f,W ; Complement f COMF i,W ; i = i ^ 255; // COMF f ; Complement f COMF i,1 ; ; W = i + 1; // INCF f,W ; Increment f INCF i,W ; i = i + 1; // INCF f ; Increment f INCF i,1 ; ; W = decsz(i); // DECFSZ f,W ; Decrement f, skip if zero DECFSZ i,W ; i = decsz(i); // DECFSZ f ; Decrement f, skip if zero DECFSZ i,1 ; ; W = rr( i); // RRCF f,W ; Rotate right f RRCF i,W ; i = rr( i); // RRCF f ; Rotate right f RRCF i,1 ; ; W = rl( i); // RLCF f,W ; Rotate left f RLCF i,W ; i = rl( i); // RLCF f ; Rotate left f RLCF i,1 ; ; W = swap( i); // SWAPF f,W ; Swap halves f SWAPF i,W ; i = swap( i); // SWAPF f ; Swap halves f SWAPF i,1 ; ; W = incsz(i); // INCFSZ f,W ; Increment f, skip if zero INCFSZ i,W ; i = incsz(i); // INCFSZ f ; Increment f, skip if zero INCFSZ i,1 ; ; flag = 0; // BCF f,b ; Bit clear f BCF 0x23,flag ; ; semi = 1; // BSF f,b ; Bit set f BSF 0x23,semi ; ; btsc( flag); // BTFSC f,b ; Bit test f, skip if clear BTFSC 0x23,flag ; ; btss( flag); // BTFSS f,b ; Bit test f, skip if set BTFSS 0x23,flag ; ; sleep(); // SLEEP ; Go into standby mode SLEEP ; ; clrwdt(); // CLRWDT ; Clear watchdog timer CLRWDT ; ; return 5; // RETLW 5 ; Return, put literal in W RETLW 5 ; ; fx1(); // CALL fx1 ; Call subroutine CALL fx1 ; W = fx2(); // CALL fx2 ; Call subroutine CALL fx2 ; ; goto X; // GOTO X ; Go to address GOTO m005 ; ; W = 45; // MOVLW 45 ; Move literal to W MOVLW 45 ; ; W = W | 23; // IORLW 23 ; Incl. OR literal and W IORLW 23 ; ; W = W & 53; // ANDLW 53 ; AND literal and W ANDLW 53 ; ; W = W ^ 12; // XORLW 12 ; Excl. OR literal and W XORLW 12 ; ; W += 33; // ADDLW 33 ADDLW 33 ; ; return W; // RETURN RETURN ; ; W = 23 - W; // SUBLW 23 SUBLW 23 ; ; W = addWFC(i); // ADDWFC f,W ADDWFC i,W ; i = addWFC(i); ADDWFC i,1 ; ; W = subWFB(i); // SUBWFB i,W SUBWFB i,W ; i = subWFB(i); SUBWFB i,1 ; ; W = rrnc(i); // RRNCF i,W RRNCF i,W ; i = rrnc(i); RRNCF i,1 ; ; W = rlnc(i); // RLNCF i,W RLNCF i,W ; i = rlnc(i); RLNCF i,1 ; ; W = decsnz(i); // DCFSNZ i,W DCFSNZ i,W ; i = decsnz(i); DCFSNZ i,1 ; ; W = incsnz(i); // INFSNZ i,W INFSNZ i,W ; i = incsnz(i); INFSNZ i,1 ; ; b = negate(W); // NEGW b,1 NEGW b,1 ; i = decadj(W); // DAW i,1 DAW i,1 ; ; flag = !flag; // BTG 0x03,flag BTG 0x23,flag ; ; #ifndef _17C42 ; multiply( 50); // MULLW 50 MULLW 50 ; multiply( i); // MULWF i MULWF i ; #endif ; ; i = 0xFF; // SETF i,1 SETF i,1 ; ; skipIfEQ(a); // CPFSEQ a CPFSEQ a ; goto X; GOTO m005 ; if (a == W) // CPFSEQ a CPFSEQ a GOTO m001 ; i += b; MOVFP b,WREG ADDWF i,1 ; ; skipIfLT(b); // CPFSLT b m001 CPFSLT b ; nop(); NOP ; if (b < W) // CPFSLT b CPFSLT b GOTO m002 ; i += b; MOVFP b,WREG ADDWF i,1 ; ; skipIfGT(b); // CPFSGT b m002 CPFSGT b ; nop(); NOP ; if (b > W) // CPFSGT b CPFSGT b GOTO m003 ; i += b; MOVFP b,WREG ADDWF i,1 ; ; skipIfZero(b); // TSTFSZ b m003 TSTFSZ b ; nop(); NOP ; if (!b) // TSTFSZ b TSTFSZ b GOTO m004 ; i += b; MOVFP b,WREG ADDWF i,1 ; ; a = readLUInc(); /* table read-LSB-update-increment */ m004 TABLRD 0,1,a ; a = readLU(); /* table read-LSB-update */ TABLRD 0,0,a ; a = readL(); /* table read-LSB */ TLRD 0,a ; ; a = readHUInc(); /* table read-MSB-update-increment */ TABLRD 1,1,a ; a = readHU(); /* table read-MSB-update */ TABLRD 1,0,a ; a = readH(); /* table read-MSB */ TLRD 1,a ; ; writeLUInc(a); /* table write-LSB-update-increment */ TABLWT 0,1,a ; writeLU(a); /* table write-LSB-update */ TABLWT 0,0,a ; writeL(a); /* table write-LSB */ TLWT 0,a ; ; writeHUInc(a); /* table write-MSB-update-increment */ TABLWT 1,1,a ; writeHU(a); /* table write-MSB-update */ TABLWT 1,0,a ; writeH(a); /* table write-MSB */ TLWT 1,a ; ;X: ; return 0; m005 RETLW 0 ;} ; ; ;char sub( void) ;{ sub ; #asm ; NOP NOP ; ; MOVWF i MOVWF i ; ; CLRF i CLRF i,1 ; ; SUBWF i,W ; Subtract W from i SUBWF i,W ; SUBWF i ; Subtract W from i SUBWF i,1 ; ; DECF i,W ; Decrement i DECF i,W ; DECF i ; Decrement i DECF i,1 ; ; IORWF i,W ; Inclusiv OR W and i IORWF i,W ; IORWF i ; Inclusiv OR W and i IORWF i,1 ; ; ANDWF i,W ; AND W and i ANDWF i,W ; ANDWF i ; AND W and i ANDWF i,1 ; ; XORWF i,W ; Exclusiv OR W and i XORWF i,W ; XORWF i ; Exclusiv OR W and i XORWF i,1 ; ; ADDWF i,W ; Add W and i ADDWF i,W ; ADDWF i ; Add W and i ADDWF i,1 ; ; ;MOVF i,W ; Move i ; ; COMF i,W ; Complement i COMF i,W ; COMF i ; Complement i COMF i,1 ; ; INCF i,W ; Increment i INCF i,W ; INCF i ; Increment i INCF i,1 ; ; DECFSZ i,W ; Decrement i, skip if zero DECFSZ i,W ; DECFSZ i ; Decrement i, skip if zero DECFSZ i,1 ; ; RRCF i,W ; Rotate right i RRCF i,W ; RRCF i ; Rotate right i RRCF i,1 ; ; RLCF i,W ; Rotate left i RLCF i,W ; RLCF i ; Rotate left i RLCF i,1 ; ; SWAPF i,W ; Swap halves i SWAPF i,W ; SWAPF i ; Swap halves i SWAPF i,1 ; ; INCFSZ i,W ; Increment i, skip if zero INCFSZ i,W ; INCFSZ i ; Increment i, skip if zero INCFSZ i,1 ; ; BCF i,0 ; Bit clear i BCF i,0 ; ; BSF i,2 ; Bit set i BSF i,2 ; ; BTFSC i,3 ; Bit test i, skip if clear BTFSC i,3 ; ; BTFSS i,4 ; Bit test i, skip if set BTFSS i,4 ; ; SLEEP ; Go into standby mode SLEEP ; ; CLRWDT ; Clear watchdog timer CLRWDT ; ; RETLW 5 ; Return, put literal in W RETLW 5 ; ; CALL fx1 ; Call subroutine CALL fx1 ; CALL fx2 ; Call subroutine CALL fx2 ; ; GOTO X ; Go to address GOTO m006 ; ; MOVLW 45 ; Move literal to W MOVLW 45 ; ; IORLW 23 ; Incl. OR literal and W IORLW 23 ; ; ANDLW 53 ; AND literal and W ANDLW 53 ; ; XORLW 12 ; Excl. OR literal and W XORLW 12 ; ; ADDLW 33 ADDLW 33 ; ; RETURN RETURN ; ; SUBLW 23 SUBLW 23 ; ; ADDWFC i,W ADDWFC i,W ; ADDWFC i ADDWFC i,1 ; ; SUBWFB i,W SUBWFB i,W ; SUBWFB i SUBWFB i,1 ; ; RRNCF i,W RRNCF i,W ; RRNCF i RRNCF i,1 ; ; RLNCF i,W RLNCF i,W ; RLNCF i RLNCF i,1 ; ; DCFSNZ i,W DCFSNZ i,W ; DCFSNZ i DCFSNZ i,1 ; ; INFSNZ i,W INFSNZ i,W ; INFSNZ i INFSNZ i,1 ; ; NEGW b,W NEGW b,W ; NEGW b NEGW b,1 ; ; DAW i,W DAW i,W ; DAW i DAW i,1 ; ; BTG flag BTG 0x23,flag ; ; MULLW 50 MULLW 50 ; MULWF i MULWF i ; ; SETF i,W SETF i,W ; SETF i SETF i,1 ; ; CPFSEQ a CPFSEQ a ; ; CPFSEQ a CPFSEQ a ; ; ; CPFSLT b CPFSLT b ; ; CPFSLT b CPFSLT b ; ; X: ; ; CPFSGT b m006 CPFSGT b ; ; CPFSGT b CPFSGT b ; ; TSTFSZ b TSTFSZ b ; ; TSTFSZ b TSTFSZ b ; ; MOVFP a,WREG MOVFP a,WREG ; MOVPF WREG,b MOVPF WREG,b ; ; MOVFP a,FSR0 MOVFP a,FSR0 ; MOVPF INDF0,b MOVPF INDF0,b ; ; TABLRD 0,1,a TABLRD 0,1,a ; TABLRD 0,0,a TABLRD 0,0,a ; TLRD 0,a TLRD 0,a ; ; TABLRD 1,1,a TABLRD 1,1,a ; TABLRD 1,0,a TABLRD 1,0,a ; TLRD 1,a TLRD 1,a ; ; TABLWT 0,1,a TABLWT 0,1,a ; TABLWT 0,0,a TABLWT 0,0,a ; TLWT 0,a TLWT 0,a ; ; TABLWT 1,1,a TABLWT 1,1,a ; TABLWT 1,0,a TABLWT 1,0,a ; TLWT 1,a TLWT 1,a ; ; ; #endasm ; nop(); NOP ; singleInstr(); MOVLR 0 CALL singleInstr ; return 88; RETLW 88 ;} ; ;#ifndef _17C42 ; #pragma origin 4000 ORG 0x0FA0 ;#endif ; ;char lsub( void) ;{ lsub ; singleInstr(); CALL singleInstr ; return 88; RETLW 88 ;} ; ;void fx1( void) ;{ fx1 ;} RETURN ; ;char fx2( void) ;{ fx2 ; return 9; RETLW 9 ;} ; ;void main(void) ;{ main ; sub(); MOVLR 0 CALL sub ; lsub(); CALL lsub ;} SLEEP GOTO main END ; *** KEY INFO *** ; 0x0FA2 P0 1 word(s) 0 % : fx1 ; 0x0FA3 P0 1 word(s) 0 % : fx2 ; 0x0001 P0 102 word(s) 1 % : singleInstr ; 0x0067 P0 95 word(s) 1 % : sub ; 0x0FA0 P0 2 word(s) 0 % : lsub ; 0x0FA4 P0 5 word(s) 0 % : main ; RAM usage: 4 bytes (0 local), 898 bytes free ; Maximum call level: 3 ; Codepage 0 has 207 word(s) : 2 % ; Codepage 1 has 0 word(s) : 0 % ; Total of 207 code words (1 %)