Shop OBEX P1 Docs P2 Docs Learn Events
Table — Parallax Forums

Table

Armored CarsArmored Cars Posts: 172
edited 2005-08-26 16:41 in General Discussion
I need a way to use a table to call different subroutines.· This is a piece of a program that will load digits into·certain registors to be displayed on·a clock.· The main·program will load the·number it needes into w,·call the subroutine·DigCall that·multiplies·w by 2·to jump to the proper location.· What just·occured to me is that it might not work because ret takes three cycles.· If pc counts three for each ret this will mess up my program.· Will this code work or is there an easier way?

Something I thought of (I don't know if it will work or not) would be to delete the top of the stack so that ret will seem to go back to addresses.· That way I could make a table of just calls, skip past the DigCall routine and go back to the main program.

DigCall
clc
mov·w,RL w
mov·pc+w
call·dig0
ret
call·dig1
ret
call·dig2
ret
call·dig3
ret

Comments

  • BeanBean Posts: 8,129
    edited 2005-08-25 13:48
    Your working too hard...
    Just do

    DigCall:
    mov pc+w
    jmp dig0
    jmp dig1
    jmp dig2
    jmp dig3


    dig0:
    ; whatever
    ret

    dig1:
    ; whatever
    ret

    dig2:
    ; whatever
    ret

    dig3:
    ; whatever
    ret

    Main:
    MOV W,#1
    CALL DigCall


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    Product web site: www.sxvm.com

    "One experiment is worth a thousand theories"
    ·
  • Armored CarsArmored Cars Posts: 172
    edited 2005-08-25 14:00
    Ah.
    So simple.
    Smile! It would have been so much easier if I had thought of that earlier...

    Thanks for the tip. I will use it well.
  • dkemppaidkemppai Posts: 315
    edited 2005-08-26 16:41
    Bean (Hitt Consulting) said...
    Your working too hard...
    Just do

    DigCall:
    mov pc+w
    jmp dig0
    jmp dig1
    jmp dig2
    jmp dig3


    dig0:
    ; whatever
    ret

    dig1:
    ; whatever
    ret

    dig2:
    ; whatever
    ret

    dig3:
    ; whatever
    ret

    Main:
    MOV W,#1
    CALL DigCall


    Bean.

    Seems to me you can do a CLC and then RL, and use JMP @'s to switch pages with the jumps.·Don't remember the details, but remember doing that somewhere once before...
    ...I think a NOP between the "Move PC+W" and first "JMP" makes·it work correctly...

    -Dan
    ·
Sign In or Register to comment.