millfork

Millfork: a middle-level programming language targeting 6502- and Z80-based microcomputers and home consoles

This project is maintained by KarolS

< back to index

Function definitions

Syntax:

[segment (<segment>)] [<modifiers>] <return_type> <name> ( <params> ) [align ( <alignment> )] [<optimization hints>] [@ <address>] { <body> }

[segment (<segment>)] [<modifiers>] <return_type> <name> ( <params> ) [align ( <alignment> )] [<optimization hints>] [@ <address>] = <expression>

[segment (<segment>)] asm <return_type> <name> ( <params> ) [<optimization hints>] @ <address> extern

Examples:

void do_nothing() { }
inline byte two() = 2
asm void chkout(byte register(a) char) !preserves_x !preserves_y @ $FFD2 extern
segment(prgrom0) void main_loop(word w, byte x) align(fast) { // body omitted

The address of a non-macro function f is a constant f.addr.

Non-macro, non-interrupt functions which have max one parameter of size max 2 bytes and return void or a value of size max 2 bytes, can be accessed via a pointer.

void f() {}
void g(byte x) {}

function.void.to.void p = f.pointer
function.byte.to.void p = g.pointer

call(p)
call(p, 13)

The value of the pointer f.pointer may not be the same as the value of the function address f.addr.