Professional Documents
Culture Documents
Microprocessor AEE Part3
Microprocessor AEE Part3
Course contents
1. Introduction to microprocessor systems
2. The Intel 8088/8086 microprocessors
3. Assembly programming for 8086
4. Memory and I/O Interfacing
5. Interrupt
6. Didect memory access (DMA)
7. Real life microprocessors
© DHBK 2005 2/Chapter3
3.1.1 Syntax
1. .Model Small
Memory model declaration
2. .Stack 100
Stack declaration
3. .Data
4.
5.
Tbao DB ‘Chuoi da sap xep:’, 10, 13
MGB DB ‘a’, ‘Y’, ‘G’, ‘T’, ‘y’, ‘Z’, ‘U’, ‘B’, ‘D’, ‘E’, Data segment declaration
6. DB ‘$’
7. .Code
8. MAIN Proc
Code segment declaration
9. MOV AX, @Data ;khoi dau DS
10.
11.
MOV
MOV
DS, AX
BX, 10 ;BX: so phan tu cua mang Start of main program
12. LEA DX, MGB ;DX chi vao dau mang byte
13. DEC BX ;so vong so sanh phai lam
14. LAP: MOV SI, DX ; SI chi vao dau mang
15. MOV CX, BX ; CX so lan so cua vong so
16. MOV DI, SI ;gia su ptu dau la max
3.1.1 Syntax
• Name Field Opcode Operands ; comment
• Assembler is not case sensitive
• Name field:
Contains label, variable, subprogram name
Length: 1 to 31 characters
Name must not contain space nor start with a digit
Can contain special characters: ? . @ _ $ %
When used . must be placed first
Labels must end with :
Examples:
TWO_WORD
?1
two-word
.@?
1word
Let’s_go
© DHBK 2005 7/Chapter3
M4 DB 4, 3, 2, 1, 5, 5, 6, 1, 5, 5, 6
© DHBK 2005 12/Chapter3
• Constant declaration
Constants can be declared within the body of a program
Often declared in the data section
Examples:
CR EQU 0Dh ; carriage return
LF EQU 0Ah ; line feed
CHAO EQU ‘CR Hello’
Models Description
Large (lớn) several code segments, several data segments, maximum arrray size is 64
KB
Huge (đồ sộ) several code segments, several data segments, arrrays can be more than 64
KB
© DHBK 2005 16/Chapter3
.Model Small
.Stack 100
.Data
;constants and variables declaration
.Code
MAIN Proc
;Initialize for DS
MOV AX, @data
MOV DS, AX
;Insert your code here
FFFFH
SP
Stack expansion
CONTINUE:
Data
0100H JMP CONTINUE IP
Program segment prefix
0000H
© DHBK 2005 21/Chapter3
Stack
SS Program
Program CS
DS
100h ES 100h
PSP PSP
.COM . EXE
© DHBK 2005 23/Chapter3
; If AX<0
CMP AX, 0 ; AX<0 ?
JNL End_if ; NO, exist
; then
NEG AX ; YES, AX=-AX
End_if: MOV BX, AX ;BX=AX
© DHBK 2005 27/Chapter3
3.3.2 If-then-else
• If condition then task 1 else task 2
• E.g: if AX<BX then CX=0 else CX=1
; if AX<BX
CMP AX, BX ; AX<BX ?
JL Then_ ; yes, CX=0
;else
MOV CX, 1 ; no, CX=1
JMP End_if
Then_: MOV CX, 0;
End_if:
© DHBK 2005 28/Chapter3
3.3.4 For-Do
• For Nr_of_iteration Do task
task
MOV CX, 80 ;number of loop
MOV AH,2 ;display one character
Decrease the counter MOV DL,’$’ ;DL stores the ascii code of
character to be displayed
HIEN: INT 21H
LOOP HIEN
N ;End_for
counter=0?
Y
© DHBK 2005 30/Chapter3