Programmation 8086 Sous Programme PDF
Programmation 8086 Sous Programme PDF
Exercice 3:
data segment
entry_msg db "Enter 9 numbers $"
numbers_array db 9 dup (?)
ones db ?
zeros db ?
one_msg db 10, 13, "Number of ones is: $"
zero_msg db 10, 13, "Number of zeros is: $"
ends
stack segment
dw 128 dup(0)
ends
code segment
read proc
mov ah, 09h
mov dl, offset entry_msg
int 21h
mov cx, 8
boucle_read:
mov ah, 01h
int 21h
sub al, 030h
mov [si], al
inc si
mov ah, 02h
mov dl, ','
int 21h
loop boucle_read
ret
read endp
countOnesAndZeros proc
mov dl, 0
mov bl, 0
mov cx, 8
boucle_countOnesAndZeros:
mov al, [si]
cmp al, 0
je zero_found
cmp al, 1
je one_found
back:
inc si
loop boucle_countOnesAndZeros
jmp exit_countOnesAndZeros
zero_found:
add bl, 1
jmp back
one_found:
add dl, 1
jmp back
exit_countOnesAndZeros:
mov ones, dl
mov zeros, bl
mov ah, 09h
mov dl, offset one_msg
int 21h
mov ah, 02h
mov dl, ones
add dl, 030h
int 21h
mov ah, 09h
mov dl, offset zero_msg
int 21h
mov ah, 02h
mov dl, zeros
add dl, 030h
int 21h
ret
countOnesAndZeros endp
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
data segment
entry_msg db "Enter 3 numbers: $"
tab db 3 dup (?)
success_msg db 10, 13, "The 3 sizes can form a triangle $"
ends
stack segment
dw 128 dup(0)
ends
code segment
read proc
mov ah, 09h
mov dl, offset entry_msg
int 21h
mov cx, 3
boucle:
mov ah, 01h
int 21h
sub al, 030h
mov [si], al
mov ah, 02h
mov dl, ','
int 21h
inc si
loop boucle
ret
read endp
condition_triangle proc
mov al, [si]
mov bl, [si+1]
mov cl, [si+2]
mov dl, bl
add dl, cl
cmp al, dl
ja exit
mov dl, al
add dl, bl
cmp cl, dl
ja exit
mov dl, al
add dl, cl
cmp bl, dl
ja exit
mov ah, 09h
mov dl, offset success_msg
int 21h
exit:
ret
condition_triangle endp
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax