From: "Mcgee, Mark" > Hi > > I'm using PIC16F628A. > > I've been wondering how would you move along a buffer/array, reading or > writing to each location in a loop? I can't see any obvious indirect > memory > access instructions in the reference manual. > > In my old 6502/'6510 assembler days I'd do something like (IIRC); > LDA #0 > LDX #5 > loop: > STA buffer_start,X > DEX > BNE loop > ... > > Obviously, PIC only has the W register, and doesn't have index > registers...Is > there some 16-bit address to set, and some indirect instruction or > something? > > cheers, > Mark Mark: Take a look at the description of FSR and INDF. This is what you need to use. A PIC equivalent of your code would be something like this: movlw buffer ; get addr of buffer movwf FSR ;into FSR movlw 5 ;get count movwf temp ;into a working reg loop: clrf INDF ; store info mem pointed to be FSR incf FSR ; point to next mem location decfsz temp ; any more to do? goto loop ; Of course, for this short buffer at a known location, I would just write: clrf buffer clrf buffer+1 clrf buffer+2 clrf buffer+3 clrf buffer+4 Bob Ammerman RAm Systems _______________________________________________ http://www.piclist.com View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist