Searching \ for '[SX]: Call a function address by variable value' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'Call a function address by variable value'.

Exact match. Not showing close matches.
PICList Thread
'[SX]: Call a function address by variable value'
2003\06\05@050934 by Amir Shalem

is it possible in SX to do CALL or JMP to an address specficed in a
variable ?

something like this: (this doesn't work)

       callback        EQU     $08
       reset start

start   mov callback, myfunction
       call callback

       ;do something

In C, its easy to do

void function() { return; }

typedef void (*ptr) (void);

void start() {
       ptr *pointer;

       pointer = function;

is it possible to do in SX asm ?


-- hint: To leave the PICList>

2003\06\05@110038 by stanton54

picon face
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}

-- hint: To leave the PICList>

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...