Chapter 11. Built-in Functions

JALv2 attempts to be a minimal language with most complex operations done with sub-programs, however some functions simply cannot be efficiently supported externally.

11.1. Multiplication, Division, Modulus Division

Multiplication, Division, and Modulus Division are internal mainly because there is no way to predetermine the size of the operands. Note that unlike the other operators which are done inline, these are function calls and require one stack entry when used!

A second reason for having these built in is the optimizer -- when a multiplication or division by 1 is done, the operation is ignored. When a multiplcation or division by a power of two is done, the resulting code is performed using shifts instead.

For both of these operations, the code generated will be that required for the largest operands unless -fastmath is passed to the compiler.. For example, if the operation occurs only between two BYTEs, the 8-bit routine will be generated. If it occurs between BYTEs and WORDs, the 16-bit routine will be generated.

If -fastmath is used, a different function will be generated for each argument type.

The compiler keeps track of the last operation, so if you find yourself needing both the division result and the remainder of, a certain operation, make sure to put the assignments close together, thus saving a function call:


        n = x / 10
        r = x % 10
      
will only result in one call to the division -- the assignment to r will be a simple assignment.