This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to call a C function from assembly

I am writing an ISR using assembly language .
I want to know how to call a C function from assembly.I am using keil compiler and 8051 microcontroller .Reply as soon as possible.

Parents
  • Instead of writing

    LCALL function_name

    I replaced the above with the follwing statement

    LCALL base_address_of_function_name

    like LCALL 0x58DC

    After the above modifications its not giving any syntax error but logical errors i am facing means my code is not working.

    I have put that particular address by seeing in keil compiler tools " code " tab which shows base addresses of all functions.

    After compiling the modified code(I mean converted code)I checked the code tab the base addresses of the functions are changed.

    Now I think u might have got my problem.So what to do?

Reply
  • Instead of writing

    LCALL function_name

    I replaced the above with the follwing statement

    LCALL base_address_of_function_name

    like LCALL 0x58DC

    After the above modifications its not giving any syntax error but logical errors i am facing means my code is not working.

    I have put that particular address by seeing in keil compiler tools " code " tab which shows base addresses of all functions.

    After compiling the modified code(I mean converted code)I checked the code tab the base addresses of the functions are changed.

    Now I think u might have got my problem.So what to do?

Children
  • After the above modifications its not giving any syntax error but logical errors i am facing means my code is not working.

    Simply calling the C function is not enough - your assembly code must also follow the calling conventions for C functions, which are described in the link I posted earlier. It deals with things like:

    * How are the function arguments passed to the function ?
    * How is the return value passed back to the caller ?
    * Which registers have to be saved by the caller, and which are saved by the function ?

    and so on.

  • "LCALL function_name"

    So, presumably, the original syntax error was because the assembler didn't recognise the function_name?

    Did you provide an appropriate EXTERN declaration for function_name?

    If you didn't, how do you expect the assembler to recognise the function name?
    This is exactly the same as if you were calling an external assembler function!!


    "I replaced the above with the follwing statement

    LCALL base_address_of_function_name

    like LCALL 0x58DC"


    You really don't want to do that, do you?

    "After compiling the modified code(I mean converted code)I checked the code tab the base addresses of the functions are changed."

    Of course it did! That's the whole point of using symbolic names, isn't it?!

  • Thanks for ur suggestion.But can u

    then you seem surprised

    So, presumably, the original syntax error was because

    How come?

    the assemble and compiler require correct writing.

    Erik