1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-22 16:34:15 +00:00

Added SELECT/CASE/DEFAULT to documentation

This commit is contained in:
Curtis F Kaylor 2018-02-05 22:40:00 -05:00
parent 459ef1b197
commit cd21e60f9a
2 changed files with 706 additions and 658 deletions

View File

@ -108,7 +108,7 @@ A binary number consists of a % followed by eight binary digits (0 or 1).
A decimal number consists of one to three decimal digits (0 through 9).
A hexadecimal number consists of a $ followed by two hexadecimal digits
(0 throuth 9 or A through F).
(0 through 9 or A through F).
A character literals consists of a single character surrounded by ' symbols.
A ' character may be specified by escaping it with a \.
@ -347,12 +347,13 @@ variable name with the address-of operator &. To pass a string, simply
specify the string as the argument.
Examples:
c = getchr(); //Get character from keyboard
c = getc(); //Get character from keyboard
n = abs(b+c-d); //Return the absolute value of result of expression
m = min(r[i], r[j]); //Return lesser of to array elements
l = strlen(&s); //Return the length of string s
p = strchr(c, &s); //Return position of character c in string s
putstr("Hello World"); //Write "Hello World" to screen
putc(getc()); //Echo typed characters to screen
puts("Hello World"); //Write "Hello World" to screen
Note: This particular argument passing convention has been chosen because
of the 6502's limited number of registers and stack processing instructions.
@ -373,7 +374,7 @@ to a function call. When using a push statement, it is followed by one or
more arguments, separated by commas, and terminated with a semi-colon. An
argument may be an expression, in which case the single byte result is
pushed onto the stack, or it may be an address or string, in which case the
address is pushed onto the string, high byte first and low byte second.
address is pushed onto the stack, high byte first and low byte second.
The pop statement is likewise used to pop arguments off of the machine
stack after a function call. When using a pop statement, it is followed
@ -512,9 +513,48 @@ Note: In order to optimize the compiled code, the if and else statements
are to 6502 relative branch instructions. This limits the amount of
generated code between the if statement and the end of the if/else block
to slightly less than 127 characters. This should be sufficient in most
cases, but larger code blocks can be accomodated using function calls or
cases, but larger code blocks can be accommodated using function calls or
goto statements.
SELECT, CASE, AND DEFAULT STATEMENTS
The select, case, an default statements are used to execute a specific
block of code depending on the result of an expression.
When using the select keyword, it is followed by an expression (surrounded
by parenthesis) and an opening curly brace, which begins the select block.
This must then be followed by a case statement.
Each use of the case keyword is followed by term and a colon. If the
term is equal to select expression then the code immediately following
the is executed, otherwise, program execution transfers to the next
case or default statement.
The code between two case statements or a case and default statement is
called a case block. At the end of a case block, program execution
transfers to the end of the select block (the closing curly brace at
the end of the default block).
The last case block must be followed by a default statement. When using
the default keyword, it is followed by a colon. The code between the
default statement and the end of the select block (marked with a closing
curly-brace) is called the default block and is executed if none of
the case arguments matched the select expression.
Example:
puts("You pressed ");
select (getc()) {
case $0D: putln("The Enter key");
case ' ': putln("The space bar");
case ltr: putln("The character in variable 'ltr'");
case s[2]: putln("The third character of string 's'");
default: putln("some other key");
}
Note: It's possible for multiple case statement arguments to evaluate to
the same value. In this case, only the first case block matching the
select expression will be executed.
WHILE LOOPS
The while statement is used to conditionally execute code in a loop. When
@ -531,7 +571,7 @@ Examples:
while() if (rdkey()) break; //Wait for a keypress
Note: While loops are compiled using the 6502 JMP statements, so the code
blocks may be abritrarily large.
blocks may be arbitrarily large.
DO WHILE LOOPS

View File

@ -7,7 +7,8 @@ C02 only supports one data type: unsigned char.
POINTERS
C02 does not support pointer type variables or parameters. However, the
address-of operator may be used in function calls.
address-of operator may be used in function calls and the inline
statement.
DECLARATIONS
@ -28,3 +29,10 @@ EXPRESSIONS
C02 supports the addition, subtraction, bitwise-and, bitwise-or, and
exclusive-or operators. The multiplication, division, and binary shift
operators are not supported. These can be implemented through functions.
STATEMENTS
Instead of the switch statement, C02 uses the select statement. The
select statement works almost identically to the switch statement except
that case blocks do not fall through and the break statement does not
exit a case block.