piclist 2003\06\05\110038a >
Thread: Call a function address by variable value
picon face BY : stanton54 email (remove spam text)

One easy way is with jump tables. Works something like this:

       mov ptr, [function number]
       mov w, <<ptr    ; w = 2 * function number
       call function_table

       jmp pc+w        ; you ARE allowed to do that;
                       ; you are just adding W to PC
       ; each one of these is 2 words, page (because of @) then jump
       jmp @function0
       jmp @function1
       jmp @function2

Then the functions can be written normally. You can probably find some
examples of doing this on 16 series PICs; it works exactly the same,
the assembly syntax is just a little different.

Now since you can add to PC just like any file register you may be
able to just do something like this:
       mov w, callback
       mov pc, w
I'm not sure if that works or not. You could try it in a simulator
if you have one.

Amir Shalem wrote:
{Quote hidden}

http://www.piclist.com hint: To leave the PICList
<3EDF5A6C.ED0039AA@earthlink.net> 7bit

See also: www.piclist.com/techref/ubicom/devices.htm?key=sx
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) Call a function address by variable value

month overview.

new search...