Page 34 - DCAP210_INTRODUCTION__TO_MICROPROCESSORS
P. 34
Introduction to Microprocessors
Notes If the address of PTR had been greater than LC+2 +510 or less than LC+2 –512, then the offset
would not fit in bits [8:0] of the instruction. In such a case, an assembly error would have occurred,
preventing the assembly process from completing successfully. Fortunately, PTR is close enough
to the LEA instruction, so the instruction assembled correctly.
The second pass continues. At each step, the LC is incremented and the location specified by LC
is assigned the translated LC-3b instruction or, in the case of .FILL, the value specified. When the
second pass encounters the .END instruction, assembly terminates.
That process was, on a good day, merely tedious. Fortunately, you do not have to do it for a
living; the LC-3b assembler does that. And, since you now know LC154 3b assembly language,
there is no need to program in machine language. Now we can write our programs symbolically
in LC-3b assembly language and invoke the LC- 3b assembler to create the machine language
versions that can execute on an LC-3b computer.
2.3 Assembly Language Statements
Assembly language statements in a source file use the following format:
{Label} {Mnemonic {Operand}} {Comment}
Each entity above is a field. The four fields above are the label field, the mnemonic field, the
operand field, and the comment field.
The label field is (usually) an optional field containing a symbolic label for the current statement.
Labels are used in assembly language, just as in HLLs, to mark lines as the targets of GOTOs
(jumps). You can also specify variable names, procedure names, and other entities using symbolic
labels. Most of the time the label field is optional, meaning a label need be present only if you
want a label on that particular line. Some mnemonics, however, require a label, others do not
allow one. In general, you should always begin your labels in column one (this makes your
programs easier to read).
A mnemonic is an instruction name (e.g. move, add, etc.). The word mnemonic means memory aid.
Move is much easier to remember than the binary equivalent of the mov instruction! The braces
denote that this item is optional. Note, however, that you cannot have an operand without a mnemonic.
The mnemonic field contains an assembler instruction. Instructions are divided into three classes:
80x86 machine instructions, assembler directives, and pseudo-opcodes.
Assembler directives are special instructions that provide information to the assembler but do
not generate any code. Examples include the segment directive, equal, assume, and end. These
mnemonics are not valid 80x86 instructions. They are messages to the assembler, nothing else.
A pseudo-opcodes is a message to the assembler, just like an assembler directive, however a
pseudo-opcodes will emit object code bytes. Examples of pseudo-opcodes include byte, word,
dword, qword, and bytes. These instructions emit the bytes of data specified by their operands
but they are not true 80X86 machine instructions.
The operand field contains the operands, or parameters, for the instruction specified in the
mnemonic field. Operands never appear on lines by themselves. The type and number of operands
(zero, one, two, or more) depend entirely on the specific instruction.
The comment field allows you to annotate each line of source code in your program. Note that
the comment field always begins with a semicolon. When the assembler is processing a line of
text, it completely ignores everything on the source line following a semicolon.
Each assembly language statement appears on its own line in the source file. You cannot have
multiple assembly language statements on a single line. On the other hand, since all the fields in
an assembly language statement are optional, blank lines are fine.
28 LOVELY PROFESSIONAL UNIVERSITY