Parallax Propeller Book - Definitions

Some specific terms are used both by PARALLAX and in this e-book, so we need to define them and you need to fully understand what they mean.

Spin

Spin is an object-based programming language used exclusively by the PARALLAX Propeller chips. 

For more details click this link:


Application

Application is the entire program for specific function(s) performed by the microcontroller.

After the Application is loaded into the Propeller chip, it loads an interpreter into Cog0 (Cog "Zero"), and this interpreter starts executing Spin code tokens stored in main memory.

Commands in the Spin code can then launch blocks of code (which might be Spin or Assembly language) into other Cogs.

Code executed by the other Cogs can launch still other Cogs regardless of whether they are Spin or Assembly, and both languages can also stop other Cogs for the sake of ending unnecessary processes or even replacing them with different ones.


Object

Objects are designed to be the building blocks of an Application, and each .spin file can be considered to be an independent Object.

While Application can be developed as a single Object (one program), Applications are more commonly a collection of several Objects.

The first Spin Object is called the top object file.

This file has the first executable line of code where the Propeller chip starts when the Application initializes to run.

In every case, Cog0 (Cog "Zero") is launched and begins executing code from the top object.

Objects can be written to use just one Cog, or can include code that gets launched into one or more additional Cogs.

Some Objects have Methods that provide a means to exchange information with processes running in other Cogs.

One Object can even make multiple copies of another Object, and set each one to a different task.

Objects can use other Objects, which in turn can use still other Objects.

In more complex Applications, a set of Objects will form functional relationships that can be viewed as a file structure with the Propeller Tool’s Object Info window.


Method

Method is a block of executable Spin commands that has a name, access rule, and can optionally create local (temporary) Variables, receive parameters, and return a value.

A Method is similar to a subroutine in other languages.

A Method is a section of source code that accepts parameters as input, performs a specific function, and then returns a result value.

Methods in Spin are declared with PUB, for public methods, and PRI, for private methods.

There must be at least one public method in every Spin object.

Propeller Application execution begins with the first public method PUB in the application’s top object.

Spin Methods are like subroutines in that they contain the instructions to perform a specific process, and can be used over and over again as needed.

Unlike subroutines in languages like PBASIC, Methods can be passed parameters; that is, a set of temporary values that are used in the execution of that instance of the subroutine, without having to define variables or constants globally in the program.


Global and Local variables

Global variables are available to all the Methods in a given Object, and they reserve variable space as long as an Application is running.

Local variables are defined in a Method, can only be used within that Method, and only exist while that Method executes commands. When it’s done, the memory these local variables used becomes available to other Methods and their local variables.

Local and Global variables are defined with different syntax.


Variable declarations and types

There are three options for variable declarations in Spin:

Byte
it can store a value from 0 to 255 and consists of 8 Bits from "00000000" which is equal to decimal "0" (zero) to "11111111" which is equal to decimal 255. (28)

Word
(0 to 65,535) is equivalent to two Bytes and consists of 16 Bits from minimum of "0000000000000000", which is equal to decimal "0" (zero) to "1111111111111111", which is equal to decimal 65,535. (216)

Long (-2,147,483,648 to 2,147,483,647) is equivalent to four Bytes and consists of 32 Bits from minimum of "00000000000000000000000000000000", which is equal to decimal -2,147,483,648 to "11111111111111111111111111111111", which is equal to decimal 2,147,483,647. That is one of (232) possible combinations of bits (i.e., one of 4,294,967,296 combinations).

The Spin language performs all mathematical operations using 32-bit signed math, meaning every long value is considered to be in the range  - 2,147,483,648 to +2,147,483,647.

However, the actual numeric value contained within a long is subject to how a computer and user interpret it.

In Propeller Assembly a long value can be treated as both signed and unsigned.


Links to related Webpages

Click the link in the list below to navigate to a detailed webpage about the listed subject.


Parallax Propeller Book - Table fo Content