piclist 2001\04\18\212452a >
Thread: Page Switching Problem
face BY : David Cary email (remove spam text)

Dear Andrew Warren and David Harris,

"David P. Harris" <dpharrisEraseMEspamEraseMETELUS.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
    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 <EraseMEaiw.....spamCYPRESS.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

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

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


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...