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
| SECTION .data
valeur dw 23268
bitsmax db 16
texte_a db "Rotation",10
length_a equ $-texte_a
texte_b db "Limite d'un mot atteinte",10
length_b equ $-texte_b
texte_c db "Nombre de 1: "
length_c equ $-texte_c
texte_d db "CF à 1",10
length_d equ $-texte_d
; SECTION .bss
; Block Starting Symbol
; Variables statiques ou non initialisées qui sont censées
; changer pendant l'exécution du programme
SECTION .bss
; Programme principal
SECTION .text
global _start
_start:
mov bx,0 ; compteur de 1
mov ax,0 ; compteur de bits (ici 16 maximum <-> DW est un mot de 16 bits)
clc ; clear carry flag
mov WORD cx,[valeur]
rotation:
rcl cx,1 ; on shift de 1 bit vers la gauche
jc additionner ; si le carry flag est à 1 on additionne
push ax
push bx
push cx
mov ax,4
mov bx,1
mov ecx,texte_a
mov dx,length_a
int 80H
pop cx
pop bx
pop ax
inc ax
cmp ax,15 ; si nous atteignons 16 rotations il faut arrêter le processus -> zf est à 1 si ax = dx
clc ; reset the CF
jz afficher
jnz rotation ; sinon on continue la rotation
additionner:
push ax
push bx
push cx
mov ax,4
mov bx,1
mov ecx,texte_d
mov dx,length_d
int 80H
pop cx
pop bx
pop ax
inc bx
clc
jmp rotation
afficher:
push ax
push bx
push cx
mov ax,4
mov bx,1
mov ecx,texte_b
mov dx,length_b
int 80H
mov ax,4
mov bx,1
mov ecx,texte_c
mov dx,length_c
int 80H
pop cx
pop bx
pop ax
cmp bx,9 ; si il y a plus de un digit il faut faire un traitement spécial
ja displaydigits
mov WORD [valeur],bx
add WORD [valeur],48 ; si valeur de bx plus petite on afficher le nombre (+48 pour que ce soit affichable à l'écran)
mov ax,4
mov bx,1
mov ecx,valeur
mov dx,1
int 80H
mov BYTE [valeur],10
mov ax,4
mov bx,1
mov ecx,valeur
mov dx,1
int 80H
jmp fin
displaydigits:
fin:
mov eax,1
mov ebx,0
int 80H |
Partager