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: www.piclist.com/techref/ubicom/devices.htm?key=sx
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

flavicon
face
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

myfunction
       ;do something
       ret


In C, its easy to do

void function() { return; }

typedef void (*ptr) (void);

void start() {
       ptr *pointer;

       pointer = function;
       (pointer)();
}

is it possible to do in SX asm ?

thanks,
       Amir.

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu>

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

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

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
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu>

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