Updated documentation re: function calls

This commit is contained in:
Curtis F Kaylor 2018-07-20 14:39:36 -04:00
parent f1b2ab3909
commit a7c4dbc309
4 changed files with 23 additions and 18 deletions

1
doc/.~lock.quickref.odt# Normal file
View File

@ -0,0 +1 @@
,LENORE/Curtis,,20.07.2018 14:37,file:///C:/Users/Curtis/AppData/Roaming/LibreOffice/4;

View File

@ -363,7 +363,7 @@ Examples:
aligned char table[240], fbncci[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34};
EXPRESSIONS
An expression is a series of one or more terms separated by operators.
The first term in an expression may be a function call, subscripted array
@ -371,8 +371,8 @@ element, simple variable, literal, or register (A, X, or Y). An expression
may be preceded with a - character, in which case the first term is assumed
to be a literal 0.
Additional terms are limited to subscripted array elements, simple variables,
literals, and constants.
Additional terms are limited to function calls, subscripted array elements,
simple variables, literals, and constants.
Operators:
+ — Add the following value.
@ -391,11 +391,12 @@ not appear anywere a | would.
After an expression has been evaluated, the A register will contain the
result.
Note: Function calls are allowed in the first term of an expression
because upon return from the function the return value will be in the
Accumulator. However, due to the 6502 having only one Accumulatorm which
is used for all operations between two bytes, there is no simple system
agnostic method for allowing function calls in subsequent terms.
Note: Function calls are implemented using LDA, LDY, and LDX to passed
arguments and JSR for the function call itself, which uses two bytes on
the stack. Function calls in the first term of an expression incur no
extra overhead, even when nested. Function calls in any other term, however
require an extra eight bytes of machine code using twenty machine cycles,
as well as one extra byte of the stack.
EVALUATIONS
@ -471,9 +472,11 @@ Examples:
c = t[getc()]; //Get a character, translate using array t and store in c
Note: After a subscripted array reference, the 6502 X register will contain
the value of the index (unless the register Y was used as the index, in
which X register is not changed). When evaluating an expression used as an
index, the Accumulator is tempororaly pushed onto the 6502 stack.
the value of the index (unless a constant, literal, or the Y register was
used as the index, in which X register is not changed). Using an expression
as an array index incurs two extra bytes of machine code totalling five
machine cycles, and uses one byte of stack space (to temporarily store the
accumulator).
STRUCTS

View File

@ -67,12 +67,8 @@ Unary minus may only be used at the beginning of an expression, in which
case it is treated as a literal 0 and the subtraction operater, and the
term following the minus is used as the second term of the expression.
Functions calls may only be used in the first term of an expression.
However, the first argument of any function call may be any expression
(including one with a function call as the first term).
As in standard C, subscripted array elements may be used in any term of
an exptression and the index may be any expression (including one with
an exptression and the index may be any expression (including one with
a function call as the first term).
The sizeof operator in C02 is the at sign @. It may only be used with
@ -81,13 +77,18 @@ declared variables and struct members, not types.
FUNCTIONS
Parameter passing uses the 6502's A, Y, and X registers. This limits
function calls to a maximum of three char variables or address reference
plus and optional char variable. However this also allows the return
function calls to a maximum of three char variables or an optional char
variable plus an address reference. However this also allows the return
of up to three char variables (see assignments below). However, the
non-standard push and pop statements allow explicit parameter passing
via the stack, and the inline keyword has been re-purposed to allow
explicit passing of inline parameters.
Due to this covention, the first char argument of a function call may be
any expression, while the second is limited to a literal, constant,
variable, or array element, and the third is limited to a literal,
constant, or variable.
ASSIGNMENTS
Unlike standard C, struct contents may not be copied via simple assignment.

Binary file not shown.