Académique Documents
Professionnel Documents
Culture Documents
PROGRAMMING
CONCEPTS 1
CHAPTER 2
ASSEMBLY LANGUAGE
PROGRAMMING
To code efficiently in assembly language for a
particular processor, the prerequisites are
a good knowledge of the internal architecture
of the processor and addressing modes
Features of assemblers
Labels are used for memory addresses
Labels are used for constants
Macros are allowed
language) and
converts it to the object code in machine
language
and Windows
TASM and MASM are very popular
It is found now that Windows 7, a new
64-bit operating system, does not
directly support 16-bit programs so 16
bit assemblers may not work with
Windows 7 directly
The x86 Microprocessor - Lyla B Das
DOS
DOS stands for Disk Operating Systems. It
keyboard
for
MOV AH ,4CH
INT 21H
10
MOV AH, 01
INT 21H
This call exits with the ASCII value of the key
pressed, being available in AL .
The key pressed is also echoed on the screen
.
11
MOV AH, 08
INT 21H
This call exits with the ASCII value of the key
pressed being available in AL .
The key pressed is not echoed on the
screen
12
unit.
For this ,the ASCII value of the character to be
displayed should be in DL
MOV DL, S
MOV AH, 02
INT 21H
13
Displaying a character
STRING DISPLAY
iv) Display a character string on the standard
display unit
The logical address DS:DX should point to the
beginning of the string .
This is to be followed by the following
instructions
MOV AH, 09
INT 21H
14
Why MASM ?
Microsoft has written considerable
documentation
Third parties have written assembly language
reference manuals for MASM
The versions of MASM 6.0 and above have a
lot more features (aimed at simplification of
writing code) than previous versions
15
Here we use
MASM 6.14, which is DOS based
In this, DOS and BIOS interrupts can be used
MASM32, which is windows based
In this, DOS and BIOS interrupts cannot be
used.
16
ASSEMBLY LANGUAGE
PROGRAMMING STEPS
Write the code with the help of an editor
Open the DOS window
Go to the MASM and then to the BIN directory
Assemble the code
Link the code
Run the executable file
17
Memory Models
For defining segments
Dot models have short cuts
The tiny model is used when only one
segment is needed
To specify a segment, write
. MODEL MODEL NAME
18
19
Save it as tiny.asm
Open MASM and go to the BIN directory.
20
21
B0 67
B3 45
02 C3
8A D0
.MODEL TINY
.CODE
MOV AL,67H
MOV BL,45H
ADD AL,BL
MOV DL,AL
.EXIT
END
The x86 Microprocessor - Lyla B Das
22
23
tinym.com
We get an underscore as the prompt
On typing r, we can see the contents of the
registers, before execution of the program
Now type u, which is the command for
unassembling
25
Example 2.5
C:\masm6.14\BIN>debugtinym.com
r
AX=0000BX=0000CX=010CDX=0000SP=0000BP=0000
SI=0000DI=0000
DS=13ADES=13ADSS=13BDCS=13BDIP=0100NVUPEIPL
NZNAPONC
13BD:0100B067MOVAL,67
u
13BD:0100B067MOVAL,67
13BD:0102B345MOVBL,45
13BD:010402C3ADDAL,BL
13BD:01068AD0MOVDL,AL
13BD:0108B44CMOVAH,4C
13BD:010ACD21INT21
The x86 Microprocessor - Lyla B Das
26
27
28
Example 2.7
29
30
31
Example 2.9a
32
Example 2.9b
33
34
characters
NUMS DB 10 DUP(0) fills up with 0s the
10 byte locations starting with the label
NUM
Other examples
STARS DB 5 DUP(#)
BLANK DB 10DUP(?)
WRDS DW 4 DUP(FF0FH)
35
values mentioned
Examples:
TEMP
PRICE
EQU 34
EQU 199
36
Example 2.10
37
38
Example 2.11a
39
Example 2.11b
40
41
42
43
Example 2.13
44