Why are you keeping an offset from pointer_in, instead of just keeping pointer_out as a virtual pointer in its own right? ~ Bob Ammerman RAm Systems > -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of noname > Sent: Tuesday, August 08, 2017 3:55 PM > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] pic16f628a memory bank switching in a large circular buffer. >=20 > Follow up question: >=20 >=20 > Following the same method as outlined by Bob, is it possible to map the > (absolute) pointer_out directly from (abs) pointer_in? I have tried several > ways on paper, but I do not get to a simple solution. >=20 >=20 > So starting with a valid (abs) pointer_in (mapped in the range 0x20-0x6F or > 0xA0-0xEF) >=20 > I need to add the offset that can be anything between 0 and 0xA0, and the= n > account for =B4bankgaps=B4 and finally land in the same range 0x20-0x6F a= nd > 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. >=20 >=20 > 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. >=20 > Nonetheless my code is some 30% smaller now: >=20 >=20 > Current code: >=20 >=20 > getpointers_table160 > decfsz virt_pointer_in, w ; if 0 the= n point to top of the > buffer again > goto _skipifset ; i= f not 0 then skip next line > addlw CIRCULAR_BUFFER_LENGTH ; + 0xA0 > _skipifset > movwf virt_pointer_in ; wreg holds the current > virt_pointer_in minus 1 >=20 > addlw h'B0'-1 ; carry set if bank1 > btfsc STATUS,C > addlw h'30' > addlw h'70' ; bank set 0x20-6F or 0xA0-EF > movwf pointer_in ; now wreg holds the abs value of > pointer_in >=20 > ; calc the pointer out > movf pointer_offset, w ; offset from 0 to 0xA0 > addwf virt_pointer_in, w ; virt_pointer_in is used as ref > here > btfsc STATUS, C > addlw h'60' > addlw h'60' - 1 ; Carry is set if >0xff > btfss STATUS, C > addlw h'A0' >=20 > ; 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 >=20 >=20 >=20 >=20 >=20 > ________________________________ > 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 > buffer. >=20 > NOTE: all numbers are in HEX below. The trick below > works because we are working MODULO 100 hex. >=20 > Input: W is a pointer ranging from 00h thru 9Fh > Output: W points to the correct register in bank 0 or 1 >=20 > ; 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 >=20 > ; 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 >=20 > ADDLW 0B0h >=20 > ; 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 >=20 > BTFSC STATUS,C > ADDLW 030h >=20 > ; One more add gives us our answer. By adding 70 we get: > ; 20..6F for page 0 addresses > ; A0..EF for page 1 addresses >=20 > ADDLW 070h >=20 > -- Problem solved in 4 instructions! >=20 > ~ Bob Ammerman > RAm Systems >=20 > -- > 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 processor. >=20 >=20 > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > 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 .