1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2025-02-21 19:29:03 +00:00

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}; aligned char table[240], fbncci[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34};
EXPRESSIONS EXPRESSIONS
An expression is a series of one or more terms separated by operators. 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 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 may be preceded with a - character, in which case the first term is assumed
to be a literal 0. to be a literal 0.
Additional terms are limited to subscripted array elements, simple variables, Additional terms are limited to function calls, subscripted array elements,
literals, and constants. simple variables, literals, and constants.
Operators: Operators:
+ — Add the following value. + — 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 After an expression has been evaluated, the A register will contain the
result. result.
Note: Function calls are allowed in the first term of an expression Note: Function calls are implemented using LDA, LDY, and LDX to passed
because upon return from the function the return value will be in the arguments and JSR for the function call itself, which uses two bytes on
Accumulator. However, due to the 6502 having only one Accumulatorm which the stack. Function calls in the first term of an expression incur no
is used for all operations between two bytes, there is no simple system extra overhead, even when nested. Function calls in any other term, however
agnostic method for allowing function calls in subsequent terms. require an extra eight bytes of machine code using twenty machine cycles,
as well as one extra byte of the stack.
EVALUATIONS EVALUATIONS
@ -471,9 +472,11 @@ Examples:
c = t[getc()]; //Get a character, translate using array t and store in c 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 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 the value of the index (unless a constant, literal, or the Y register was
which X register is not changed). When evaluating an expression used as an used as the index, in which X register is not changed). Using an expression
index, the Accumulator is tempororaly pushed onto the 6502 stack. 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 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 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. 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 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). a function call as the first term).
The sizeof operator in C02 is the at sign @. It may only be used with 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 FUNCTIONS
Parameter passing uses the 6502's A, Y, and X registers. This limits 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 function calls to a maximum of three char variables or an optional char
plus and optional char variable. However this also allows the return variable plus an address reference. However this also allows the return
of up to three char variables (see assignments below). However, the of up to three char variables (see assignments below). However, the
non-standard push and pop statements allow explicit parameter passing non-standard push and pop statements allow explicit parameter passing
via the stack, and the inline keyword has been re-purposed to allow via the stack, and the inline keyword has been re-purposed to allow
explicit passing of inline parameters. 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 ASSIGNMENTS
Unlike standard C, struct contents may not be copied via simple assignment. Unlike standard C, struct contents may not be copied via simple assignment.

Binary file not shown.