Assembly Lesson 3
Example:
| label | instruction | operand(s) |
| optional | required | optional |
| var1 | db | "Hello world" |
|
|
add | ax, var2 |
|
|
mov | var1, 67h |
|
|
jmp | label1 |
| bignum | dw | 76899 |
Label - at the front of the assembly language line, usually only used
when defining a variable. Labels are used to define a location, whether it is in
memory or somewhere in your program, to come back to later.
** The only exception to the rule of always having an instructon would be
simple labels, which have no instruction and just mark a location in your
program. They are constructed with the label name (label names have the same
limitations as variable names) followed by a colon. This can be used a jump
point to reference to from other places in the program. **
Instructions - the collection of commands that the assembler can
understand. Knowing the instructions is really all there is to learning
assembly; there are no complex data structures to learn, and your proficiency is
limited only by how many commands you know. Every line in assembly has only one
instruction and does only one thing. An assembly language program is just a list
of things for the computer to do.
operands - the data that the instructions will be performed on. These can
be numeric constants, variables, or registers. In a line that contains more than
one operand, the operation is generally performed on the first one, using the
second one. Looking at the above examples of the mov and add commands, it is the
first operand that receives the change. "mov var1, 67h" places the value of 67
(hex) into the memory location assigned to var1. "add ax, var2" adds the value
of var2 to the value in the ax register. The value in var2 is left
unchanged.
Comments are added to assembly programs with a semicolon. These can be placed
anywhere on a line, and anything following the semicolon will not be read by the
assembler. I recommend commenting your programs liberally, since a typical
program consists mainly of a whole lot of "mov" and "int" commands which can get
very inscrutable very fast. Without functions to break things up, an asm program
is just a long list of very similar commands.
Couple things to remember:
|
|
The only required part of an assembly line is an instruction, sometimes referred to as a directive, that tells the computer what to do. |
|
|
This is the only format allowed for any line in your program, and only one command is allowed per line. You cannot stack commands on one line like you can in C++. |
|
|
Spacing is not very important to assembly. "add ax, bx" would work just as well as "add ax,bx", and likewise with capitalization. I generally keep my commands uniform in lowercase, but "ADD AX,BX" would do the same thing. |