Assembly Language

Lecture Notes

Dominique Thiébaut

Week of Nov 18th, 1996

In these two lectures we look at how a processor executes programs in its simplest form.

The first thing to realize is that everything inside the computer is binary. It's all represented by bits that can be ON or OFF, 1 or 0.

The memory can be thought of as a tall array of cells. The cells are referred to as memory cells, or memory words.

Each cell is numbered, and the number is called the address of the cell. The numbering system goes from 0 to a very large number. This number is directly related to the size of the memory. If you have a PC with 8 Megabytes of Random Access Memory (RAM), then your memory contains roughly 8 million cells, each with its own address: 0, 1, 2, 3, 4, .... 8,000,000 (in reality it's 8,388,608 which corresponds to 2^23).

In order for the processor to access memory and either store or read information from it, it needs a collection of wires to attach it to the memory. There are two main such "collections" of wires. They are called buses. One is referred to as the address bus, the other one as the data bus.

The address bus allows the processor to send a number to the memory. This number, made of 1s and 0s represents the address of a cell the processor needs wants to access. When the memory receives this address, a series of decodes (electronic circuits made of and, or and not gates) selects the cell whose address matches the number on the address bus, and dumps the contents of the cell onto the second bus. This second bus, the data bus, brings the information to the processor, where it is "processed."

What type of information will we find flowing on the data bus? Binary information. Just bits! For the processor to do something meaningful, we need to "code" this information. One way to do that is to specify patterns of 1s and 0s to mean something specific to the processor. We will refer to them as instructions.

Instructions tell the processor to perform simple operations:

  1. fetch some data from memory and bring it into the processor
  2. add two numbers together and store the result somewhere
  3. subtract a number from another number and store the result somewhere
  4. multiply two numbers together
  5. etc...

For the processor to be able to deal with numbers stored in the memory, in needs places to hold these numbers in.  These places are called registers.

We will write program for a simple processor modeled after the Pentium processor. This processor does not exist because it is too simple by today's standards, but it is sophisticated enough for us to write small programs that will give us a very precise idea of what real processors do.

Our simplified processor contains 4 data registers, or general purpose registers: AX, BX, CX, and DX. One index register, SI, one instruction pointer register IP, and two flag bits, LessThan and Equal (more on them later!)

The IP register
The IP register contains the address of the instruction the processor is about to execute. Every time the processor
needs to execute an instruction, it dumps the contents of IP on the address bus. This makes the memory react by
sending to the processor the word whose address in is IP. As soon as the processor has obtained the instruction, it
increments IP by one. This is a very simple mechanism. The processor is a machine that scans the memory
sequentially, fetching cells that are contiguous, one after the other. IP gets incremented every time by one, creating this
sequential access to memory cells.
The Data Registers
The Data registers, AX, BX, CX, and DX, allow the processor to store information locally temporarily. It is much
easier (and faster) for the processor to access information in registers than in memory, so the most recently used
information will be kept in data registers.
The Index Register
The Index register is used to access data in memory. We'll see how it comes into play when we look at instructions more closely.

Instructions

The simplified processor supports the following instructions:

Arithmetic Instructions
The arithmetic instructions, ADD, SUB, MUL and DIV are used to perform arithmetic operations.
Control Instructions
JMP, JNE, JE, JLE, JLT, JGT, JGE are jump instructions.  JMP is an unconditional jump and will force the processor
to jump to a specific address int memory.  The other instructions are conditional jumps and perform a jump only if the
Equal and LessThan flags are set accordingly (you'll see more about this in the lab).
Comparison Instructions
We only have one such instruction: CMP. It compares two operands and sets the Equal and LessThan flag according
to the result of the comparison.
Loop instruction
The LOOP instruction allows the processor to repeat a group of instructions a fixed number of times.
Move instructions
The LOAD and STORE instructions allow the processor to move information from one place to another in the
computer, without modifying the information.

Stay tune for examples of small demo programs utilizing the above instructions!