Assembly Language Programming

This article discusses assembly language programming syntax.

An assembly statement consists of up to four fields. They are:

[label[:]] [operation-code-specification {operand(s) separated by commas}] [;comment]

where [] surround optional fields (and the optional colon in the label field). The only field not

optional is the operand(s) field and its existence and number of elements depends on the operation code (opcode) field. It does not (must not) exist for many instructions. The label field provides a symbolic handle for the information specified on that and possibly succeeding lines. It is used to assign names to program variables, constants, and the beginning of sections of code that need a name. Code sections that need names include subroutines, beginnings of loops, or parts of if-then-else style program constructs. The opcode field can specify either a machine instruction or it can be a command to the assembler. In the later case it is usually referred to as a pseudo opcode or pseudo-op for short.

These assemblers have only a handful of pseudo-ops, but 120 machine instruction mnemonics. The opcode field dictates the number of operands that can be present (if any). Any of these fields may appear on a line by itself except the operands field which must exist on the same line as the opcode with which it is connected. If a label is not followed by the optional colon it must start in column 1. Other than that the fields are in a free format. Any amount of white space may appear between fields. No field can contain white space except the comment field and the operand field when it is a quoted string. No statement, in and of itself, requires a label, but we will see programming situations that will necessitate labels.

You should try to identify those situations in the following assembly language programs which are rewrites of the previously presented machine language examples.