Follow up question: Following the same method as outlined by Bob, is it possible to map the (ab= solute) pointer_out directly from (abs) pointer_in? I have tried several wa= ys on paper, but I do not get to a simple solution. So starting with a valid (abs) pointer_in (mapped in the range 0x20-0x6F or= 0xA0-0xEF) I need to add the offset that can be anything between 0 and 0xA0, and then = account for =B4bankgaps=B4 and finally land in the same range 0x20-0x6F and= 0xA0-0xEF . I tried something by adding 0xB0 to the offset (is it smaller = or larger than 50?) but I diverge in such bookkeeping I cannot oversee. My current code utilises the virtual pointer_in as reference, but I think I= can go even faster if I took the absolute pointer_in as reference. Nonetheless my code is some 30% smaller now: Current code: getpointers_table160 decfsz virt_pointer_in, w ; if 0 then = point to top of the buffer again goto _skipifset ; if = not 0 then skip next line addlw CIRCULAR_BUFFER_LENGTH ; + 0xA0 _skipifset movwf virt_pointer_in ; wreg hold= s the current virt_pointer_in minus 1 addlw h'B0'-1 ; car= ry set if bank1 btfsc STATUS,C addlw h'30' addlw h'70' ; b= ank set 0x20-6F or 0xA0-EF movwf pointer_in ; now wr= eg holds the abs value of pointer_in = ; calc the pointer out movf pointer_offset, w ; offset f= rom 0 to 0xA0 addwf virt_pointer_in, w ; virt_point= er_in is used as ref here btfsc STATUS, C addlw h'60' addlw h'60' - 1 ; Ca= rry is set if >0xff btfss STATUS, C addlw h'A0' = ; At this point wreg =3D virtual pointer_out addlw h'B0' ; carry set if bank1 btfsc STATUS,C addlw h'30' addlw h'70' ; bank set 0x20-6F or 0x80-EF movwf pointer_out return ________________________________ Van: piclist-bounces@mit.edu namens Bob Ammerman = Verzonden: maandag 7 augustus 2017 19:52 Aan: 'Microcontroller discussion list - Public.' Onderwerp: RE: [PIC] pic16f628a memory bank switching in a large circular b= uffer. NOTE: all numbers are in HEX below. The trick below works because we are working MODULO 100 hex. Input: W is a pointer ranging from 00h thru 9Fh Output: W points to the correct register in bank 0 or 1 ; At entry, the value of W is as follows: ; 00..4F - we want to map to page 0 addresses 20..6F ; 50..9F - we want to map to page 1 addresses A0..EF ; We start by adding B0. This will set STATUS,C to 1, ; if we have a page 1 address, and to 0 if we have a ; page 0 address. After this add, we will have: ; B0..FF - which we want to map to page 0 addresses 20..6F ; 00..4F - which we want to map to page 1 addresses A0..EF ADDLW 0B0h ; Now, if carry is set, we add 30. After this conditional ; add, we will have: ; B0..FF - which we want to map to page 0 addresses 20..6F ; 30..7F - which we want to map to page 1 addresses A0..EF BTFSC STATUS,C ADDLW 030h ; One more add gives us our answer. By adding 70 we get: ; 20..6F for page 0 addresses ; A0..EF for page 1 addresses ADDLW 070h -- Problem solved in 4 instructions! ~ Bob Ammerman RAm Systems -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive PIClist, Microchip PIC www.piclist.com The PICList is a collection of people interested in the Microchip PIC proce= ssor. View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .