Passing a parameter to a sub routine, is it possible?

Status
Not open for further replies.

patricktran

New Member
Hi,
In the high level programming language, it is easy to pass a parameter to a function, just like: function1(1)

How about in assembly? I think we have to make like this:
Code:
       movlw          d'1'                  ; w = 1, this is our vehicle to pass para
       call               function1

function1                             ; assume w now is our para!!!!!  :shock: 
       ; we can do whatever with w (parameter) at this point
      retfie

However, what happen if we have 2,3,4 parameters? We have only one w though.
 
Use registers/internal RAM for passing parameters. The calling code first writes the parameters in those registers and the function/sub routine retrives it from thos registers/RAM when called.
This is what a "C" compiler does when it converts your C code to assembley.
 
Just a little note to patricktran - In your example the function 'function1' has a RETFIE at the end. RETFIE is intended for returning from interrupts only. A normal subroutine should return with a normal RETURN statement.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…