How Assembly Language is Used

../../_images/assembly-diag1.png

Upon examining the contents of read-only memory or program random-access memory, a program would appear as a sequence of hexaaecimal digits which are interpreted by the machine as instruction codes, addresses, or constant data.

It is possible to write a program as a sequence of digits (just as they appear in memory), but that is slow and expensive.

For example, in the example to the right, several instructions reference memory to address another instructions.

The example program works as follows:

  • Byte 0x332 specifies that the accumulator and carry bit are to be cleared.

  • Bytes 0x333 and 0x334 specify that program execution is to continue at location 0x356.

  • Byte 0x356 specifies that register 0 is to be incremented.


Now suppose that an error discovered in the program logic necessitates placing a new instruction after byte 0x332. Program code would have to change as follows:

../../_images/assembly-diag2.png

Many instructions have been moved and as a result some must be changed to reflect the new addresses of instructions. The potential for making mistakes is very high and is aggravated by the complete unreadability of the program.
Writing programs in assembly language is the first and most significant step towards economical programming; it provides a readable notation for instructions, and separates the programmer from a need to know or specify absolute memory addresses.
Assembly language programs are written as a sequence of instructions which are converted to executable hexadecimal code by a special program called an Assembler

../../_images/assembly-diag3.png

As illustrated above, the assembly language program generated by a programmer is called a SOURCE PROGRAM. The assembler converts the SOURCE PROGRAM into an equivalent OBJECT PROGRAM, which consists of a sequence of hexadecimal codes that can be loaded into ROM or program RAM and executed.

For example:

../../_images/assembly-diag4.png

If a new instruction must be added, only one change is required. Even the reader who is not yet familiar with assembly language will see how simple the addition is:

../../_images/assembly-diag5.png

The assembler takes care of the fact that a new instruction will shift the rest of the program in memory.