Professional Documents
Culture Documents
Chapter 1 - Introduction
Chapter 1 - Introduction
1.0 Outcomes
; Disp.asm
; display a message on the screen
.MODEL SMALL
.STACK 200h
.DATA
Prompt db 13,10,"This is the message $"
.CODE
start:
mov ax, seg prompt ;moves the segment of data into ax
mov ds,ax
mov ah,9
mov dx,offset Prompt
int 21h ;print the message
.exit
End start
normal text.
The next field is the operation code (Add), which must be a valid operation code for the given
microprocessor. The operation codes are given by the microprocessor manufacturer and are
called the instructions set. The operation code tells the microprocessor what action to perform.
This field is required unless that line of the program is a comment line.
The third field is the operand field, (AX,5H). This contains the data on which the operation will
be performed. The type and the number of operands depend on the operation code. An
operation code may require no operand, one, or two operands. If more than one operand is
required they must be separated by commas.
The last field is the remark field (; Add percentage). This may contains anything as it is
intended for the programmer and not the computer. The objectives of the remark field are to
aid the readability of the program; help the programmer understands the program and thus
improve maintainability. The comment field starts with a semicolon (;). This field is not
compulsory but recommended.
Example 1.1
New: Add AX,5H ; Add percentage
Mov dx,ax
Jmp new
Table 1.1 summarises the fields of the four fields of the assembly language instruction
The assembler used for all the examples given in this book is Turbo Assembler (TASM
version 5). Some of the directives given in Figure 1.1 are explained in Table 1.2. For a
complete list of all directives consult the TASM user reference.
In describing the syntax of a directive in Table 1.2, the followings are used:
The .directive is the directive name from the list of available directives for TASM. <required
parameter> is a parameter that must be included with the directive. {optional parameter} is a
parameter that can be supplied or omitted. If it is not supplied a default value is used. Note
.MODEL .MODEL <memory model> This directive defines the attributes that affect
SMALL the entire module such as: memory model,
{,options}
default calling and naming conventions,
operating system, stack type etc. Thus, it must
appear in the program before any other
simplified segment directive. The memory
models available are: tiny, small, compact,
medium, large, huge, or flat. The memory
model selected determines size of code and data
pointers
.STACK .STACK {stack size} This directive creates a stack segment. If the
200h stack size is not supplied, the assembler
allocates 1K of memory for the stack.
.DATA .DATA This directive creates a near data segment that
contains the frequently used data for your
program. The data segment can occupy:
• up to 64K in MS-DOS
• or up to 512 megabytes under flat model
.CODE .CODE This directive creates a near code segment that
contains the code for your program
.exit .exit This directive is available only in 16-bit
addressing modes. It is used to terminate
program execution and return control to DOS
text editor such as Notepad or WordPad which comes free with Windows operating systems.
Source
Code
instructions that can be executed by the microprocessor. As can be seen from Figure 1.3, the
assembler takes the source code as input and will produces an object file containing the
machine code instructions if the assembler did not detect any syntax error during the assembly
process. Other optional files may be generated depending on the assembler in use. If the
assembler detects any error during the assembly process only a list file containing the assembly
instructions, the error code, and an error message for each error encountered will be produced.
No
Source code
Listing Object
Code
Figure 1.3. The Process of Assembling (Translating) an Assembly Code into Machine Code
1.2.3 Linker
A linker is a program that links several object files into an executable file, a program that can be
executed by the operating system. The output of the linker is an executable file if no error
encountered during the linking process. If any error encountered the linking process is halted
and an error message describing the error is displayed as shown in Figure 1.4.
Object Linker Executable
Code Code
Library
Files
Figure 1.4
1. Design your program using any of the design tools mentioned earlier
2. Use a text editor or a word processor that can produce text file to type the assembly
language programs
5. If the program assembles properly, Link the program to produce an executable file