Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

CHAPTER 4

Assembly Language Programming

‫رابط الكورس كامل لهندسة حاسب | جامعة الطائف‬


https://si-manual.com/courses/micro-processors

‫رابط الكورس كامل لعلوم حاسب | جامعة الطائف‬


https://si-manual.com/courses/micro-processors-and-assembly-language

By Eng. Emad Mahdy


WhatsApp: +20 12 7148 2006
https://www.youtube.com/@eng.emadmahdy
https://si-manual.com

By Eng. Emad Mahdy


WhatsApp: +201100184676
YouTube: https://www.youtube.com/channel/UC2VtseEd46wuDfmDXhfB9Ag
‫أي برنامج‬Assembly
:‫يتكون من‬

Directives
Instructions
Examples:
Examples:
.MODEL SMALL
ADD
.STACK 64
MOV
.DATA

By Eng. Emad Mahdy


WhatsApp: +201100184676
YouTube: https://www.youtube.com/channel/UC2VtseEd46wuDfmDXhfB9Ag
assembly ‫نموذج أي برنامج‬

. MODEL SMALL
. STACK 64

. DATA

‫عرف كل المتغيرات هنا‬

.CODE
MAIN PROC FAR ; This is the program entry point
MOV AX, @DATA ; Load the data segment address
MOV DS, AX ; Assign value to DS

‫اكتب هنا الكود الخاص بك‬

MOV AH, 4CH ; set up to return to DOS


INT 21H
MAIN ENDP
END MAIN ; This is the program exit point

The Instruction’s Fields


:‫ تتكون من االتي‬Assembly instruction ‫أي‬

[label: ] mnemonic [operands] [; comment]


The label must end with a colon ∶ in case of assembly instructions but not in case of directives

Directives or Pseudo-Instructions

▪ ORG Directive
o ORG; indicates the beginning of the offset address.

segment ‫ معين يتخزن فيه داتا بداخل ال‬offset ‫ لما أكون عاوز احدد‬ORG ‫بستخدم ال‬

By Eng. Emad Mahdy


WhatsApp: +201100184676
YouTube: https://www.youtube.com/channel/UC2VtseEd46wuDfmDXhfB9Ag
Example

DATA
ORG 30H
X DB 10

30h offset ‫ علي مسافة‬DATA Segment ‫ يتخزن في ال‬X variable ‫هنا انا قدرت أخلي ال‬

▪ DUP Directive
o DUP is used to allocate (create space for) an array or string.

‫ از قيمة ابتدائية ثابتة‬,‫ بدون أن بكون لها قيمة ابتدائية‬bytes ‫ لو عاوز احجز عدد معبن من ال‬DUP ‫بستخدم ال‬

Examples

var2 DB 5 DUP(? ) ; 5 bytes, uninitialized

? ? ? ? ?

▪ EQU Directive
o defines a constant without occupying a memory location.

C++ ‫ في ال‬#define ‫ هو نفس فكرة ال‬EQU ‫ال‬

memory ‫المتغير المحجوز ال يأخذ أي مكان في ال‬

Example

COUNT EQU 25

C + + ‫ في ال‬#define COUNT 25 ‫هي نفسها‬

▪ MODEL Directive
o This directive selects the size of the memory model.

‫بحدد حجم البرنامج‬

. MODEL SMALL uses a maximum of 64K bytes of memory for code and another 64K bytes of memory for data.
. MODEL MEDIUM uses a maximum of 64K bytes of memory for data and the code can exceed 64K bytes of
memory.
. MODEL COMPACT uses a maximum of 64K bytes of memory for code and the data can exceed 64K bytes of
memory.
. MODEL LARGE both data & code can exceed 64K bytes of memory, but no single set of data should exceed 64k
bytes.
. MODEL HUGE both data & code can exceed 64K bytes of memory and data items such as arrays can exceed 64k
bytes.
. MODEL TINY used with COM files in which data & code must fit into 64k bytes.

Data Types

By Eng. Emad Mahdy


WhatsApp: +201100184676
YouTube: https://www.youtube.com/channel/UC2VtseEd46wuDfmDXhfB9Ag
Data types

DB DW DD DQ DT
byte Word Double word Ten byte
Quad word
1-bytes (2-bytes) (4-bytes) (10-bytes)
(8-bytes)

Data type Data type name size


DB (Define Byte) Directive 1-byte
DW (Define Word) Directive 2-byte
DD (Define Double word) Directive 4-byte
DQ (Define Quad word) Directive 8-byte
DT (Define Ten byte) Directive 10-byte

By Eng. Emad Mahdy


WhatsApp: +201100184676
YouTube: https://www.youtube.com/channel/UC2VtseEd46wuDfmDXhfB9Ag
Segment Definition

The 8086 CPU memory has 4 segments:


▪ CS (Code segment)
▪ DS (Data segment
▪ SS (Stack segment)
▪ ES (Extra segment)
Every line in an assembly program must correspond to one of these segments.
‫ دي‬segments ‫ هتكتبه الزم هيتخزن في واحد من ال‬Assembly ‫أي سطر كود‬

An assembly program consists of at least 3 segments:


▪ . 𝐒𝐓𝐀𝐂𝐊 ; marks the beginning of the stack segment
▪ . 𝐃𝐀𝐓𝐀 ; marks the beginning of the data segment
▪ . 𝐂𝐎𝐃𝐄 ; marks the beginning of the code segment

Extra Segment

Stack Segment

Data Segment

Code Segment

By Eng. Emad Mahdy


WhatsApp: +201100184676
YouTube: https://www.youtube.com/channel/UC2VtseEd46wuDfmDXhfB9Ag
Assemble-Link Execute Cycle

By Eng. Emad Mahdy


WhatsApp: +201100184676
YouTube: https://www.youtube.com/channel/UC2VtseEd46wuDfmDXhfB9Ag

You might also like