Hi BAJ. Thanks for the help. I thought there must be something like that, given there is no indexing register or indirect opcode. I assume that once the FSR and (IRP-status bit 7 - looked it up) have been set, by referencing location INDF with clrf or movlf etc will perform the indirection for you? I like the 'no bankswitching' technique. Cheers, Mark > -----Original Message----- > From: piclist-bounces@mit.edu > [mailto:piclist-bounces@mit.edu]On Behalf > Of Byron A Jeff > Sent: 18 October 2004 13:47 > To: Microcontroller discussion list - Public. > Subject: Re: [PIC]Stepping through buffer in assembler? > > > 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 > ============================================================================== This message is for the sole use of the intended recipient. If you received this message in error please delete it and notify us. If this message was misdirected, CSFB does not waive any confidentiality or privilege. CSFB retains and monitors electronic communications sent through its network. Instructions transmitted over this system are not binding on CSFB until they are confirmed by us. Message transmission is not guaranteed to be secure. ============================================================================== _______________________________________________ http://www.piclist.com View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist