Assembly Language Lab # 2 Assembly Language Fundamentals: Eng. Alaa.I.Haniya
Assembly Language Lab # 2 Assembly Language Fundamentals: Eng. Alaa.I.Haniya
Eng. Alaa.I.Haniya
Assembly Language Fundamentals
Assembly Language :
Assembly Language is a programming language that is very similar to machine language, but
uses symbols instead of binary numbers. It is converted by the assembler (e.g. Tasm and Masm)
into executable machine-language programs.
To make programs in assembly language, you must know some information about the 8086
microprocessor. The 8086 contains 14 registers. Each register is 16 bits long. See Figure (1)
Assembly Language Fundamentals
Each register has different usage as shown in Table (1) below. The general purpose registers
can be "split". You have the AH and the AL register for example. AH contains the high byte of AX
and AL contains the low byte. You also have: BH, BL, CH, CL, DL, DH So if for example. DX
contains the value 1234h DH would be 12h and DL would be 34h.
1
Assembly Language Fundamentals | 2/20/2013
Table(1): Registers of 8086 microprocessor and their purposes
And a 16-bit FLAG Register. The FLAGS Register consists of 9 status bits. These bits are also
called flags, because they can either be SET (1) or NOT SET (0). All these flags have a name
and purpose.
2
Table(2): FLAGS Register
Instruction Forms:
Assembly instructions are made up of an operation code (op-code) and a set of operands. The op-code
identifies the action to be taken. The operands identify the source and destination of the data.
The operands identify CPU registers, memory locations, or I/O ports. The complete form of an
instruction is:
For example:
(Add 1 to register AX); one operand INC AX
(Store 100 in register AX); two operands MOV AX, 100
Assembly Language Fundamentals
Segments:
Code, Data, Stack an Extra. Within the 1 MB of memory space the 8086 defines four 64 K byte
memory blocks called the code segment, data segment, stack segment, and the extra segment.
3
Instruction Description
General-Purpose Registers:
4
Data Types:
Syntax:
[name] directive initializer [,initializer] . . .
value1 BYTE 10
db
We can defines a single byte of storage, use multiple initializers , Defining Strings .
5
Integer Constants
An integer constant (or integer literal) is made up of an optional leading sign, one or more digits
and an optional suffix character (called a radix) indicating the number's base:
[{+ | - }] digits [radix ]
Common radix characters:
h – hexadecimal
d – decimal
b – binary
o – octal
A character constant is a single character enclosed in either single or double quotes. The
assembler converts it to the binary ASCII code matching the character. Examples are:
'A'
"x"
ASCII character = 1 byte.
String Constants
6
Reserved Words
Assembly language has a list of words called reserved words. These have special meaning and
can only be used in their correct context. Reserved words can be any of the following:
Instruction mnemonics, such as MOV, ADD or MUL which correspond to built-in
operations performed by Intel processors.
Attributes, which provide size and usage information for variables and operands.
Examples are BYTE and WORD.
Predefined symbols. Such as @data which return constant integer values at assembly
time.
Identifiers
Assembly Language Fundamentals
Comments
Block comments, beginning with the COMMENT directive and a user-specified symbol.
All subsequent lines of text are ignored by the assembler until the same user-specified
symbol appears. For example:
7
Using the DUP Operator:
Syntax:
8
Homework:
Note: To print a character on the screen you have to use the int 21h with the service 2, the
character to be printed have to be in dl. For Example, the following code print A on the screen.
mov ah, 2
mov dl, 41h
int 21h
2.Print the following output on the command window using the DUP Operator:
*
**
***
****
*****
Assembly Language Fundamentals
3. Write the following message on the console using (0Ah = line feed):
This
is
my
H.W
Assembly Language Lab # 2