Call a User Definced Function from ASM code

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Call a User Definced Function from ASM code

Post by octal » Thu Jan 18, 2007 10:31 am

Hi,
Actually, in ASM blocs we can call a user defined Sub

Code: Select all

sub MyCallingSubroutine(myParam as Byte)
...
  ; set Bit value...
   movf   DataPort, W    
   andwf  MakeLow, W   
   btfsc  STATUS, C       
   iorwf  MakeHigh, W    
   movwf  DataPort        

;>>>>>>> THE CALL TO MY SWFBasic Subroutine
  rcall  MyUserSubroutine
;>>>>>>> THE CALL TO MY FUNCTION

   decfsz Index, F        
   bra    $ - 32          
...
End Sub
How must I do If I want to call MyUserSubroutine with a parameter ... for example

Code: Select all


sub MyUserSubroutine( SomeParam as Byte)  as Byte
//doSomething ..... with the SomeParam
end sub

sub MyCallingSubroutine(myParam as Byte)
...
  ; set Bit value...
   movf   DataPort, W    
   andwf  MakeLow, W   
   btfsc  STATUS, C       
   iorwf  MakeHigh, W    
   movwf  DataPort        

;>>>>>>> THE CALL TO MY FUNCTION
   rcall  MyUserSubroutine          
//if I would like to call MyUserSubroutine with myParam as parameter???
          
;>>>>>>> THE CALL TO MY FUNCTION

   decfsz Index, F        
   bra    $ - 32          
...
End Sub
And how must we do if we want to call a FUNCTION with a param and get its result ?

best regards

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Thu Jan 18, 2007 11:08 am

Code: Select all

function MyUserSubroutine( SomeParam as byte) as byte  
   result = SomeParam
end function

sub MyCallingSubroutine(myParam as byte)
   asm
   ; set bit Value...
   movf   DataPort, W   
   andwf  MakeLow, W   
   btfsc  STATUS, C       
   iorwf  MakeHigh, W   
   movwf  DataPort       
   end asm
   Value = MyUserSubroutine(myParam)
   asm            
   decfsz Index, F       
   bra    $ - 32         
   end asm
end sub 

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Thu Jan 18, 2007 11:20 am

Thank you David, but this does not answer to my first question.

Intead of calling my sub using RCALL in asm, can I simply close the asm bloc, call mu sub with parameter, and reopen the asm bloc ?
is that correct ?

Best regards

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Thu Jan 18, 2007 11:29 am

That's what the example code I posted does...

Post Reply