Functionals

This essay deals with indirect calls. These are the core of an enormous number of high level languages: LISP's closures, C's function pointers, C++ and Java's virtual method calls, and some implementations of the switch statement.

These techniques vary in complexity, and most will not be appropriate for large-scale assembler projects. Of them, however, the Data-Directed approach is the most likely to lead to organized and maintainable code.

Function Pointers

Because assembly language is totally untyped, function pointers are the same as any other sixteen-bit integer. This makes representing them really quite easy; most assemblers should permit routines to be declared simply by naming the routine as a .word directly.

To actually invoke these methods, copy them to some sixteen-bit location (say, target) and then invoking the method is a simple matter of the using an indirect jump: the JMP (target) instruction.

There's really only one subtlety here, and it's that the indirect jump is an indirect jump, not an indirect function call. Thus, if some function A makes in indirect jump to some routine, when that routine returns, it returns to whoever called A, not A itself.

There are several ways of dealing with this, but only one correct way, which is to structure your procedures so that any call to JMP (xxxx) occurs at the very end.