Assembly Language

Assembly Language

Programming Your Robot

It is generally accepted that there are three types or levels of computer programming languages; Machine Code, Assembly Language and High level languages. (Although some authors and texts reduce these to two: 1. Machine Code and Assembly, and 2. High Level Languages.) Here are some examples:

Machine Code

Machine code is the "Native" language of the CPU that is running the program. The instructions are binary numbers composed on 8, 16 or more bits that when fed to the CPU provide Opcodes (What command is requested), Operands (more information that specifies how much, or where information), and other information.

A small 8-bit machine code program might look something like this:

10001010
01100011
10001101
11001111

As you can see, without the "Secret Decoder Ring" that comes with the CPU, this seems like gibberish and has no meaning. Also, remembering the sequences of ones and zeros as specific commands is close to impossible for our human minds. But, this is the language the CPU needs to see, so all of the languages below must be converted to machine code before they can run on a particular chip.

Assembly Language

Because of the difficulty in reading and remembering machine code, assembly code was invented to make commands more meaningful and readable to us humans. Here is a short assembly code program, similar to the assembly in the Motorola 68HC11 chip that adds the numbers 7 and 10 and stores the result in memory location 252:

LDAA 07
ADDA 0A
STAA 00 FC
Stop

Translated, this is…

LDAA 07 = Load Accumulator A with the number 7

ADDA 0A = Add to accumulator A the number 10 (0A is hexadecimal for decimal 10)

STAA 00 FC = Store what is in Accumulator A at memory location 00FC. Since the address bus in the 68HC11 is 16 bits, we need to specify a 16 bit address. The number 252 in 16 bit binary is 00000000 11111100, when converted to hex is 00FC.

Stop = End the program

So this language is a great improvement. It doesn’t take long for the programmer to remember that LDAA is “Load Accumulator A” and STAA means “Store Accumulator A at —” and so on. Assembly languages tend to have as little as 30 instructions to upwards of 250 instructions, depending on the hardware. But a programmer working every day in assembler soons learns all of the common commands and has a "Cheat Sheet" handy for seldom used or forgotten commands.

High-Level Languages

You have probably heard the names of some high-level languages. They have names like COBOL, Fortran, C++ (pronounced Sea-Plus-Plus), Visual Basic, C# (pronounced C Sharp), RPG, Perl, PHP, ASP and there are many others. Most robotics chips allow the use of the C language or some form of Basic. Here is the source code in C and Basic for a program that prints the numbers from 1 to 10:

In Basic, the source code would look something like:

Dim i as Integer
For i = 1 to 10

   Print i
Next

And in the C language:

int i;

for(i = 1; i<=10; ++i)

   printf(“%d”, i);


So, this code looks a little strange, but when you are taught that loops that do something over and over are formed like the above, you soon learn the syntax of the language you are using.