# 10-mavzu: Assembler tilida dasturlash asoslari Reja Assembler tilining sintaksisi

 Sana 04.02.2023 Hajmi 497.72 Kb. #1157054
Bog'liq
10-Mavzu

## 10-mavzu: Assembler tilida dasturlash asoslari

Reja
Assembler tilining sintaksisi
Yusupov R.A., 2021
Assembler nima
Mashina kodining matnli anologi.
Quyi darajali tizimli dasturlash.
IA-32 (x86) protsessori
MASM
TASM
FASM
NASM
ASM…
Yusupov R.A., 2021
Biz MASM32 kompilyatoridan foydalanamiz. MASM32 (Macro ASseMbler) 32-razriyadli protsessor uchun mo’ljallangan:
Yusupov R.A., 2021
MASM32 Editor oynasining ko’rinishi:
Yusupov R.A., 2021
MASM32 da yozilgan dasturga misol:
Yusupov R.A., 2021
Dastur seksiyalari
Makroslar
Direktivalar
Izohlar
Yusupov R.A., 2021
Belgilar
Lotin alifbosining barcha harflari: A—Z, a—z. Bu yerda jimlik holatida bosh va kichik harflar farqlanmaydi.
(Lekin - option casemap: none ).
0 dan 9 gacha bo’lgan raqamlar;
Belgilar ?, @, \$, _, & . Ular ham harflar deb sanaladi;
Ajratuvchilar , . [ ] ( ) < > { } + / * % ! ' " \ = # ^ .
Ism uzunligi – 32 belgigacha. Ism raqam bilan boshlanmasligi kerak.
Yusupov R.A., 2021
Sonlar tavsifi
 O’nlik 16-lik Hexadecimal, hex Binar ikkilik Nt dd 12100 Part1 dw 11h, 0A6h Mov ESI , 0011010101B Mass dw 1,2,3,5,10 Arr dd 0ah, 0bh, 0ch, 0bfh Tabl db 01b, 101B,1001b Mov EAX, 255 Xor EDX, 0A0b0c0dH AND AL, 11110000B Lea EDI, 128*4/(3+6) Mov EAX, (9-0Fh)*33h Add AX, 1010b OR 1110B

Yusupov R.A., 2021
Nishonlar
Nishon – bu o’zgaruvchilarmi?
.MODEL FLAT, stdcall
.DATA
FVal dd 0
F dd 12
.CODE
Factorial5 proc
mov eax,401000h
mov eds,eax
mov [FVal],1
mov [F],2
mov ecx,4
Loop5:
mov eax,[FVal]
mul [F]
mov [FVal],eax
inc [F]
LOOP Loop5
ret
Factorial5 endp
end Factorial5
Quyidagilarga havola:
• Son
• Satrlarga
• Protseduraga kirish nuqtasiga

Unikal (o’ziga xoslik)
Yusupov R.A., 2021
 MOV Move ADD Add XCHG Exchange CMP Compare PUSH Push CALL Call RET Return JMP Jump

Ularning hammasi – kalitli so’zlardir.
Jami 150 atrofida.
Yusupov R.A., 2021
Direktivalar
A) Kompilyator xatti-harakatini o’zgartirish
.386
.model flat, stdcall
option casemap: none
End entry_point
B) «Kompilyator! Men uchun chora ko’r!»
Mov EAX, offset Num
Kod yo’q.
Yusupov R.A., 2021
Ifodalar
O’zgarmas o’rnida.
mov bx, OFFSET MemVar + (3*2) - 5
Operatsiyalar ko’p.
+ - * /(butun) mod
EQ NE LT LE GT GE
And Or Xor Not
[ ] indeksli
mov bx, 156H MOD 12H
mov al, tab_size GE 50 ; 0 yoki 1
Cmp AL, mas[esi] ; трактуется как (mas + ESI)
O’zgarmas kabi qatnashishi kerak
mov ebx, 15A6H MOD AX ; xato
Yusupov R.A., 2021
Ma’lumotlarni joylashtirish
DB, DW, DD, DQ, DT. . . Masalan, DW – “Define Word”
Ifoda
.data
N1 dd 1, 6, 0aah, ?, ?
Mass4 dw 0
Arr dw 100 dup (200h)
Dozen dd 12
L dd 12 dup (Dozen)
Yusupov R.A., 2021
Name dB “Fizika, Matematika, Dasturlash”, 0
MOV AL, Name ; al = ‘F’
MOV AL, [Name] ; al = ‘F’
MOV AL, Name + 6 ; al = ’,’
MOV AL, Name[6] ; al = ’,’
MOV AL, [Name][6] ; al = ’,’
MOV AL, [Name + 6] ; al = ’,’
Yusupov R.A., 2021
Name dB “Matematika, Fizika, Dasturlash”, 0
; Vergul belgisi adresini hisoblab va uni EBXga joylaydi
… … … …
MOV AL, [EBX]; al = ’,’ EBX registrida joylashgan ; adresni olish
Har xil ЕВХ – turli o’qish joyi.
.data ma’lumotlar seksiyasi uchun
Kombinatsiya
[UIR + ESI/EDI + siljish]
.stack stek seksiyasi uchun
Kombinatsiya
[ЕВР + ESI/EDI + siljish]
Yusupov R.A., 2021
Nusxa olish vaqtida ma’lumotlarning o’lchamlarini o’zgartirish.
MOV [EAX], 1
0000 0001, 0000 0000 0000 0001, 0000 0000 0000 0000 0000 0000 0000 0001 …
MOV BYTE PTR [EAX], 1
MOV WORD PTR [EAX], 1
MOV DWORD PTR [EAX], 1
Yusupov R.A., 2021
Izohlar
comment * ----------------------------------
Ko’p satrli izohga misol.
Dastur qismi uchun qulay.
---------------------------------- *
; Bir satrli izoh
Mov ax, dx ; ; bilan boshlanadiначинаются
; va satr oxiri belgisi bilan tugaydi
Yusupov R.A., 2021
SAVOLLAR?????