Lecture 4 Assembly Language Syntax and Program Structure
Lecture 4 Assembly Language Syntax and Program Structure
ا
ا د
Royal Commission at Yanbu ا ا
University College – Yanbu - ا ا
Department of ACS & AIT
Yanbu Al-Sinaiyah ا
CS-203 HANDOUT 4
ASSEMBLY LANGUAGE SYNTAX AND PROGRAM STRUCTURE
4.1 Introduction
Assembly language imposes some rules on how names are assigned to labels,
variables, procedures and macros. It is the assembler's function to translate those
names into memory addresses.
Note that naming conventions used in this course are related to the MASM 6.15
assembler used in the lab.
This field specifies data to be acted on. It may have one, two or no operands at all.
There exist around 150 instructions for the 8086 processor. These instructions may be
classified into different classes. The following table summarizes the different classes of
instructions, together with examples of each class.
Assembler directives are instructions that are directed to the assembler. Assembler
directives affect the generated machine code, but are not translated directly into
machine code. Directives can be used to declare variables, constants, segments,
macros, and procedures.
In general, a directive:
tells the assembler to do a specific thing, and
is not translated into machine code.
.RADIX H
The title directive is optional and specifies the title of the program. Like a comment, it
has no effect on the program. It is just used to make the program easier to understand.
The model directive specifies the total amount of memory the program would take. In
other words, it gives information on how much memory the assembler would allocate for
the program. This depends on the size of the data and the size of the program or code.
Segments are declared using directives. The following directives are used to specify the
following segments:
• stack
• data
• code
Example:
Here is how the "hello world" program would look like in assembly:
.data
greeting db 'hello world !',13,10,'$'
.code
mov ax,@data
mov ds,ax
mov ah,9
mov dx,offset greeting
int 21h
mov ah,4ch
The memory model specifies the memory size assigned to each of the different parts or
segments of a program. There exist different memory models for the 8086 processor
The .MODEL Directive
The memory model directive specifies the size of the memory the program needs. Based
on this directive, the assembler assigns the required amount of memory to data and
code.
Each one of the segments (stack, data and code), in a program, is called a logical
segment . Depending on the model used, segments may be in one or in different
physical segments.
In MASM 6.X, segments are declared using the .MODEL directive. This directive is
placed at the very beginning of the program, or after the optional title directive.
MODEL directive
.MODEL memory_model
Where memory_model can be:
• TINY
• SMALL
• COMPACT
• MEDIUM
• LARGE or
• HUGE.
(*) For the LARGE model, the largest arrays size can not exceed 64 KB.(br) (**)For the
HUGE model, an array may have a size greater than 64 KB and hence can span more
than one physical segment.
The amount of data that has to be manipulated and code that needs to be written are the
major factors in determining the choice of an appropriate model. The following are
guidelines to help chose the right model for a program.
For a small fast program that operates on small quantities of data, the SMALL or TINY
models are the most suitable ones. These models allow up to 64K of memory (i.e. one
single physical segment), but the executable code is fast. The only difference between
these two models is that the TINY model generates a .COM module in which far
references cannot be used, whereas the SMALL model generates a .exe module.
For very long programs that require more than one code segment and operate on large
amounts of data which would require more than one data segment, the LARGE and
HUGE models are most appropriate.
.data
main endp
;Other Procedures
The following rules have to be strictly followed in order to write correct code.
a. All coding
b. Data variables and stack variables
c. Variables and constants
d. None of above
a. Type of program
b. Memory model of program
c. Data model of program
d. Code model of program
Question: What is the difference between the LARGE and HUGE memory model.