You are on page 1of 5

; CC8E Version 1.0G, Copyright (c) B Knudsen Data ; C compiler for the PIC18 microcontrollers ; ************ 28.

May 2003 6:44 ************* processor PIC18C252 radix DEC INDF0 POSTINC0 POSTDEC0 PREINC0 FSR0 POSTINC1 FSR1 px p1 s e a px_2 i ax pxx lp C1tmp C2tmp z EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU GOTO main ; FILE 18\demo-ptr.c ;// POINTERS AND INDEXED TABLES ; ;#pragma chip PIC18C252 ; ; ;char tab1[10]; ;char tab2[10]; ; ;bank2 uns24 tu2[10]; ;bank3 uns24 tu3[10]; ;uns24 *px; ; ; ;void pointers( void) ;{ pointers ; ; MOVLW 10 MOVWF p1,0 ; CLRF s,0 ; ; ; m001 MOVFF p1,FSR0 CLRF FSR0+1,0 MOVLW 3 do s += *p1 & 3; char s = 0; // p1 is 8 bit wide char *p1 = tab1; 0xFEF 0xFEE 0xFED 0xFEC 0xFE9 0xFE6 0xFE1 0x1E 0x02 0x03 0x04 0x07 0x08 0x09 0x20 0x2C 0x2D 0x02 0x02 0x00

ANDWF INDF0,W,0 ADDWF s,1,0 ; INCF p1,1,0 MOVLW 19 CPFSGT p1,0 BRA m001 ; ; from 2 banks ; CLRF px,0 MOVLW 2 MOVWF px+1,0 ; MOVLW MOVWF MOVLW MOVWF MOVFF MOVFF MOVFF MOVFF MOVFF 27 px,0 3 px+1,0 px = &tu3[9]; px = tu2; // px is 16 bit wide because it can access elements while (++p1 < &tab1[10]);

m002

; uns24 e = *px; px,FSR0 px+1,FSR0+1 POSTINC0,e POSTINC0,e+1 POSTINC0,e+2 ; ; ; // low level pointer access ; FSR0 = &tab1[1]; MOVLW 11 MOVWF FSR0,0 CLRF FSR0+1,0 ; FSR1 = &tab2[0]; MOVLW 20 MOVWF FSR1,0 CLRF FSR1+1,0 ; char a = 10-1; MOVLW 9 MOVWF a,0 ; do { ; POSTINC0 = POSTINC1; // *FSR0++ = *FSR1++; MOVFF POSTINC1,POSTINC0 ; } while (--a > 0); DECFSZ a,1,0 BRA m002 ; ; char *px, i; ; i = *px; MOVFF px_2,FSR0 CLRF FSR0+1,0 MOVFF INDF0,i ; ; i = *FSR0; // MOVFF INDF0,i MOVFF INDF0,i ; i = *FSR0++; // MOVFF POSTINC0,i MOVFF POSTINC0,i ; i = *FSR0--; // MOVFF POSTDEC0,i MOVFF POSTDEC0,i ; i = *++FSR0; // MOVFF PREINC0,i MOVFF PREINC0,i

; i = *--FSR0; // MOVF POSTDEC0,W,0 , MOVFF INDF0,i MOVF POSTDEC0,W,0 MOVFF INDF0,i ;} RETURN ; ; ;typedef struct { ; uns16 ab; ; struct { ; uns8 l1; ; uns8 l2; ; } vx; ;} Txx; ; ;Txx ax, bx[2], *pxx; ; ;void sub( void) ;{ sub ; MOVLW 32 MOVWF pxx,0 ; MOVLW MOVWF MOVLW MOVWF CLRF MOVLW ADDWF MOVWF MOVLW MOVWF 232 ax,0 3 ax+1,0 ; FSR0+1,0 2 pxx,W,0 FSR0,0 3 INDF0,0 ; ; MOVLW 36 MOVWF pxx,0 ; CLRF MOVWF CLRF CLRF FSR0+1,0 FSR0,0 POSTINC0,0 POSTINC0,0 ; MOVLW 4 ADDWF pxx,1,0 ; CLRF MOVLW ADDWF MOVWF CLRF RETURN ; ; ;/* An array that need to cross page boundaries can opti onally be ; assigned a specific start address. This start addres FSR0+1,0 3 pxx,W,0 FSR0,0 INDF0,0 ;} pxx->vx.l2 = 0; pxx ++; pxx->ab = 0; pxx = &bx[0]; pxx->vx.l1 = 3; ax.ab = 1000; pxx = &ax;

s is only ; eed to cross ; a 256 byte boundary. */ ; ;uns16 large[256] @ 0x400; // bank 4 and 5 ; ;size2 uns16 *lp; ; ;uns16 sub2( void) ;{ sub2 ; MOVLW 2 ADDWF lp,1,0 MOVLW 0 ADDWFC lp+1,1,0 MOVLW 5 CPFSGT lp+1,0 BRA m003 ; CLRF lp,0 MOVLW 4 MOVWF lp+1,0 m003 ; return *lp; MOVFF lp,FSR0 MOVFF lp+1,FSR0+1 MOVFF POSTINC0,C1tmp MOVFF POSTINC0,C1tmp+1 MOVF C1tmp,W,0 RETURN ;} ; ;uns16 sub3( void) ;{ ; return *lp; MOVFF lp,FSR0 MOVFF lp+1,FSR0+1 MOVFF POSTINC0,C2tmp MOVFF POSTINC0,C2tmp+1 MOVF C2tmp,W,0 RETURN ;} ; ; ;void main(void) ;{ main ; RCALL pointers ; RCALL sub ; ; CLRF lp,0 MOVLW 4 MOVWF lp+1,0 ; RCALL sub2 uns16 z = sub2(); lp = &large[0]; sub(); pointers(); lp = &large[0]; if (++lp >= &large[256]) required when the array is less than 257 bytes and n

sub3

MOVFF C1tmp,z MOVFF C1tmp+1,z+1 ; RCALL sub3 ADDWF z,1,0 MOVF C2tmp+1,W,0 ADDWFC z+1,1,0 ;} SLEEP RESET END ; ; ; ; ; ; ; ; ;

z += sub3();

*** KEY INFO *** RAM usage: 619 bytes (10 local), 917 bytes free Maximum call level: 1 Total of 133 code words (0 %) 59 26 20 10 16 word(s), word(s), word(s), word(s), word(s), 0 0 0 0 0 %: %: %: %: %: pointers sub sub2 sub3 main