Assembly Language Program - Part I
Assembly Language Program - Part I
Assembly Language Program - Part I
Step 1:
Edit
(Editor) .ASM .LST
Step 3: Step 4:
Step 2:
Link Load
Assembler .EXE (Loader) Memory
(Linker)
(Assembler) .OBJ
.CRF
1) Step 1: Edit
Tools used: Editor (E.g.: Microsoft Visual C++ Express Edition 2005, notepad,
DosBox)
Objective: Convert text into source file (.ASM)
Output: .ASM file (Source file. Contains source code)
2) Step 2: Assembling
Tools used: Assembler
Act as a compiler
Convert source file (.ASM) to object file (.OBJ) and optionally error listing file
(.LST) and cross reference file (.CRF)
Assembler used = Two pass assembler
Objective: To resolve forward reference to addresses in program
Pass 1: Read .ASM & construct SYMBOL TABLE (with names & labels) to
determine the number of codes generated for each instruction.
Pass 2: Complete the object code for each instruction into symbol table.
1
BACS1024 Introduction to Computer Systems
Output: .OBJ file (Object file. Contain machine language), .LST file (Error
listing file. Contains error diagnostic) & .CRF file (Cross reference file
contains references for large program).
3) Step 3: Linking
Tools used: Linker.
Read object file (.OBJ)
Check references
Combine procedure from link library with object file (.OBJ)
Objective: Convert object file (.OBJ) to executable file (.EXE)
Functions:
Combine separated module
Generate .EXE file
Outputs: .EXE file (Executable file. Contains executable code), .MAP file and
.LIB file
4) Step 4: Executing
Tools used: Loader.
Creates PSP (Program segment prefix).
Objective: Read executable file (.EXE) into memory for execution.
1) Constants
a) Numeric constant
Can be written in any base
Debug program: HEX (default base)
Assembly Language editor: DEC (default base)
Specified by radix suffices
B = Binary (Or Y = Binary
D = Decimal (Or T = Ten)
H = Hexadecimal
R = real value for HEX or DEC constant
E.g.: VAR1 DB 2
VAR2 DB 2AH
VAR3 DB 10101010B
b) Character constant
Enclosed using single quote (' ') or double quote (“ ”)
E.g.: VAR4 DB "A"
VAR5 DB 'B'
c) String constant
Enclosed using single quote (' ') or double quote (“ ”)
E.g.: VAR6 DB "HRLLO WORLD$"
VAR7 DB 'HELLO WORLD',"$"
2) Comments
Used to improve the program clarity.
2
BACS1024 Introduction to Computer Systems
4) Identifiers
To represent an item / act as a marker
Rules:
1st char MUST be a letter / underscore / special character
1st char cannot be a dot
1st char cannot be a digit
No casa-sensitive
a) Data label
Refer to data item
E.g.: NUM DB 0 ; NUM = data identifier
b) Code label
Refer to instruction / procedure / segment
E.g.: SUM: ADD AL,BL ;SUM = instruction identifier
5) Statements
General format:
[Identifier] Operation [operand(s)] [;comment]
a) Instructions
Definition: Executable code
E.g.: L10: MOV AL,BL
b) Directive
Definition: Acted upon by the assembler
E.g.: NUM DB 1
6) Directives
a) Memory model
Objective: Provide space for object code & optimize execution
Format: .MODEL mem-model
b) Stack segment
Default size = 1024 bytes
3
BACS1024 Introduction to Computer Systems
Format: .STACK
Characteristic: Can be override
c) Data segment
Format: .DATA
Declaration: MOV AX,@data
MOV DS,AX
d) Code segment
Format: .CODE
e) PROC directive
Initiation: PROC FAR
Ending : ENDP
f) END directive
Objective: End of entire program
E.g.: END MAIN
Procedure:
MOV AX,4C00H
INT 21H
Same as:
MOV AH,4CH
INT 21H
4
BACS1024 Introduction to Computer Systems
4. Data Definition
1) Format
[name] directive initializer
3) Initializer: 0, ? or value
Single element /
initializer AX = 2 bytes
A DB 10 var Data seg Offset
(DS) address (SI)
; A =0AH AX = 0AH
00H 00H 0AH
B DW 10
; B =000AH 00H AH AL
C DD 10 (1 byte) (1 byte)
00H
; C =00 00 00 0AH
5
BACS1024 Introduction to Computer Systems
00H
D DQ 10
;D = 00 00 00 00 00 00
00 0AH 00H
AX = 310AH
00H 31H 0AH
00H AH AL
(1 byte) (1 byte)
D 0AH 0007H
00H
00H
00H
C 0AH 0003H
00H 0002H
B 0AH 0001H
A 0AH 0000H
1) MOV instruction
Objective: Copy data from a location to another
Rule : Agreed size
Format : MOV reg/mem, reg/mem/imm
E.g.: MOV AX,BX
MOV AX, VAR1
MOV VAR2,BX
2) XCHG instruction
Objective: Swap the contents of two memory location
Format : XCHG reg/mem, mem/reg
E.g.: XCHG AX,BX
XCHG AX,VAR1
XCHG VAR2,BX
6
BACS1024 Introduction to Computer Systems
7
BACS1024 Introduction to Computer Systems
1) Format
AND / OR/ XOR destination / source
NOT register / memory
2) Instructions
1 1 0 0
AND 1 0 1 0
1 0 0 0
1 1 0 0
OR 1 0 1 0
1 1 1 0
1 1 0 0
XOR 1 0 1 0
0 1 1 0
NOT 1 0
0 1
8
BACS1024 Introduction to Computer Systems
7. ASCII Table
HEX ASCII HEX ASCII HEX ASCII HEX ASCII HEX ASCII HEX ASCII HEX ASCII HEX ASCII
00 20 40 @ 60 ` 80 Ç A0 á C0 └ E0 α
01 ☺ 21 ! 41 A 61 a 81 ü A1 í C1 ┴ E1 ß
02 ☻ 22 “ 42 B 62 b 82 é A2 ó C2 ┬ E2 Γ
03 ♥ 23 # 43 C 63 c 83 â A3 ú C3 ├ E3 π
04 ♦ 24 $ 44 D 64 d 84 ä A4 ñ C4 ─ E4 Σ
05 ♣ 25 % 45 E 65 e 85 à A5 Ñ C5 ┼ E5 σ
06 ♠ 26 & 46 F 66 f 86 å A6 ª C6 ╞ E6 µ
07 • 27 ‘ 47 G 67 g 87 ç A7 º C7 ╟ E7 τ
08 ◘ 28 ( 48 H 68 h 88 ê A8 ¿ C8 ╚ E8 Φ
09 ○ 29 ) 49 I 69 i 89 ë A9 ⌐ C9 ╔ E9 Θ
0A ◙ 2A * 4A J 6A j 8A è AA ¬ CA ╩ EA Ω
0B ♂ 2B + 4B K 6B k 8B ï AB ½ CB ╦ EB Δ
0C ♀ 2C , 4C L 6C l 8C î AC ¼ CC ╠ EC ∞
0D ♪ 2D - 4D M 6D m 8D ì AD ¡ CD ═ ED φ
0E ♫ 2E . 4E N 6E n 8E Ä AE « CE ╬ EE ε
0F ☼ 2F / 4F O 6F o 8F Å AF » CF ╧ EF ∩
10 ► 30 0 50 P 70 p 90 É B0 ░ D0 ╨ F0 ≡
11 ◄ 31 1 51 Q 71 q 91 æ B1 ▒ D1 ╤ F1 ±
12 ↕ 32 2 52 R 72 r 92 Æ B2 ▓ D2 ╥ F2 ≥
13 ‼ 33 3 53 S 73 s 93 ô B3 │ D3 ╙ F3 ≤
14 ¶ 34 4 54 T 74 t 94 ö B4 ┤ D4 ╘ F4 ⌠
15 § 35 5 55 U 75 u 95 ò B5 ╡ D5 ╒ F5 ⌠
16 ▬ 36 6 56 V 76 v 96 û B6 ╢ D6 ╓ F6 ÷
17 ↨ 37 7 57 W 77 w 97 ù B7 ╖ D7 ╫ F7 ≈
18 ↑ 38 8 58 X 78 x 98 ÿ B8 ╕ D8 ╪ F8 °
19 ↓ 39 9 59 Y 79 y 99 Ö B9 ╣ D9 ┘ F9 ∙
1A → 3A : 5A Z 7A z 9A Ü BA ║ DA ┌ FA ·
1B ← 3B ; 5B [ 7B { 9B ¢ BB ╗ DB █ FB √
1C ∟ 3C < 5C \ 7C | 9C £ BC ╝ DC ▄ FC ⁿ
1D ↔ 3D = 5D ] 7D } 9D ¥ BD ╜ DD ▌ FD ²
1E ▲ 3E > 5E ^ 7E ~ 9E ₧ BE ╛ DE ▐ FE ■
1F ▼ 3F ? 5F _ 7F ⌠ 9F ƒ BF ┐ DF ▀ FF