On Mon, Oct 18, 2004 at 01:04:46PM +0100, Mcgee, Mark wrote: > 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. The SFR combo you're looking for is FSR/INDF > > 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 In PIC the eqivalent would be something like (unchecked code warning...): movlw 5 movwf count movlw buffer_start movwf fsr loop: clrf indf incf fsr,F decfsz count,f goto 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? It does have index register(s). But they are special function registers as opposed to out of memory registers likw W. FSR holds the address, while INDF references the target of that address. And the 18F family actually has 3 pairs of them, along with auto inc/dec instructions for the FSR registers. Yet another advantage of the 18F parts. Finally be aware that FSR is only 8 bits. If the memory you need to access is beyond that, then you have to manipulate the indirect upper bits in some register (STATUS or OPTION can't remember off the top of my head). One advntage of FSR is that it is 8 bits so you can indirectly address up to 256 bytes (in)directly, while you can only access 128 bytes directly without switching banks. That's why sometimes I'll do code like: movlw TRISB ; In bank 1 movwf FSR clrf INDF ; make port B all outputs Without bothering to fiddle with the banking bits. Hope this helps, BAJ _______________________________________________ http://www.piclist.com View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist