Icall()
Icall() Makes an indirect call of methods via a function pointer.
Syntax: Icall( Address[, Parameter definition( Parameter1, Parameter2, .. )] )
Use Parameter definition to pass parameters to the method.
- Address is the method address in memory (Flash).
Note: A indirect call to Luna methods expects #odecl.
See also: #cdecl, #odecl, #idecl
Example
' -------------------------------------------- ' ICALL example ' Example using a function pointer ' -------------------------------------------- ' System Settings ' -------------------------------------------- const F_CPU = 20000000 avr.device = atmega328p avr.clock = F_CPU avr.stack = 48 uart.baud = 19200 uart.Recv.enable uart.send.enable #define LeD1 as portd.5 #define LeD2 as portd.6 #define LeD3 as portd.7 'Function prototype declares number and type of paramters to pass 'Meaning: ' #cdecl = All Parameter are passed via stack. ' #odecl = 1. Parameter is passed via Register A, the rest via stack ' #idecl = 1. and 2. Parameter passed via Register A and B respectively, the rest via stack. The 1. Parameter must be a Variable, address, constant etc. ' Syntax: #cdecl <datatype/void> Identifier( [<byRef/byVal>] <datatype>, .. ) #odecl byte func_p(byte) #odecl void proc_p(byRef byte,word) ' | | | | | ' | | | | +Data Type 2.Parameter ' | | | +Data Type 1.Parameter ' | | +Type (optional), Reference or value(Default) ' | +Identifier of the parameter declaration ' +Return Type when Procedure "void" ' LeD1.mode = output LeD2.mode = output LeD3.mode = output dim a,b as byte dim ptr1,ptr2,ptr3 as word print 12; 'Function pointer of Method ptr1=test().Addr ptr2=myproc.Addr ptr3=myfunc.addr print "ptr1 = 0x";hex(ptr1) print "ptr2 = 0x";hex(ptr2) print "ptr3 = 0x";hex(ptr3) do icall(ptr1) icall(ptr2,proc_p(a,b)) b=icall(ptr3,func_p(b)) print 13; loop procedure test() LeD1.toggle print " | test()"; waitms 300 endproc function myfunc(a as byte) as byte LeD3.toggle incr a print " | myfunc(): a=0x";hex(a); waitms 300 return a endfunc procedure myproc(byRef a as byte,b as word) LeD2.toggle incr a print " | myproc(): a=0x";hex(a);", b=0x";hex(b); waitms 300 endproc