简体   繁体   中英

Calling a procedure by pointer from variable in Intel 8086 Assembly

Let's say I have a variable with procedure address:

func_pointer dw offset my_function

my_function proc near

my_function endp

How can I call it from the variable?

I have tried

call dword ptr[func_pointer + 1]

but it does not seem to work.

All you need to do is use call func_pointer or call [func_pointer] (they're both the same to MASM). Because the type of the symbol func_pointer is WORD the assembler knows to use an indirect call rather than a direct call.

For example:

_TEXT   SEGMENT PUBLIC USE16
    ASSUME DS:_TEXT

func_pointer dw offset my_function

my_function proc near
    ret
my_function endp

caller proc
    call [func_pointer]
caller endp

_TEXT   ENDS

    END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM