You are on page 1of 27

Microprocessors

Chapter 7
Assembly Language
Programming
Consideration and Applications
prepared by
Dr: Mohamed EL-Bouridy Dr : Reda EL-Sheshtawy
mohamed.elbouridy@aiet.edu.eg RedaSheshto66@gmail.com
Software Assembly Utilities
The required software to convert an
assembly language program to machine
code, then the machine code is
downloaded it into the microprocessor for
actual operation
Utilities
Assembler
Linker
Loader
Source Program
Written with Editor

Assembler generate two files


Object File List File
The program in Symbols and
formating of labels in machine
machine code code

LINKER Adapt the


(Link the machine state shape
code with memory by to be suitable
physical address and for the target
produce exe file for system
execution)
The Assembly
Directives
The Assembly language written
as follows :
Label Instruction Operand Comments
The Assembly Directives
1) Comment Directive: ; (List file ) √ (object file) x
This make the assembler didn’t generate a machine
code for this line or comment .

2) Name Directive : (List file ) √ (object file) x


Identify the program name i.e Mostafa

3) Assume Directive :
Initialize the segment register to specified values
Assume : CS : 3772 H
DS :
SS :
ES :
The Assembly Directives
4) EQU Directive : Equated value to
corresponding symbol
5) Label Begin : Begin refers to start the
program from this point .
6) Offset Directive : MOV DX, offset message
Take the first offset address of message.
7) Directive END : Finished the operation
Begin :
Program
END : Begin ( finished the operation)
The Program Structure
To write an assembly program like any other language program we must follow the following sequence:

1) Decide the problem and the goal.


2) Draw the program flowchart.
3) Write the program code.
The sequence of writing
the assembly
Program
1)The program goal described by the designer according to the requirements.
2) The flowchart consists of :
a) Start : written in rectangular shape

Start
The sequence of writing
the assembly
Program
b) Preparation : write the preparation steps

c) Process : state the process of the operation

State
The sequence of writing
the assembly Program
d)Decision : after decision the program may be perform feedback according to requirement

c) End : Ending the program

No
Decision

Yes

End
Example 1:
Write an assembly program to transfer a
group of data stored in the data segment
from offset 0001H to 000F H, DS=3F3C
H to the output port addressed by 037B
H?
Solution:
1) The problem goal is to transfer the data from
DS=3F3C H, offset 0001H 000F H to the
O/P port address 037BH.
2) Transfer 15 data stored in memory to O/P port
address 037BH.
The flow chart
Start

DS= 3F3C H,SI= 0001H


DX= 037BH ,CX= 000EH

Transfer SI to AX o/p port


CX= CX-1
SI=SI+1
Is data
finished No

Yes

End
The Program
Begin
MOV BX, 3F3C H
MOV DS, BX ; Go to selected data segment
MOV SI , 0001 H ; Go to the offset
MOV DX, 037B H ; Identification of o/p address
MOV CX, 000E H ; Counter
LL1 MOV AL, [SI]
OUT DX, AL
INC SI
LOOP LL1
END Begin
Example 2:

Write an assembly program to receive


a digital data from radar system and
compeer it with a fixed threshold level,
if true multiply it’s amplitude by 2 and
o/p it again. If it false multiply it’s
amplitude by 0 and o/p it again. The I/P
port address is 8F00H, The O/P port
address is 8C00H, the threshold level
is 5BH.
Solution:

1)The problem goal: is to compeer the


I/P data comes from the I/P address
8F00H with a threshold level equal
5BH, if it true multiply it by 2, if it
false multiply it by 0, and the O/P
address is 8C00H.
The flow chart Start

I/P port address SI= 8F00H

O/P port address DI= 8C00 H

Threshold level BL= 5BH

I/P the target


from SI
No
I/P ≥ BL
Yes
MUL * 2 MUL* 0

O/P the data


from DI
The Program
Begin MOV SI, 8F00H ; I/P port address
MOV DI, 8C00 H ; O/P port address
MOV CL, 00 H
MOV BH,02H
MOV BL, 5B H ; Threshold level
CC1 MOV DX,SI
IN AL, DX
CMP AL,BL
JGE BB1
MUL CL
JMP OUTPUT
BB1 MUL BH
JMP OUTPUT
OUTPUT MOV DX, DI
OUT DX, AX
JMP CC1
Example 3:
Write an assembly program to perform
the following mathematical function and
save the result, start offset 1F00H in
DS.
Where: m=1,2,3,4
EX : 3
Where: m=1,2,3,4
Begin:
Mov SI,1f00 H ;The offset
Mov CX,0001 H ; starting m
Mov AX,0001 H ;help for Mul
aa4: Mov BL,01 H ;starting n
Mov BP,0000 H ;help for summation
aa2: MUL BL
ADD BP,AX
Mov AX,CX
CMP BL,04H
JE aa3
INC BL
JMP aa2
aa3: Mov [SI],BP ; the result
INC SI
INC SI
CMP CX,0004H
JE aa5
INC CX
MOV AX,CX
JMP aa4
aa5: INT 3H
Example 4:
Write an assembly program to perform
the following mathematical function and
save the result, start offset 1F00 in DS.
EX : 4
Begin: Where: m=1,2,3,4
Mov SI,1f00h ; The offset
Mov CX,0001H ;Starting m
Mov DX,0001H ;help for multiplication
a4: Mov BX,0001H ;Stating n
Mov AX,0001H ;help for multiplication
a2: ADD DX,BX
MUL DL
Mov DX,CX
CMP BX,0004H
JE a3
INC BX
JMP a2
a3: Mov [SI],AX
INC SI
INC SI
CMP CX,04H
JE a5
INC CX
Mov DX,CX
JMP a4
a5: INT 3h
EX : 5
Where: m=1,2,3,4
begin:
MOV SI,1F00 H
MOV CX,0001 H m;
MOV AX,0001 H
aa4: MOV BX,0001 H n;
MOV DX,0000 H
aa2: ADD AX,BX
ADD DX,AX
MOV AX,CX
CMP BX,04H
JE aa3
INC BX
JMP aa2
aa3: Mov [SI],DX
INC SI
INC SI
CMP CX,0004H
JE aa5
INC CX
MOV AX,CX
JMP aa4
aa5: INT 3h
EX : 6
Where: m=2

begin:
Mov AX,0002H m;
Mov BP,0000H
aa4: Mov BX,0001H n;
Mov DX,0005H
Mov CX,0002H
aa2: ADD AX,BX
ADD BP,AX
CMP BX,0004H
JE aa3
INC BX
Mov AX,CX
JMP aa2
aa3: ADD DX,BP
INT 3h
EX : 7
Where: m=2
begin:
Mov AX,0002H
aa4: Mov BX,0001H
Mov DX,0005H
Mov CX,0002H
aa2: ADD AX,BX
ADD BP,AX
CMP BX,0004H
Je aa3
INC BX
Mov AX,CX
JMP aa2
aa3: Mov AX,BP
MUL DX
INT 3h
EX : 8
begin: MOV SI,1F00H
MOV CL,01H
;m
MOV AL,01H
aa4: MOV BL,01H
;n
MOV DL,00H
aa2: ADD AL,BL
ADD DL,AL
MOV AL,CL
CMP BL,04H
JE aa3
INC BL
JMP aa2
aa3: MOV [SI],DL
INC SI
CMP CL,04h
JE aa5
INC CL
MOV AL,CL
JMP aa4
aa5: ADD DL,[1F00H]
ADD DL,[1F01H]
ADD DL,[1F02H]
ADD DL, 05H
EX : 9
Begin:
MOV SI,1F00H
MOV CL,01H
;m
MOV AL,01H
aa4: MOV BL,01H
;n
MOV DL,00H
aa2: MUL BL
ADD DL,AL
MOV AL,CL
CMP BL,04H
JE aa3
INC BL
JMP aa2
aa3: MOV [SI],DL
INC SI
CMP CL,04H
JE aa5
INC CL
MOV AL,CL
JMP aa4
aa5: ADD DL,[1F00H]
ADD DL,[1F01H]
ADD DL,[1F02H]
ADD DL,5H
The
END

You might also like