Assembler Source Statement Label Field
Assembler Source Statement Label Field
knowledge, and it's slow to write. In the same time that you take to write ten
lines of assembly language- that's ten instructions, you could write ten lines of
C++, perhaps the equivalent of 500 instructions!
main()
{
int a = 1; int b = 2; int c;
__asm{
mov eax, a ;// Load the value of the a variable into the EAX register
mov ebx, b ;// Load the value of the b variable into the EBX register
add eax, ebx ;// Add EAX to EBX, and write the result into EAX
mov c, eax ;// Load the EAX value into the c variable
}
printf("a + b = %x + %x = %x\n",a,b,c);
}
An assembler is a translator that translates source instructions (in symbolic language) into target
instructions (in machine language), on a one to one basis.
The assembler performs the following primary functions:
A typical source line has four fields. A label (or a location), a mnemonic (or operation), an operand,
and a comment. There are four fields in a source statement, listed here in the order in which
they must appear on a source statement:
1. Label Field 2. Operation Field 3. Operand Field 4. Comment Field
The general syntax for source statements is as follows:
[label [:] ] operation [operands] [; comment]
The operand field of an assembly language statement supplies the arguments to the machine
instruction, assembler directive, or macro.
The operand field may contain one or more operands, depending on the requirements of the
preceding machine instruction or assembler directive. Some machine instructions and assembler
directives don't take any operand, and some take two or more. If the operand field contains more
than one operand, the operands are generally separated by commas, as shown here: operand
[ , operand ] ... ]
Comment Field
The comment field is optional; if used, it contains a comment. Comments are introduced with
the comment character ( ;). After the comment character, any string of ASCII text characters
may be coded (except newline, which delimits source statements). The comment character
may optionally be separated from a preceding field by coding whitespace characters. If there
are no preceding fields, the comment character may be specified in the first column, or it
may be preceded by whitespace.
Assembler Constants
The assembler constant is a self-defining term whose value is specified explicitly. The
assembler supports four kinds of constant:
Types of assembler
A One-pass Assembler: One that performs all its functions by reading the sourcefile once.
A Two-Pass Assembler: One that reads the source file twice.
A Resident Assembler: One that is permanently loaded in memory. Typically such an assembler
resides in ROM, is very simple (supports only a few directives and no macros), and is a one-pass
assembler.
A Macro-Assembler: One that supports macros
A Cross-Assembler: An assembler that runs on one computer and assembles programs for another.
Many cross-assemblers are written in a higher-level language to make them portable. They run on a
large machine and produce object code for a small machine.
A Meta-Assembler: One that can handle many different instruction sets.
A Disassembler: This, in a sense, is the opposite of an assembler. It translates machine code into a
source program in assembler language.
A one pass assembler passes over the source file exactly once, in the same pass collecting the labels,
resolving future references and doing the actual assembly. The difficult part is to resolve future label
references and assemble code in one pass.