Getting Down with ...

by ...

Lesson n:

Now that we have marked the “drawers” that we will store our data in, we get to move on to the code itself! But before we can write our own code, we need to understand how to order the code.

Like most high-level programming languages, code is executed in a linear order downward through the text until instructed to stop, jump or loop back to another part of the program. Fortunately for us, assembly language is also structured this way. So every command you enter will be executed in the order of the line it is written on. Let’s look at the ways we can break the linear order of execution.

HLT
Halt: This command is self-explanatory. It terminates the program. This command should be placed at the end of any process that would continue perpetually or loop infinitely. By the end of the program, the variables will be changed if any commands acted on them.
JMP

Jump: This command is how you move to different lines of code based on a condition. The JMP command is similar to an if statement in other languages. Unlike an if command however, you cannot define your own condition with a JMP statement. There are several ways to utilize this command, but each requires its own unique version of the command. For example:

  • JMP: Jumps to the stated location and presents no condition.
  • JZ: Jumps to the stated location if the value in the accumulator is zero.
  • JP: Jumps to the stated location if the value in the accumulator is positive.
  • JM: Jumps to the stated location if the value in the accumulator is negative.

Exercises: