piclist 2001\04\18\212452a >
Thread: Page Switching Problem
www.piclist.com/techref/power/priswitch.htm?key=switching
flavicon
face BY : David Cary email (remove spam text)



Dear Andrew Warren and David Harris,

"David P. Harris" <RemoveMEdpharrisspamspamTELUS.NET> on 2001-04-17 07:34:25 PM asked
> Why particularly do we need to restore the page bits?
> I thought these are only important when: doing a long call, long goto, or
> otherwise manipulatiing the PCLATH register, say when doing a long table
> look up?
> David

If you don't restore the page bits after a LCALL, this annoying problem happens:

    ; warning: untested code.
    incf fsr,f
    movlw 8
    movwf indf
next_iteration:
    lcall subroutine_on_another page
    ; ....... (normal, straight-line code)
    decfsz indf
    goto next_iteration
    decf fsr,f

Gotcha ! that final goto jumps some random location on that other page, rather
than back up to next_iteration.

Change that "lcall" to a "fcall" and then it works as expected (that
subroutine_on_another_page gets called 8 times).

Andrew Warren <spamaiwEraseMEspam@spam@CYPRESS.COM> on 2001-04-18 07:20:35 PM noted:
> MPASM's LCALL pseudo-op doesn't restore the page bits after the
> subroutine return.

True, alas.

Currently I have lots of "fcall" scattered through my code

    ...
fcall     macro subroutine_name
    lcall subroutine_name
    ; just in case we do *local* calls or gotos before the next fcall.
    local   here
    pagesel here
here:
    endm

    ...
    fcall sb_left_shift
    fcall sb_add
    fcall sb_left_shift
    fcall lookupTOS
    movwf screen+1
    ...
    decfsz indf,f
    goto next_bit_iteration
    return
    ...

This macro lets me call subroutines in any page from any page,
and restores the page bits after return so that I can do "short" call and goto.
(LGOTO works fine as-is).

I see that lots of people have tried to make similar macros that automatically
assemble a short call when possible, but I've never seen anyone succeed.

Using MPASM 02.61.

-- David Cary

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


<86256A33.00079FC8.00@Brunswickoutdoor.com>

See also: www.piclist.com/techref/power/priswitch.htm?key=switching
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Page Switching Problem

month overview.

new search...