The set of valid instructions comes from the particular programming language used. There are
many languages, including C, C++, Java, Ada, Lisp, Fortran, Basic, Pascal, Perl, and a thousand
others. The Arduino uses a simplified variation of the C programming language.
For any programming language, the instructions must be entered in a specific syntax in order for
the computer to interpret them properly. Typically, the interpretation is a two step process. A
compiler takes the language specific text you enter for the program and converts it into a
machine readable form that is downloaded into the processor. When the program executes, the
processor executes the machine code line by line.
6.1 Basics of Programming Languages
All sequential programming languages have four categories of instructions. First are operation
commands that evaluate an expression, perform arithmetic, toggle states of I/O lines, and many
other operations. Second are jump commands that cause the program to jump immediately to
another part of the program that is tagged with a label. Jumps are one way to break out of the
normal line-by-line processing mode. For example, if you want a program to repeat over and
over without stopping, have the last line of the program be a jump command that takes the
program back to its first line. Third are branch commands that evaluate a condition and jump if
the condition is true. For example, you might want to jump only if a number is greater than zero.
Or, you might want to jump only if the state of an i/o line is low. Fourth are loop commands that
repeat a section of code a specified number of times. For example, with a loop you can have a
light flash on and off exactly six times.
Most programming languages contain a relatively small number of commands. The complexity
of computers comes from combining and repeating the instructions several million times a
second.
Here's a generic program.
1.
Do this
2.
Do that
3.
Jump to instruction 6
4.
Do the other thing
5.
All done, sleep
6.
If switch closed, do that thing you do
7.
Jump to instruction 4
The computer will execute this line by line. The art of programming is simply a matter of
translating your intent into a sequence of instructions that match.
Here is an example of a for loop command followed by a branch command that uses an IF
statement
for (i=0;i<6,i++) {
instructions
}
14
Need help?
Do you have a question about the uno and is the answer not in the manual?
Questions and answers