1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| ;
; Encodage d'un nombre hexadecimal dans un byte
;
INCLUDE conio.inc
INCLUDE numtoalfa.inc
.MODEL small,stdcall
.STACK 4096
.386
dumpregs PROTO
.DATA
msgencode db "Encodez votre nombre hexadecimal (max FF) $"
msgerreur db "Erreur de débordement ...$"
msgchoix db "Voulez-vous annuler le nombre (r) ou quitter (q) : $"
msgmerci db "Merci d'utiliser notre programme !$"
base db 16
digit db 0
nombre db 0
.CODE
main proc
mov ax,@data
mov ds,ax
mov es,ax
EncodeNombre:
clrscr
gotoxy 2,2
mov ah,09h
mov dx,offset msgencode
int 21h
mov nombre,0 ;contient la valeur du nombre
EncodeChiffre:
mov ah,01h
int 21h
cmp al,13 ;est ce le retour chariot?
je Affiche ; oui alors on affiche
cmp al,'0' ; non, on compare à '0'=30h
jl PasChiffre ; si <, alors on recommence
cmp al,'9' ; on compare à '9'=39h
jg EncodeLettre
sub al,30h ;on passe du chiffre à sa valeur reelle
mov digit,al ; on la recopie dans digit
mov al,nombre
mul base
jc ErreurCarry ; si debordement...
mov nombre,al ;si ok alors on retranscrit
mov al,digit
add nombre,al
jc ErreurCarry
jmp EncodeChiffre
EncodeLettre:
cmp al,'A'
jl PasChiffre
cmp al,'F'
jg PasChiffre
sub al,37h
mov digit,al
mov al,nombre
mul base
jc ErreurCarry
mov nombre,al
mov al,digit
add nombre,al
jc ErreurCarry
jmp EncodeChiffre
ErreurCarry:
gotoxy 2,8
mov ah,09h
mov dx,offset msgerreur
int 21h
gotoxy 2,9
mov ah,09h
mov dx,offset msgchoix
int 21h
tantque:
mov ah,01h
int 21h
cmp al,'r'
je EncodeNombre
cmp al,'q'
je fin
mov ah,2
mov dl,8
int 21h
jmp tantque
PasChiffre:
mov ah,2
mov dl,8
int 21h
jmp EncodeChiffre
Affiche:
gotoxy 2,10
btoadun nombre
mov ah,02h
mov dl,' '
int 21h
btoah nombre
mov ah,02h
mov dl,' '
int 21h
btoab nombre
fin:
gotoxy 2,12
mov ah,09h
mov dx,offset msgmerci
int 21h
sortie:
mov ah, 00h
int 16h
; fin du programme
mov ah, 4Ch
mov al,0
int 21h
; et retour au DOS
main ENDP
END main |
Partager