Load function in assembly

If I have the address of particular function, is it possible load the function in assembly?

I understand that usually the function is loaded as

LCALL _function

but I was wondering whether it is possible to load the function with its address?

Appreciate anyone who can offer me advise on this. Thank you.

Parents
  • Can you clarify your question? Do you mean that you want to call a function in assembly language when you only have the address of the function to be called stored in a variable or registers?

    It is possible to use something like the (untested) code below. Basicly, the return address and the function pointer are loaded onto the stack and then a RET instruction causes the CPU to pop the address of the function pointer into the PC. When the function executes a RET, the return address will be popped into the PC and the CPU will be back at return_address.

        MOV     A,#LOW(return_address)
        PUSH    Acc
        MOV     A,#HIGH(return_address)
        PUSH    Acc
        MOV     A,function_pointer_low
        PUSH    Acc
        MOV     A,function_pointer_high
        PUSH    Acc
        RET
    retern_address:
        ....
    

Reply
  • Can you clarify your question? Do you mean that you want to call a function in assembly language when you only have the address of the function to be called stored in a variable or registers?

    It is possible to use something like the (untested) code below. Basicly, the return address and the function pointer are loaded onto the stack and then a RET instruction causes the CPU to pop the address of the function pointer into the PC. When the function executes a RET, the return address will be popped into the PC and the CPU will be back at return_address.

        MOV     A,#LOW(return_address)
        PUSH    Acc
        MOV     A,#HIGH(return_address)
        PUSH    Acc
        MOV     A,function_pointer_low
        PUSH    Acc
        MOV     A,function_pointer_high
        PUSH    Acc
        RET
    retern_address:
        ....
    

Children
More questions in this forum