Table
Armored Cars
Posts: 172
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
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
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"
·
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.
...I think a NOP between the "Move PC+W" and first "JMP" makes·it work correctly...
-Dan
·