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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
|
segment .data
buffer: times 1 db 0
choix_lu: times 1 db 0
chaine_lue: times 33 db 0
len: db 0
len2: db 0
maxLen: equ 32
options: db "Voici les options disponibles", 10
options_len equ $-options
choix_1: db "1) Entrer une chaine", 10
choix_1_len equ $-choix_1
choix_2: db "2) Transformer en miniscules", 10
choix_2_len equ $-choix_2
choix_3: db "3) Transformer en majuscules", 10
choix_3_len equ $-choix_3
choix_4: db "4) Quitter", 10
choix_4_len equ $-choix_4
choix_invalide: db "Le choix entre est invalide...", 10
choix_invalide_len equ $-choix_invalide
chaine_vide: db "La chaine est vide" , 10
choix_vide_len equ $-chaine_vide
contenu_chaine: db "La chaine contient : "
contenu_chaine_len equ $-contenu_chaine
contenu_chaine2: db "La chaine contient : ", 10
contenu_chaine_len2 equ $-contenu_chaine
demande_chaine: db "Entrez une chaine : ", 10
demande_chaine_len equ $-demande_chaine
demande_choix: db "Entrez votre choix : ", 10
demande_choix_len equ $-demande_choix
message_quitter: db "Au revoir" , 10
message_quitter_len equ $-message_quitter
message_trop_long db "La chaine est trop longue..", 10
message_trop_long_len equ $-message_trop_long
saut_ligne: db 0xa
segment .bss
chaineMin: times 33 db 0
chaineMaj: times 33 db 0
segment .text
global _start
_start:
;;if: cmp eax, ""
;;jnz Then
;;jnb Else
;;Then: mov eax, 4
;;mov ebx, 1
;;mov ecx, chaine_vide
;;int 0x80
;;Else: mov eax, 4
menu:
;;Affichage du message avant chaine_lue
; mov eax, 4
; mov ebx, 1
; mov ecx, contenu_chaine2
; mov edx, contenu_chaine_len2
; int 0x80
; ;; Affichage de la chaine contenue dans chaine_lue
; mov eax, 4
; mov ebx, 1
; mov ecx, chaine_lue
; mov edx, maxLen
; int 0x80
;; Affiche options
mov eax, 4
mov ebx, 1
mov ecx, options
mov edx, options_len
int 0x80
;; Affiche choix_1
mov eax, 4
mov ebx, 1
mov ecx, choix_1
mov edx, choix_1_len
int 0x80
;; Affiche choix_2
mov eax, 4
mov ebx, 1
mov ecx, choix_2
mov edx, choix_2_len
int 0x80
;; Affiche choix_3
mov eax, 4
mov ebx, 1
mov ecx, choix_3
mov edx, choix_3_len
int 0x80
;; Affiche choix_4
mov eax, 4
mov ebx, 1
mov ecx, choix_4
mov edx, choix_4_len
int 0x80
;; Saut de ligne
mov eax, 4
mov ebx, 1
mov ecx, saut_ligne
mov edx, 1
int 0x80
;; Message qui demande à l'utilisateur d'entrer son choix
mov eax, 4
mov ebx, 1
mov ecx, demande_choix
mov edx, demande_choix_len
int 0x80
;;Lecture choix
mov eax, 3
mov ebx, 0
mov ecx, choix_lu
mov edx, 1
int 0x80
;; vider buffer
mov eax, 3
mov ebx, 0
mov ecx, buffer
mov edx, 1
int 0x80
;; switch
mov al,[choix_lu]
case_1:
cmp al,'1'
jnz case_2
mov eax, 4
mov ebx, 1
mov ecx, demande_chaine
mov edx, demande_chaine_len
int 0x80
mov eax, 3
mov ebx, 0
mov ecx, chaine_lue
mov edx, maxLen
int 0x80
mov eax, 4
mov ebx, 1
mov ecx, contenu_chaine
mov edx, contenu_chaine_len
int 0x80
mov eax, 4
mov ebx, 1
mov ecx, chaine_lue
mov edx, maxLen
int 0x80
mov bl, [len]
cmp bl, maxLen
jae case_1
jmp finSwitch
case_2:
cmp al,'2'
jnz case_3
;; calcule de la longueur effective
mov eax,chaine_lue
mov ch,-1 ; pour ne pas inclure le retour a la ligne dans la longueur
encore:
mov cl,[eax]
inc ch
inc eax
mov bl,maxLen
cmp ch,bl
jl noBuffer
;; le vider maintenant
vider:
mov eax, 3
mov ebx, 0
mov ecx, buffer
mov edx, 1
int 0x80
mov bl,[buffer]
cmp bl,10
jne vider
jmp finsi
noBuffer:
cmp cl,10
jne encore
mov [len],ch
;; Conversion vers minuscule
mov ebx,chaine_lue
mov edx,chaineMin
mov cl, 'a'
sub cl, 'A'
xor ch, ch
refaire:
mov al, [ebx]
add al,cl
cmp al,'z'
jna finsi
mov al,[ebx] ;pas de changement
finsi:
mov [edx],al
inc ch
inc ebx
inc edx
cmp ch,[len]
jl refaire
mov eax, 4
mov ebx, 1
mov ecx, contenu_chaine
mov edx, contenu_chaine_len
int 0x80
;; Affiche chaine minuscule
mov eax, 4
mov ebx, 1
mov ecx, chaineMin
mov edx, [len]
int 0x80
jmp finSwitch
case_3:
cmp al,'3'
jnz case_4
;; calcule de la longueur effective
mov eax,chaine_lue
mov ch,-1 ; pour ne pas inclure le retour a la ligne dans la longueur
encore2:
mov cl,[eax]
inc ch
inc eax
mov bl,maxLen
cmp ch,bl
jl noBuffer2
;;; vider buffer ici et jump finlecture
mov bl,10
mov [eax-1],bl ;marque la fin de chaine
mov [len],ch
;; le vider maintenant
vider2:
mov eax, 3
mov ebx, 0
mov ecx, buffer
mov edx, 1
int 0x80
mov bl,[buffer]
cmp bl,10
jne vider2
jmp finsi2
noBuffer2:
cmp cl,10
jne encore2
mov [len],ch
;; Conversion vers majuscule
mov ebx,chaine_lue
mov edx,chaineMaj
mov cl, 'a'
sub cl, 'A'
xor ch, ch
refaire2:
mov al, [ebx]
sub al,cl
cmp al,'A'
jnb finsi2
mov al,[ebx] ;pas de changement
finsi2:
mov [edx],al
inc ch
inc ebx
inc edx
cmp ch,[len]
jl refaire2
mov eax, 4
mov ebx, 1
mov ecx, contenu_chaine
mov edx, contenu_chaine_len
int 0x80
;; Affiche chaine majuscule
mov eax, 4
mov ebx, 1
mov ecx, chaineMaj
mov edx, [len]
int 0x80
jmp finSwitch
case_4:
cmp al,'4'
mov eax, 4
mov ebx, 1
mov ecx, message_quitter
mov edx, message_quitter_len
int 0x80
jmp fin
;;Aficher cas invalid
case_default:
mov ecx, choix_invalide
mov edx, choix_invalide_len
mov eax, 4
mov ebx, 1
int 0x80
jmp finSwitch
finSwitch:
mov ebp,ecx
mov esi,edx
xor eax, eax ; initialisation du registre
b_lecture:
cmp eax, 4
je b_lecture_fin
mov eax, 4
mov ebx, 1
mov ecx, saut_ligne
mov edx, 1
int 0x80
jmp menu
b_lecture_fin:
mov ebp,ecx
mov esi,edx
;;; Sort du programme
fin:
mov ebx, 0
mov eax, 1
int 0x80 |
Partager