Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web


Inapoi la pagina principala


Ce exemple doriti sa vedeti? 1. Exemple de instructiuni si date:
Tipuri de date:


Tipul Segment si directiva ASSUME:

nume_data segment
var1 db 'Haribol'
nume_data ends
assume ds:nume_data


Declararea de variabile:

sir1 db dup(100) ; sir de 100 de caractere
CR equ dh ; constanta (carriage return, cod D)


Un sablon de program:
	date segment
sir db dup(100)
num db ? ; nedefinit
date ends
assume cs:cod ds:date
cod segment
mov ax, num ; instructiuni ASM...
mov ds, ax
mov ah, 4ch ; iesire DOS
int 21h ; iesire DOS
cod ends
end ; end-ul final(e obligatoriu!)

Instructiuni de transfer:
mov ax, bx ; muta in AX continutul lui BX
mov ax, 5 ; ax = 5

Instructiuni aritmetice:
add ax, 56; ax = ax + 56

dec bx; bx = bx - 1

mov ax, 9
div 4 ; ah = 2, al = 1

mov ax, 8
mul 7 ; ax = 56

sub ax, cx; ax = ax - cx

mov ax, 5
shl ax, 2; ax = 5 * 4 = 20

mov ax, 64
shr 3 ; ax = 64 / 8 = 8

Instructiuni logice:
xor ax, ax ; ax = 0

and cx, dx

Instructiuni cu siruri:
lea dx, ds ; ds e adresa unui sir
lodsb

Instructiuni de salt:
@1:mov ax, 7
mov bx, 5
cmp ax, bx
jl @2 ; nu sare deoarece 7 < 5 e fals
jge @2 ; sare la @2 pt. ca 7 >= 5
jmp @1 ; sare la @1(fara discutie...)
@2:...
mov cx, 1000

@1:loop @1 ; sare la @1 de 1000 ori

Instructiuni complexe:
aduna macro a b ; parametrii a si b
local @1
local mm db ?
add a, b ; ii aduna
aduna endm

save proc
pushf ; salveaza toti registrii
ret ; return
save endp

Tehnici:
IF (ax >= bx) and (ax > 10) THEN ax = ax / 2
ELSE ax = bx
cmp ax, bx
jl et1
cmp ax, 10
jle et1
et1:mov ax, bx
jmp et2
shr ax, 1
et2:

REPEAT readchar UNTIL enter
et1:mov ah, 1; citeste caracter cu ecou
int 16h
cmp al, 13 ;cod ENTER
jne et1


2. Exemple de programe ASM:
Fisier COM(asteapta o tasta):
code segment
org 100h
assume cs:code
mov ah, 0 ;functie waitchar
int 16h
mov ah, 4ch ;iesire DOS
int 21h
code ends
end

Afiseaza un sir:
data segment
sir db 'Haribol', '$'
data ends
assume cs:code ds:data
code segment
mov ax, data
mov ds, ax
mov ah, 9h ;functie sfisare sir
lea dx, sir
int 21h
mov ah, 4ch ;iese DOS
int 21h
code ends
end

Aprinde toate LED-urile:
code segment
assume cs:code
mov al, 0edh
out 60h, al
mov cx, 10000 ; asteapta...
@1:loop @1
mov al, 7; 1 + 2 + 4
oout 60h, al
mov ah, 4ch
int 21h
code ends
end

Macro de Bar grafic:
code segment
assume cs:code
putpixel macro x, y, c
mov ah, 0ch ;functia de pixel...
mov bh, 0
mov cx, x
mov dx, y
mov al, c
int 10h
putpixel endm
bar macro x1, y1, x2, y2, c
local @1
mov cx, x1
mov dx, y1
@1:putpixel cx, dx, c ;se foloseste macro-ul definit anterior
inc cx
cmp cx, x2
jl @1
mov cx, x1
inc dx
cmp dx, y2
jl @1
bar endm
mov ax, 10h
int 10h
bar 1, 1, 300, 200, 5
mov ah, 0
int 16h
mov ax, 3
int 10h
mov ah, 4ch
int 21h
code ends
end

Muta cursorul la coord. mouse-ului pentru b1. La b2 iese:
code segment
assume cs:code
move macro x, y
mov bh, x ;muta cursorul
mov dx, y
mov ah, 2
int 10h
move endm
xor ax, ax
int 33h
mov ax, 1
int 33h
@1:mov ax, 3 ;preia coord. mouse(CS, DX) + buton(BX)
cmp bx, 2
je @2
cmp bx, 1
je @3
jmp @1
@3:move cx, dx
jmp @1
@2:mov ah, 4ch
int 21h
code ends
end

Citeste un sir si-l afiseaza apoi pe ecran:
data segment
sir db dup(?) ;dimensiune nedeclarata
mes db 'Dati un sir:', '$'
data ends
code segment
assume ds:data cs:code
mov ax, data ;afisam mes
mov ds, ax
mov ah, 9
lea dx, mes
int 21h
lea di, sir ;atribuie sirului sir indicele DI
@1:mov ah, 1 ;citeste char
int 16h
cmp al, 13
je @2 ;cat timp nu e ENTER
inc di ;crestem indicele
mov sir[di], al ;punem pe pozitia DI din sir caracterul citit in AL
jmp @1 ;reluam
@2:inc di ;adaugam un $(pentru final...)
mov sir[di], '$'
mov ah, 9 ;tiparim sirul
lea dx, sir
int 21h
mov ah, 4ch
int 21h
code ends
end