Introduction to Assembly Language

If you're reading this, you must be familiar with computer programming, maybe in a language like Java or Python. These languages encourage you to perform a lot work in very few lines of code. The code considered most clever accomplishes the most work with the least code, often with aid of built-in library functionality. Languages like this are considered "high level languages".

By contrast, assembly language has no built in facilities, and accomplishing simple tasks may be many lines of code. Assembly language is considered a "low level language". You have to adjust your thinking to "what is the exact series of steps I have to do to accomplish this task"?

The most important thing to know about assembly language is that each line translates to one processor instruction.

Consider a C statement such as:

int a = b + 100;

In assembly language, you might have to do this in the following steps:

  1. Load the address of the variable B into register #1

  2. Load the contents of that memory address into register #2

  3. Add the immediate value 0x64 to register #2

  4. Load the address of variable A into register #1

  5. Write the contents of register #2 to the address stored in register #1

In code it would look something like this:

   lea    a1, #$1000        ; the address of variable a    
   lea    a2, #$1008        ; the address of variable b    
   move.l d0,(a2)    
   add.l  d0, #$64    
   mov    (a1),d0    

Some things to note:

One thing is similar between clever high level language programmers and assembly jockeys. Assembly programmers take pride in accomplishing a task as efficiently as possible and minimize the number of instructions used. The code for arcade games is usually written with every extra byte and cycle squeezed out of the code.

← Prev: logical-operations   Next: stacks →

Post questions or comments on Twitter @realemulator101, or if you find issues in the code, file them on the github repository.