ASSEMBLERS

7.3 ASSEMBLERS

The assembler (or the cross-assembler), as defined before, is a program that trans­lates assembly language mnemonics or source code into binary executable code. Here, we are using the term assembler to include all the utility programs (such as Assembler and Linker) necessary for the assembly process. This translation pro­cess requires that the source program be written strictly according to the specified syntax of the assembler. The assembly language source program includes three types of statements:

1. The program statements in Z80 mnemonics, which are to be translated into binary code.

2. Comments, which are reproduced as a part of the program documentation.

3. Directives to the assembler that specify such items as starting memory loca­tions, label definitions, and required memory spaces for data.

The first two types of statements have been used in the program of adding two Hex numbers in the last chapter. The format of these statements as they appear in an assembly language source program is identical to the format used here. The third type-directives-and their functions will be described in Section 7.3.2.

7.3.1 Assembly Language Format

A typical assembly language programming statement is divided into four parts, called fields: label, operation code (opcode), operand, and comments. These fields are separated by delimiters as shown in Table 7.1.

The assembler statements have a free-field format, which means that any number of blanks can be left between fields. Comments are optional but are gen­erally included for good documentation. A label for an instruction is also optional,

Untitled-24_03

7.3.2 Assembler Directives

The assembler directives are the instructions to the assembler concerning the pro­gram being assembled; they are also called pseudo operations or pseudo-ops, these instructions are neither translated into machine code nor assigned any memory locations in the object file. Some of the important assembler directives for the Z80 assembler are listed and described here.

Assembler Directives

Example

Description

1.ORG (Origin)

ORG 0100H

The next block of instruc­tions should be stored in memory locations starting from 0100H.

2.END

END

End of assembly. The HALT instruction sug­gests the end of a pro­gram, but that does not necessarily mean the end of assembly.

3. EQU

(Equate)

PORT1 EQU 01H

The value of the term PORT1 is equal to 01H. Generally, this means the PORT1 has the port ad­dress 01H.

INBUF EQU 1899H

The value of the term INBUF is 1899H. This may be the memory loca­tion used as input buffer.

OUTBUF EQU INBUF + 4

The equate can be ex­pressed by using the label of another equate. This example defines the OUTBUF memory location in terms of INBUF.

4.DB or DEFB (Define Byte)

DATA: DEFB A2H, 9FH

Initializes an area byte by byte, in some assemblers either symbol (DB or DEFB) can be used. As­sembled bytes of data are stored in successive mem­ory locations until all val­ues are stored. This is a convenient way of writing a data string. The label is optional.

5. DW or DEFW (Define Word)

DEFW 2050H

Initializes an area of two bytes at a time. In some assemblers either symbol (DW or DEFW) can be used. This statement re­serves two locations for 2050H

6. DS or DEFS (Define Storage)

OUTBUF: DEFS 4

Reserves a specified num­ber of memory locations. In this example, four mem­ory locations are reserved for OUTBUF,

7. Constant Suffix D, B, Q, H

32H 0A5H 97

Numerical values can be expressed in decimal (D), binary (B), octal (Q), or Hex (H). Hexadecimal dig­its from A to F must be preceded by 0 as shown by 0A5H, and any number without a suffix is consid­ered-decimal.

7.3.3 Advantages of the Assembler

The assembler is a tool for developing programs with the assistance of the com­puter. Assemblers are absolutely essential for writing industry-standard software; manual assembly is quite time-consuming for programs larger than 50 instruc­tions. The assembler performs many functions in addition to translating mnemon­ics, and it has several advantages over manual assembly. The salient features of the assembler are as follows:

1. The assembler translates mnemonics into binary code with speed and accu­racy, thus eliminating human errors in looking up the codes.

2. The assembler assigns appropriate values to the symbols used in a program. This facilitates specifying jump locations.

3. It is easy to insert or delete instructions in a program; the assembler can quickly reassemble the entire program with new memory locations and modi­fied addresses for jump locations. This avoids rewriting the program manually.

4. The assembler checks syntax errors, such as wrong labels and expressions, -and provides error messages. However, it cannot check logic errors in a program.

5. The assembler can reserve memory locations for data or results.

6. The assembler can provide files for documentation.

7. A Debugger program can be used in conjunction with the assembler to test and debug an assembly language program.

CAUTION

A correctly assembled program with zero errors does not mean it is a working program. The assembler cannot check the logic of the program; it checks only the syntax of the program.

Leave a comment

Your email address will not be published. Required fields are marked *