-
Notifications
You must be signed in to change notification settings - Fork 2
Further Syntax
The input instruction is used to incorporate further source files into the program. The syntax is:
import "sys/stdio.asm"
import "sys/comm.c"
import "myfile.c"
The file extension ('c' or 'asm') must also be specified, as well as the pathname (like 'sys/' or 'lib/'). A program can be structured in several files. In this case the "main" file has to import the other files.
A comment starts with a slash asterisk /*
and ends with a asterisk slash */
and can be anywhere in your program.
Comments can span several lines within your program.
The compiler supports also single line comments. All characters after the //
slashes are ignored by the compiler.
/*
* this is a comment
*/
// this is a comment
func init() {
}
/* this is a comment */
func loop() { // this is also a comment
}
Used to end a statement.
Example
var a = 13;
Notes and Warnings
Forgetting to end a line in a semicolon will result in a compiler error. The error text may be obvious, and refer to a missing semicolon, or it may not. If an impenetrable or seemingly illogical compiler error comes up, one of the first things to check is a missing semicolon, in the immediate vicinity, preceding the line at which the compiler complained.
Curly braces (also referred to as just "braces" or as "curly brackets") are a major part of the mC programming language. They are used in several different constructs, outlined below, and this can sometimes be confusing for beginners. An opening curly brace { must always be followed by a closing curly brace }. This is a condition that is often referred to as the braces being balanced.
Unbalanced braces can often lead to cryptic, impenetrable compiler errors that can sometimes be hard to track down in a large program. Because of their varied usages, braces are also incredibly important to the syntax of a program and moving a brace one or two lines will often dramatically affect the meaning of a program.
The main uses of curly braces are listed in the examples below.
Functions
func myfunction(argument) {
// any statement(s)
}
Loops
while (boolean expression) {
// any statement(s)
}
for (initialisation; termination condition; incrementing expr) {
// any statement(s)
}
Conditional Statements
if (boolean expression) {
// any statement(s)
}
else if (boolean expression) {
// any statement(s)
}
else {
// any statement(s)
}
The compiler allows inline assembler.
Example for a function with ASM code.
func time_slot(cycle) {
_asm_ {
move A, [SP+1]
add A, #1
xor A, [SP+1]
msb A, A
dec A
}
}
- The return value must be provided in register
A
(the instructionret
is provided by the C function framework) - For a function
foo(a)
, parametera
is on stack position[SP+1]
- For a function
foo(a, b)
, the parametera
is on the stack position[SP+2]
and the parameterb
is on the stack position[SP+1]
- For a function
foo(a,b,c)
, the parametera
is on the stack position[SP+3]
, the parameterb
is on the stack position[SP+2]
and the parameterb
is on stack position[SP+1]