ClementColmerauer commited on 2024-10-20 09:30:55
Showing 11 changed files, with 1931 additions and 0 deletions.
| ... | ... |
@@ -0,0 +1,134 @@ |
| 1 |
+\documentclass[a4paper, 10pt]{article}
|
|
| 2 |
+ |
|
| 3 |
+\input{$LATEX_HEADER}
|
|
| 4 |
+ |
|
| 5 |
+\begin{document}
|
|
| 6 |
+% Page de titre |
|
| 7 |
+\begin{titlepage}
|
|
| 8 |
+ \headingfont |
|
| 9 |
+ \vfill |
|
| 10 |
+ \vspace{2.5in}
|
|
| 11 |
+ \begin{flushleft}
|
|
| 12 |
+ \HUGE\textbf{TRAVAIL\\PRATIQUE :}\\ARCHITECTURE\\DES ORDINATEURS
|
|
| 13 |
+ \end{flushleft}
|
|
| 14 |
+ \vspace{1in}
|
|
| 15 |
+ \begin{flushleft}
|
|
| 16 |
+ \Large\textsc{CESANO UGO\\COLMERAUER CLÉMENT}
|
|
| 17 |
+ \hfill |
|
| 18 |
+ 2024 |
|
| 19 |
+ \end{flushleft}
|
|
| 20 |
+\end{titlepage}
|
|
| 21 |
+ |
|
| 22 |
+ |
|
| 23 |
+\tableofcontents |
|
| 24 |
+\newpage |
|
| 25 |
+ |
|
| 26 |
+\begin{enonce}
|
|
| 27 |
+Dans ce travail pratique, nous devons mettre en place un système d'enregistrement du personnel programmé un assembleur x86 32-bit sous Linux. |
|
| 28 |
+ |
|
| 29 |
+ |
|
| 30 |
+Le programme doit permettre les opérations suivantes : |
|
| 31 |
+\begin{enumerate}
|
|
| 32 |
+\item Enregistrer du personnel |
|
| 33 |
+\item Lister des personnes enregistrées |
|
| 34 |
+\item Afficher une personne spécifique |
|
| 35 |
+\item Afficher la personne la plus jeune |
|
| 36 |
+\item Quitter le programme |
|
| 37 |
+\end{enumerate}
|
|
| 38 |
+\end{enonce}
|
|
| 39 |
+ |
|
| 40 |
+\begin{remarqueImportante}
|
|
| 41 |
+Le programme ne vérifie pas si l'information entrée par l'utilisateur respècte les conventions données dans ce document, le programme fonctionnera comme demandé si et seulement si l'on respecte celles-ci. |
|
| 42 |
+\end{remarqueImportante}
|
|
| 43 |
+ |
|
| 44 |
+\begin{remarque}
|
|
| 45 |
+Nous avons choisi d'enregistrer les informations des personnes dans un fichier CSV, celui-ci sera nommé \hl{\texttt{registry.csv}} et est situé dans le répertoire contenant l'exécutable.
|
|
| 46 |
+\end{remarque}
|
|
| 47 |
+ |
|
| 48 |
+\newpage |
|
| 49 |
+ |
|
| 50 |
+\section{Enregistrement du personnel}
|
|
| 51 |
+L'enregistrement d'une nouvelle personne se déroule de la manière suivante : |
|
| 52 |
+\begin{enumerate}
|
|
| 53 |
+\item L'utilisateur entre la commande d'enregistrement (\hl{\texttt{r}}) dans l'invite de commande principal (\hl{\texttt{>}}) :
|
|
| 54 |
+\begin{verbatim}
|
|
| 55 |
+> r |
|
| 56 |
+: |
|
| 57 |
+\end{verbatim}
|
|
| 58 |
+\item L'invite de commande secondaire (\hl{\texttt{:}}) s'affiche, on y entre le nom puis l'age séparés d'un espace :
|
|
| 59 |
+\begin{verbatim}
|
|
| 60 |
+> r |
|
| 61 |
+: Zaphod 42 |
|
| 62 |
+> |
|
| 63 |
+\end{verbatim}
|
|
| 64 |
+\item On valide les instructions avec la touche retour. |
|
| 65 |
+\end{enumerate}
|
|
| 66 |
+ |
|
| 67 |
+ |
|
| 68 |
+À ce moment là, le programme ajoute la personne à la fin du fichier \hl{\texttt{registry.csv}} en incrémentant le numéro de celle-ci depuis le numéro de la personne précédente.
|
|
| 69 |
+ |
|
| 70 |
+ |
|
| 71 |
+Le programme remplace l'espace entre le nom et l'age de la personne par une virgule, respectant ainsi, la convention des fichier CSV. |
|
| 72 |
+ |
|
| 73 |
+ |
|
| 74 |
+Il ouvre le fichier en écriture seule, écrit les informations puis referme le fichier avant de retourner à l'invite de commande principal. |
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+\begin{remarque}
|
|
| 78 |
+Si le fichier \hl{\texttt{registry.csv}} n'existe pas, le programme le crée lors de l'ajout de la première personne.
|
|
| 79 |
+\end{remarque}
|
|
| 80 |
+ |
|
| 81 |
+ |
|
| 82 |
+Le programme peut enregistrer au maximum $2^{32}$ personnes dont l'age varie entre $0$ et $2^{32}$. Cette borne supérieur est dûe à l'architecture IA-32 qui fonctionne avec des mots de 32 bits.
|
|
| 83 |
+ |
|
| 84 |
+ |
|
| 85 |
+\section{Lister les personnes enregistrées}
|
|
| 86 |
+L'utilisateur doit entrer la commande de listage (\hl{\texttt{l}}) dans l'invite de commande principal (\hl{\texttt{>}}).
|
|
| 87 |
+ |
|
| 88 |
+Le programme ouvre le fichier en lecture seule, et affiche le fichier en remplaçant les virgules par des espaces. |
|
| 89 |
+ |
|
| 90 |
+ |
|
| 91 |
+Lorsque le contenu du fichier est entièrement affiché, le programme ferme le fichier et retourne à l'invite de commande principal. |
|
| 92 |
+ |
|
| 93 |
+\newpage |
|
| 94 |
+ |
|
| 95 |
+\section{Afficher une personne spécifique}
|
|
| 96 |
+L'affichage d'une personne spécifique se déroule de la manière suivante : |
|
| 97 |
+\begin{enumerate}
|
|
| 98 |
+\item L'utilisateur entre la commande de recherche (\hl{\texttt{s}}) dans l'invite de commande principal (\hl{\texttt{>}}) :
|
|
| 99 |
+\begin{verbatim}
|
|
| 100 |
+> s |
|
| 101 |
+: |
|
| 102 |
+\end{verbatim}
|
|
| 103 |
+\item L'invite de commande secondaire (\hl{\texttt{:}}) s'affiche, on y entre le numéro de la personne recherchée :
|
|
| 104 |
+\begin{verbatim}
|
|
| 105 |
+> r |
|
| 106 |
+: 1 |
|
| 107 |
+1 Zaphod 42 |
|
| 108 |
+> |
|
| 109 |
+\end{verbatim}
|
|
| 110 |
+\item On valide les instructions avec la touche retour. |
|
| 111 |
+\end{enumerate}
|
|
| 112 |
+ |
|
| 113 |
+ |
|
| 114 |
+Le programme lit le numéro de l'utilisateur sous forme de chaîne de caractères dans l'invite de commande secondaire, le convertit en entier puis affiche la personne à la ligne égale à ce dernier. |
|
| 115 |
+ |
|
| 116 |
+\section{Afficher la personne la plus jeune}
|
|
| 117 |
+L'utilisateur doit entrer la commande de listage (\hl{\texttt{y}}) dans l'invite de commande principal (\hl{\texttt{>}}).
|
|
| 118 |
+ |
|
| 119 |
+ |
|
| 120 |
+Le programme compare l'age de toutes les personnes enregistrées et enregistre le numéro de la personne ayant l'age minimal. |
|
| 121 |
+ |
|
| 122 |
+ |
|
| 123 |
+Ensuite, celui-ci l'affiche de le même manière que la seconde partie de l'opération de recherche. |
|
| 124 |
+ |
|
| 125 |
+\begin{remarque}
|
|
| 126 |
+S'il y a plus d'une personne avec l'age minimal, la dernière est choisie. |
|
| 127 |
+\end{remarque}
|
|
| 128 |
+ |
|
| 129 |
+ |
|
| 130 |
+\section{Quitter le programme}
|
|
| 131 |
+On quitte le programme en entrant la commande \hl{\texttt{q}} dans l'invite de commande principal (\hl{\texttt{>}}).
|
|
| 132 |
+ |
|
| 133 |
+ |
|
| 134 |
+\end{document}
|
| ... | ... |
@@ -0,0 +1,596 @@ |
| 1 |
+global _start |
|
| 2 |
+ |
|
| 3 |
+ |
|
| 4 |
+section .data |
|
| 5 |
+ |
|
| 6 |
+; Texte et message à afficher dans la sortie standard |
|
| 7 |
+mainPrompt: db "> " |
|
| 8 |
+mainPromptLength: equ $-mainPrompt |
|
| 9 |
+secondaryPrompt: db ": " |
|
| 10 |
+secondaryPromptLength: equ $-secondaryPrompt |
|
| 11 |
+welcomeMessage: db "COMPUTER ARCHITECTURE PROJET: REGISTRATION PROGRAM", 10, "Press 'h' or return key for a list of the available commands.", 10 |
|
| 12 |
+welcomeMessageLength: equ $-welcomeMessage |
|
| 13 |
+helpMessage: db "Available commands:", 10, " r - Register a new person", 10, " l - Lists all registered persons", 10, " s - Search and display a specific person", 10, " y - Display the youngest person registered", 10, " q - Quit the program", 10 |
|
| 14 |
+helpMessageLength: equ $-helpMessage |
|
| 15 |
+commandErrorMessage: db "ERROR: Unknown command.", 10, 7 |
|
| 16 |
+commandErrorMessageLength: equ $-commandErrorMessage |
|
| 17 |
+fileErrorMessage: db "ERROR: No registry file, please create one.", 10, 7 |
|
| 18 |
+fileErrorMessageLength: equ $-fileErrorMessage |
|
| 19 |
+numberErrorMessage: db "ERROR: Not a number.", 10, 7 |
|
| 20 |
+numberErrorMessageLength: equ $-numberErrorMessage |
|
| 21 |
+searchErrorMessage: db "ERROR: Requested person not found.", 10, 7 |
|
| 22 |
+searchErrorMessageLength: equ $-searchErrorMessage |
|
| 23 |
+space: db ' ' |
|
| 24 |
+spaceLength: equ $-space |
|
| 25 |
+comma: db ',' |
|
| 26 |
+commaLength: equ $-comma |
|
| 27 |
+ |
|
| 28 |
+; Fichier |
|
| 29 |
+fileName: db "registry.csv" |
|
| 30 |
+fd : dw 0 |
|
| 31 |
+ |
|
| 32 |
+; Mémoire tampon |
|
| 33 |
+mainPromptBuffer: db 2 dup(0) |
|
| 34 |
+secondaryPromptBuffer: db 1024 dup(0) |
|
| 35 |
+generalPurposeBuffer: db 8192 dup(0) |
|
| 36 |
+numberBuffer: db 12 |
|
| 37 |
+ |
|
| 38 |
+ |
|
| 39 |
+section .text |
|
| 40 |
+ |
|
| 41 |
+_start: |
|
| 42 |
+ ; Message informatif au démarrage du programme |
|
| 43 |
+ mov eax, 4 |
|
| 44 |
+ mov ebx, 1 |
|
| 45 |
+ mov ecx, welcomeMessage |
|
| 46 |
+ mov edx, welcomeMessageLength |
|
| 47 |
+ int 80h |
|
| 48 |
+ |
|
| 49 |
+ ; Gestion de l'invite de commande principal |
|
| 50 |
+ .prompt: |
|
| 51 |
+ ; Affichage de l'invite de commande |
|
| 52 |
+ mov eax, 4 |
|
| 53 |
+ mov ebx, 1 |
|
| 54 |
+ mov ecx, mainPrompt |
|
| 55 |
+ mov edx, mainPromptLength |
|
| 56 |
+ int 80h |
|
| 57 |
+ ; Lecture de la commande entrée par l'utilisateur |
|
| 58 |
+ mov eax, 3 |
|
| 59 |
+ mov ebx, 0 |
|
| 60 |
+ mov ecx, mainPromptBuffer |
|
| 61 |
+ mov edx, 2 |
|
| 62 |
+ int 80h |
|
| 63 |
+ ; Gestion des différentes opération du programme selon la commande reçue |
|
| 64 |
+ cmp eax, 0 |
|
| 65 |
+ jle .error |
|
| 66 |
+ cmp byte [mainPromptBuffer], 10 ; Affiche l'aide si l'on appuie sur la touche retour |
|
| 67 |
+ je .help |
|
| 68 |
+ cmp byte [mainPromptBuffer + 1], 10 |
|
| 69 |
+ jne .flush |
|
| 70 |
+ cmp byte [mainPromptBuffer], "h" |
|
| 71 |
+ je .help |
|
| 72 |
+ cmp byte [mainPromptBuffer], "r" |
|
| 73 |
+ je .register |
|
| 74 |
+ cmp byte [mainPromptBuffer], "l" |
|
| 75 |
+ je .list |
|
| 76 |
+ cmp byte [mainPromptBuffer], "s" |
|
| 77 |
+ je .search |
|
| 78 |
+ cmp byte [mainPromptBuffer], "y" |
|
| 79 |
+ je .youngest |
|
| 80 |
+ cmp byte [mainPromptBuffer], "q" |
|
| 81 |
+ je .quit |
|
| 82 |
+ jmp .error |
|
| 83 |
+ |
|
| 84 |
+ .help: |
|
| 85 |
+ mov eax, 4 |
|
| 86 |
+ mov ebx, 1 |
|
| 87 |
+ mov ecx, helpMessage |
|
| 88 |
+ mov edx, helpMessageLength |
|
| 89 |
+ int 80h |
|
| 90 |
+ jmp .prompt |
|
| 91 |
+ |
|
| 92 |
+ .register: |
|
| 93 |
+ call register |
|
| 94 |
+ jmp .prompt |
|
| 95 |
+ |
|
| 96 |
+ .list: |
|
| 97 |
+ call list |
|
| 98 |
+ jmp .prompt |
|
| 99 |
+ |
|
| 100 |
+ .search: |
|
| 101 |
+ call search |
|
| 102 |
+ jmp .prompt |
|
| 103 |
+ |
|
| 104 |
+ .youngest: |
|
| 105 |
+ call youngest |
|
| 106 |
+ jmp .prompt |
|
| 107 |
+ |
|
| 108 |
+ .flush: |
|
| 109 |
+ mov eax, 3 |
|
| 110 |
+ mov ebx, 0 |
|
| 111 |
+ mov ecx, mainPromptBuffer |
|
| 112 |
+ mov edx, 1 |
|
| 113 |
+ int 80h |
|
| 114 |
+ cmp byte [mainPromptBuffer], 10 |
|
| 115 |
+ jne .flush |
|
| 116 |
+ jmp .error |
|
| 117 |
+ |
|
| 118 |
+ .error: |
|
| 119 |
+ ; Affichage d'un message d'erreur |
|
| 120 |
+ mov eax, 4 |
|
| 121 |
+ mov ebx, 2 |
|
| 122 |
+ mov ecx, commandErrorMessage |
|
| 123 |
+ mov edx, commandErrorMessageLength |
|
| 124 |
+ int 80h |
|
| 125 |
+ jmp .prompt |
|
| 126 |
+ |
|
| 127 |
+ ; Quitte le programme avec le valeur 0 (Succès) |
|
| 128 |
+ .quit: |
|
| 129 |
+ mov eax, 1 |
|
| 130 |
+ xor ebx, ebx |
|
| 131 |
+ int 80h |
|
| 132 |
+ |
|
| 133 |
+register: |
|
| 134 |
+ ; Ouverture du fichier en lecture seule |
|
| 135 |
+ mov eax, 5 |
|
| 136 |
+ mov ebx, fileName |
|
| 137 |
+ xor ecx, ecx |
|
| 138 |
+ mov edx, 0666o |
|
| 139 |
+ int 80h |
|
| 140 |
+ mov edi, 1 |
|
| 141 |
+ cmp eax, 0 |
|
| 142 |
+ jl .create |
|
| 143 |
+ |
|
| 144 |
+ mov esi, eax |
|
| 145 |
+ |
|
| 146 |
+ ; Calcul du nombre de lignes du fichier |
|
| 147 |
+ .while: |
|
| 148 |
+ mov eax, 3 |
|
| 149 |
+ mov ebx, esi |
|
| 150 |
+ mov ecx, generalPurposeBuffer |
|
| 151 |
+ mov edx, 1 |
|
| 152 |
+ int 80h |
|
| 153 |
+ cmp eax, 0 |
|
| 154 |
+ je .end_while |
|
| 155 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 156 |
+ je .inc |
|
| 157 |
+ jmp .while |
|
| 158 |
+ |
|
| 159 |
+ .inc: |
|
| 160 |
+ inc edi |
|
| 161 |
+ jmp .while |
|
| 162 |
+ |
|
| 163 |
+ .end_while: |
|
| 164 |
+ |
|
| 165 |
+ ; Fermeture du fichier ouvert en lecture |
|
| 166 |
+ mov eax, 6 |
|
| 167 |
+ mov ebx, esi |
|
| 168 |
+ int 80h |
|
| 169 |
+ |
|
| 170 |
+ ; Conversion de l'entier en chaîne de caractères |
|
| 171 |
+ mov eax, edi |
|
| 172 |
+ mov esi, numberBuffer |
|
| 173 |
+ mov byte [esi], 0 |
|
| 174 |
+ mov ebx, 10 |
|
| 175 |
+ xor ecx, ecx |
|
| 176 |
+ |
|
| 177 |
+ .convert: |
|
| 178 |
+ xor edx, edx |
|
| 179 |
+ div ebx |
|
| 180 |
+ add dl, 48 |
|
| 181 |
+ dec esi |
|
| 182 |
+ mov [esi], dl |
|
| 183 |
+ inc ecx |
|
| 184 |
+ cmp eax, 0 |
|
| 185 |
+ jne .convert |
|
| 186 |
+ |
|
| 187 |
+ mov edi, esi |
|
| 188 |
+ |
|
| 189 |
+ ; Affichage de l'invite de commande secondaire |
|
| 190 |
+ .open: |
|
| 191 |
+ push edi |
|
| 192 |
+ push ecx |
|
| 193 |
+ mov eax, 4 |
|
| 194 |
+ mov ebx, 1 |
|
| 195 |
+ mov ecx, secondaryPrompt |
|
| 196 |
+ mov edx, secondaryPromptLength |
|
| 197 |
+ int 80h |
|
| 198 |
+ |
|
| 199 |
+ ; Ouverture du fichier en écriture |
|
| 200 |
+ mov eax, 5 |
|
| 201 |
+ mov ebx, fileName |
|
| 202 |
+ mov ecx, 401h |
|
| 203 |
+ mov edx, 0666o |
|
| 204 |
+ int 80h |
|
| 205 |
+ |
|
| 206 |
+ ;cmp eax, 0 |
|
| 207 |
+ ;jbe .create |
|
| 208 |
+ |
|
| 209 |
+ mov esi, eax |
|
| 210 |
+ |
|
| 211 |
+ mov eax, 4 |
|
| 212 |
+ mov ebx, esi |
|
| 213 |
+ pop ecx |
|
| 214 |
+ mov edx, ecx |
|
| 215 |
+ pop edi |
|
| 216 |
+ mov ecx, edi |
|
| 217 |
+ int 80h |
|
| 218 |
+ |
|
| 219 |
+ mov eax, 4 |
|
| 220 |
+ mov ebx, esi |
|
| 221 |
+ mov ecx, comma |
|
| 222 |
+ mov edx, commaLength |
|
| 223 |
+ int 80h |
|
| 224 |
+ |
|
| 225 |
+ .write: |
|
| 226 |
+ mov eax, 3 |
|
| 227 |
+ xor ebx, ebx |
|
| 228 |
+ mov ecx, secondaryPromptBuffer |
|
| 229 |
+ mov edx, 1 |
|
| 230 |
+ int 80h |
|
| 231 |
+ |
|
| 232 |
+ mov edx, eax |
|
| 233 |
+ |
|
| 234 |
+ mov eax, 4 |
|
| 235 |
+ mov ebx, esi |
|
| 236 |
+ cmp byte [secondaryPromptBuffer], ' ' |
|
| 237 |
+ je .comma |
|
| 238 |
+ jmp .skip |
|
| 239 |
+ .comma: |
|
| 240 |
+ mov ecx, comma |
|
| 241 |
+ jmp .interrupt |
|
| 242 |
+ .skip: |
|
| 243 |
+ mov ecx, secondaryPromptBuffer |
|
| 244 |
+ .interrupt: |
|
| 245 |
+ int 80h |
|
| 246 |
+ cmp byte [secondaryPromptBuffer], 10 |
|
| 247 |
+ je .end |
|
| 248 |
+ jmp .write |
|
| 249 |
+ |
|
| 250 |
+ .create: |
|
| 251 |
+ mov eax, 5 |
|
| 252 |
+ mov ebx, fileName |
|
| 253 |
+ mov ecx, 100o |
|
| 254 |
+ mov edx, 0666o |
|
| 255 |
+ int 80h |
|
| 256 |
+ ; Fermeture du fichier |
|
| 257 |
+ mov ebx, eax |
|
| 258 |
+ mov eax, 6 |
|
| 259 |
+ int 80h |
|
| 260 |
+ jmp register |
|
| 261 |
+ |
|
| 262 |
+ .end: |
|
| 263 |
+ ; Fermeture du fichier |
|
| 264 |
+ mov eax, 6 |
|
| 265 |
+ mov ebx, esi |
|
| 266 |
+ int 80h |
|
| 267 |
+ ret |
|
| 268 |
+ |
|
| 269 |
+list: |
|
| 270 |
+ ; Ouverture du fichier regristry.csv |
|
| 271 |
+ mov eax, 5 |
|
| 272 |
+ mov ebx, fileName |
|
| 273 |
+ xor ecx, ecx |
|
| 274 |
+ mov edx, 0666o |
|
| 275 |
+ int 80h |
|
| 276 |
+ cmp eax, -2 ; Affiche une erreur si le fichier n'existe pas |
|
| 277 |
+ je .error |
|
| 278 |
+ |
|
| 279 |
+ mov esi, eax ; Copie du descripteur de fichier dans esi |
|
| 280 |
+ |
|
| 281 |
+ ; Affichage de la liste |
|
| 282 |
+ .loop: |
|
| 283 |
+ mov eax, 3 |
|
| 284 |
+ mov ebx, esi |
|
| 285 |
+ mov ecx, generalPurposeBuffer |
|
| 286 |
+ mov edx, 1 |
|
| 287 |
+ int 80h |
|
| 288 |
+ cmp eax, 0 |
|
| 289 |
+ jbe .end |
|
| 290 |
+ mov edx, eax |
|
| 291 |
+ mov eax, 4 |
|
| 292 |
+ mov ebx, 1 |
|
| 293 |
+ cmp byte [generalPurposeBuffer], ',' |
|
| 294 |
+ jne .nocomma |
|
| 295 |
+ mov ecx, space |
|
| 296 |
+ jmp .interrupt |
|
| 297 |
+ .nocomma: |
|
| 298 |
+ mov ecx, generalPurposeBuffer |
|
| 299 |
+ .interrupt: |
|
| 300 |
+ int 80h |
|
| 301 |
+ jmp .loop |
|
| 302 |
+ |
|
| 303 |
+ .error: |
|
| 304 |
+ mov eax, 4 |
|
| 305 |
+ mov ebx, 2 |
|
| 306 |
+ mov ecx, fileErrorMessage |
|
| 307 |
+ mov edx, fileErrorMessageLength |
|
| 308 |
+ int 80h |
|
| 309 |
+ ret |
|
| 310 |
+ |
|
| 311 |
+ .end: |
|
| 312 |
+ ; Fermeture du fichier |
|
| 313 |
+ mov eax, 6 |
|
| 314 |
+ mov ebx, esi |
|
| 315 |
+ int 80h |
|
| 316 |
+ ret |
|
| 317 |
+ |
|
| 318 |
+search: |
|
| 319 |
+ ; Affichage de l'invite de commande secondaire |
|
| 320 |
+ mov eax, 4 |
|
| 321 |
+ mov ebx, 1 |
|
| 322 |
+ mov ecx, secondaryPrompt |
|
| 323 |
+ mov edx, secondaryPromptLength |
|
| 324 |
+ int 80h |
|
| 325 |
+ |
|
| 326 |
+ xor edi, edi |
|
| 327 |
+ |
|
| 328 |
+ .convert: |
|
| 329 |
+ ; Lecture de l'entrée standard |
|
| 330 |
+ mov eax, 3 |
|
| 331 |
+ xor ebx, ebx |
|
| 332 |
+ mov ecx, secondaryPromptBuffer |
|
| 333 |
+ mov edx, 1 |
|
| 334 |
+ int 80h |
|
| 335 |
+ |
|
| 336 |
+ ; Conversion en entier |
|
| 337 |
+ xor ebx, ebx |
|
| 338 |
+ mov bl, [secondaryPromptBuffer] |
|
| 339 |
+ cmp ebx, 10 |
|
| 340 |
+ je .print |
|
| 341 |
+ |
|
| 342 |
+ sub ebx, 48 |
|
| 343 |
+ imul edi, 10 |
|
| 344 |
+ add edi, ebx |
|
| 345 |
+ jmp .convert |
|
| 346 |
+ |
|
| 347 |
+ .print: |
|
| 348 |
+ ; Ouverture du fichier regristry.csv |
|
| 349 |
+ mov eax, 5 |
|
| 350 |
+ mov ebx, fileName |
|
| 351 |
+ xor ecx, ecx |
|
| 352 |
+ mov edx, 0666o |
|
| 353 |
+ int 80h |
|
| 354 |
+ cmp eax, -2 ; Affiche une erreur si le fichier n'existe pas |
|
| 355 |
+ je .error |
|
| 356 |
+ |
|
| 357 |
+ mov esi, eax ; Copie du descripteur de fichier dans esi |
|
| 358 |
+ |
|
| 359 |
+ cmp edi, 1 ; Dans le cas où edi = 1, on passe la boucle |
|
| 360 |
+ je .loop |
|
| 361 |
+ |
|
| 362 |
+ .while: |
|
| 363 |
+ mov eax, 3 |
|
| 364 |
+ mov ebx, esi |
|
| 365 |
+ mov ecx, generalPurposeBuffer |
|
| 366 |
+ mov edx, 1 |
|
| 367 |
+ int 80h |
|
| 368 |
+ cmp eax, 0 |
|
| 369 |
+ je .end |
|
| 370 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 371 |
+ je .dec |
|
| 372 |
+ .next: |
|
| 373 |
+ cmp edi, 1 |
|
| 374 |
+ je .loop |
|
| 375 |
+ jmp .while |
|
| 376 |
+ |
|
| 377 |
+ ; Affichage de la ligne |
|
| 378 |
+ .loop: |
|
| 379 |
+ mov eax, 3 |
|
| 380 |
+ mov ebx, esi |
|
| 381 |
+ mov ecx, generalPurposeBuffer |
|
| 382 |
+ mov edx, 1 |
|
| 383 |
+ int 80h |
|
| 384 |
+ cmp eax, 0 |
|
| 385 |
+ jbe .unknown |
|
| 386 |
+ mov edx, eax |
|
| 387 |
+ mov eax, 4 |
|
| 388 |
+ mov ebx, 1 |
|
| 389 |
+ cmp byte [generalPurposeBuffer], ',' |
|
| 390 |
+ jne .nocomma |
|
| 391 |
+ mov ecx, space |
|
| 392 |
+ jmp .interrupt |
|
| 393 |
+ .nocomma: |
|
| 394 |
+ mov ecx, generalPurposeBuffer |
|
| 395 |
+ .interrupt: |
|
| 396 |
+ int 80h |
|
| 397 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 398 |
+ je .end |
|
| 399 |
+ jmp .loop |
|
| 400 |
+ |
|
| 401 |
+ .error: |
|
| 402 |
+ mov eax, 4 |
|
| 403 |
+ mov ebx, 2 |
|
| 404 |
+ mov ecx, fileErrorMessage |
|
| 405 |
+ mov edx, fileErrorMessageLength |
|
| 406 |
+ int 80h |
|
| 407 |
+ ret |
|
| 408 |
+ |
|
| 409 |
+ .unknown: |
|
| 410 |
+ mov eax, 4 |
|
| 411 |
+ mov ebx, 2 |
|
| 412 |
+ mov ecx, searchErrorMessage |
|
| 413 |
+ mov edx, searchErrorMessageLength |
|
| 414 |
+ int 80h |
|
| 415 |
+ ret |
|
| 416 |
+ |
|
| 417 |
+ .end: |
|
| 418 |
+ ; Fermeture du fichier |
|
| 419 |
+ mov eax, 6 |
|
| 420 |
+ mov ebx, esi |
|
| 421 |
+ int 80h |
|
| 422 |
+ ret |
|
| 423 |
+ |
|
| 424 |
+ .dec: |
|
| 425 |
+ dec edi |
|
| 426 |
+ jmp .next |
|
| 427 |
+ |
|
| 428 |
+youngest: |
|
| 429 |
+ ; Ouverture du fichier regristry.csv |
|
| 430 |
+ mov eax, 5 |
|
| 431 |
+ mov ebx, fileName |
|
| 432 |
+ xor ecx, ecx |
|
| 433 |
+ mov edx, 0666o |
|
| 434 |
+ int 80h |
|
| 435 |
+ cmp eax, -2 ; Affiche une erreur si le fichier n'existe pas |
|
| 436 |
+ je .error |
|
| 437 |
+ |
|
| 438 |
+ mov esi, eax |
|
| 439 |
+ |
|
| 440 |
+ xor eax, eax |
|
| 441 |
+ push eax |
|
| 442 |
+ push eax |
|
| 443 |
+ mov eax, 65536 |
|
| 444 |
+ push eax |
|
| 445 |
+ |
|
| 446 |
+ .get_ages: |
|
| 447 |
+ |
|
| 448 |
+ mov edi, 2 |
|
| 449 |
+ |
|
| 450 |
+ .get_to_age: |
|
| 451 |
+ mov eax, 3 |
|
| 452 |
+ mov ebx, esi |
|
| 453 |
+ mov ecx, generalPurposeBuffer |
|
| 454 |
+ mov edx, 1 |
|
| 455 |
+ int 80h |
|
| 456 |
+ |
|
| 457 |
+ cmp eax, 0 |
|
| 458 |
+ jbe .print |
|
| 459 |
+ |
|
| 460 |
+ cmp byte [generalPurposeBuffer], ',' |
|
| 461 |
+ je .dec_comma |
|
| 462 |
+ .dec_comma_ret: |
|
| 463 |
+ cmp edi, 0 |
|
| 464 |
+ jne .get_to_age |
|
| 465 |
+ |
|
| 466 |
+ .convert: |
|
| 467 |
+ mov eax, 3 |
|
| 468 |
+ mov ebx, esi |
|
| 469 |
+ mov ecx, generalPurposeBuffer |
|
| 470 |
+ mov edx, 1 |
|
| 471 |
+ int 80h |
|
| 472 |
+ |
|
| 473 |
+ cmp eax, 0 |
|
| 474 |
+ jbe .print |
|
| 475 |
+ |
|
| 476 |
+ ; Conversion en entier |
|
| 477 |
+ xor ebx, ebx |
|
| 478 |
+ mov bl, [generalPurposeBuffer] |
|
| 479 |
+ cmp ebx, 10 |
|
| 480 |
+ je .newline |
|
| 481 |
+ |
|
| 482 |
+ sub ebx, 48 |
|
| 483 |
+ imul edi, 10 |
|
| 484 |
+ add edi, ebx |
|
| 485 |
+ jmp .convert |
|
| 486 |
+ |
|
| 487 |
+ |
|
| 488 |
+ .newline: |
|
| 489 |
+ pop eax |
|
| 490 |
+ cmp eax, edi |
|
| 491 |
+ pop ebx |
|
| 492 |
+ inc ebx |
|
| 493 |
+ jbe .not_younger |
|
| 494 |
+ pop ecx |
|
| 495 |
+ mov ecx, ebx |
|
| 496 |
+ push ebx |
|
| 497 |
+ push ebx |
|
| 498 |
+ push edi |
|
| 499 |
+ jmp .get_ages |
|
| 500 |
+ .not_younger: |
|
| 501 |
+ push ebx |
|
| 502 |
+ push eax |
|
| 503 |
+ jmp .get_ages |
|
| 504 |
+ |
|
| 505 |
+ .print: |
|
| 506 |
+ pop eax |
|
| 507 |
+ pop edi |
|
| 508 |
+ pop edi |
|
| 509 |
+ |
|
| 510 |
+ cmp edi, 1 ; Dans le cas où edi = 1, on passe la boucle |
|
| 511 |
+ je .loop |
|
| 512 |
+ |
|
| 513 |
+ ; Fermeture du fichier |
|
| 514 |
+ mov eax, 6 |
|
| 515 |
+ mov ebx, esi |
|
| 516 |
+ int 80h |
|
| 517 |
+ ; Ouverture du fichier regristry.csv |
|
| 518 |
+ mov eax, 5 |
|
| 519 |
+ mov ebx, fileName |
|
| 520 |
+ xor ecx, ecx |
|
| 521 |
+ mov edx, 0666o |
|
| 522 |
+ int 80h |
|
| 523 |
+ cmp eax, -2 ; Affiche une erreur si le fichier n'existe pas |
|
| 524 |
+ je .error |
|
| 525 |
+ |
|
| 526 |
+ mov esi, eax ; Copie du descripteur de fichier dans esi |
|
| 527 |
+ |
|
| 528 |
+ .while: |
|
| 529 |
+ mov eax, 3 |
|
| 530 |
+ mov ebx, esi |
|
| 531 |
+ mov ecx, generalPurposeBuffer |
|
| 532 |
+ mov edx, 1 |
|
| 533 |
+ int 80h |
|
| 534 |
+ cmp eax, 0 |
|
| 535 |
+ je .end |
|
| 536 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 537 |
+ je .dec |
|
| 538 |
+ .next: |
|
| 539 |
+ cmp edi, 1 |
|
| 540 |
+ je .loop |
|
| 541 |
+ jmp .while |
|
| 542 |
+ |
|
| 543 |
+ ; Affichage de la ligne |
|
| 544 |
+ .loop: |
|
| 545 |
+ mov eax, 3 |
|
| 546 |
+ mov ebx, esi |
|
| 547 |
+ mov ecx, generalPurposeBuffer |
|
| 548 |
+ mov edx, 1 |
|
| 549 |
+ int 80h |
|
| 550 |
+ cmp eax, 0 |
|
| 551 |
+ jbe .unknown |
|
| 552 |
+ mov edx, eax |
|
| 553 |
+ mov eax, 4 |
|
| 554 |
+ mov ebx, 1 |
|
| 555 |
+ cmp byte [generalPurposeBuffer], ',' |
|
| 556 |
+ jne .nocomma |
|
| 557 |
+ mov ecx, space |
|
| 558 |
+ jmp .interrupt |
|
| 559 |
+ .nocomma: |
|
| 560 |
+ mov ecx, generalPurposeBuffer |
|
| 561 |
+ .interrupt: |
|
| 562 |
+ int 80h |
|
| 563 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 564 |
+ je .end |
|
| 565 |
+ jmp .loop |
|
| 566 |
+ |
|
| 567 |
+ .error: |
|
| 568 |
+ mov eax, 4 |
|
| 569 |
+ mov ebx, 2 |
|
| 570 |
+ mov ecx, fileErrorMessage |
|
| 571 |
+ mov edx, fileErrorMessageLength |
|
| 572 |
+ int 80h |
|
| 573 |
+ ret |
|
| 574 |
+ |
|
| 575 |
+ .unknown: |
|
| 576 |
+ mov eax, 4 |
|
| 577 |
+ mov ebx, 2 |
|
| 578 |
+ mov ecx, searchErrorMessage |
|
| 579 |
+ mov edx, searchErrorMessageLength |
|
| 580 |
+ int 80h |
|
| 581 |
+ ret |
|
| 582 |
+ |
|
| 583 |
+ .end: |
|
| 584 |
+ ; Fermeture du fichier |
|
| 585 |
+ mov eax, 6 |
|
| 586 |
+ mov ebx, esi |
|
| 587 |
+ int 80h |
|
| 588 |
+ ret |
|
| 589 |
+ |
|
| 590 |
+ .dec: |
|
| 591 |
+ dec edi |
|
| 592 |
+ jmp .next |
|
| 593 |
+ |
|
| 594 |
+ .dec_comma: |
|
| 595 |
+ dec edi |
|
| 596 |
+ jmp .dec_comma_ret |
| ... | ... |
@@ -0,0 +1,72 @@ |
| 1 |
+global _start |
|
| 2 |
+ |
|
| 3 |
+section .data |
|
| 4 |
+ |
|
| 5 |
+message: db "GWAK !", 10 |
|
| 6 |
+filename: db "file.txt", 0 |
|
| 7 |
+fd: dw 0 |
|
| 8 |
+buffer: dw 0 |
|
| 9 |
+ |
|
| 10 |
+section .text |
|
| 11 |
+ |
|
| 12 |
+_start: |
|
| 13 |
+ call open_wo |
|
| 14 |
+ call write |
|
| 15 |
+ call close |
|
| 16 |
+ |
|
| 17 |
+ call open_ro |
|
| 18 |
+ call read |
|
| 19 |
+ call print |
|
| 20 |
+ call close |
|
| 21 |
+ |
|
| 22 |
+ mov eax, 1 |
|
| 23 |
+ xor ebx, ebx |
|
| 24 |
+ int 80h |
|
| 25 |
+ |
|
| 26 |
+open_wo: |
|
| 27 |
+ mov eax, 5 |
|
| 28 |
+ mov ebx, filename |
|
| 29 |
+ mov ecx, 0101q |
|
| 30 |
+ mov edx, 0666q |
|
| 31 |
+ int 80h |
|
| 32 |
+ mov [fd], eax |
|
| 33 |
+ ret |
|
| 34 |
+ |
|
| 35 |
+open_ro: |
|
| 36 |
+ mov eax, 5 |
|
| 37 |
+ mov ebx, filename |
|
| 38 |
+ mov ecx, 0102q |
|
| 39 |
+ mov edx, 0666q |
|
| 40 |
+ int 80h |
|
| 41 |
+ mov [fd], eax |
|
| 42 |
+ ret |
|
| 43 |
+ |
|
| 44 |
+write: |
|
| 45 |
+ mov eax, 4 |
|
| 46 |
+ mov ebx, [fd] |
|
| 47 |
+ mov ecx, message |
|
| 48 |
+ mov edx, 7 |
|
| 49 |
+ int 80h |
|
| 50 |
+ ret |
|
| 51 |
+ |
|
| 52 |
+read: |
|
| 53 |
+ mov eax, 3 |
|
| 54 |
+ mov ebx, [fd] |
|
| 55 |
+ mov ecx, [buffer] |
|
| 56 |
+ mov edx, 7 |
|
| 57 |
+ int 80h |
|
| 58 |
+ ret |
|
| 59 |
+ |
|
| 60 |
+print: |
|
| 61 |
+ mov eax, 4 |
|
| 62 |
+ mov ebx, 1 |
|
| 63 |
+ mov ecx, byte [buffer] |
|
| 64 |
+ mov edx, 7 |
|
| 65 |
+ int 80h |
|
| 66 |
+ ret |
|
| 67 |
+ |
|
| 68 |
+close: |
|
| 69 |
+ mov eax, 6 |
|
| 70 |
+ mov ebx, [fd] |
|
| 71 |
+ int 80h |
|
| 72 |
+ ret |
| ... | ... |
@@ -0,0 +1,34 @@ |
| 1 |
+global _start |
|
| 2 |
+ |
|
| 3 |
+section .data |
|
| 4 |
+ |
|
| 5 |
+buffer: db 64 dup(0) |
|
| 6 |
+ |
|
| 7 |
+section .text |
|
| 8 |
+ |
|
| 9 |
+_start: |
|
| 10 |
+ xor esi, esi |
|
| 11 |
+ .convert: |
|
| 12 |
+ ; Lecture de l'entrée standard |
|
| 13 |
+ mov eax, 3 |
|
| 14 |
+ xor ebx, ebx |
|
| 15 |
+ mov ecx, buffer |
|
| 16 |
+ mov edx, 1 |
|
| 17 |
+ int 80h |
|
| 18 |
+ |
|
| 19 |
+ ; Conversion en entier |
|
| 20 |
+ xor ebx, ebx |
|
| 21 |
+ mov bl, [buffer] |
|
| 22 |
+ cmp ebx, 10 |
|
| 23 |
+ je .print |
|
| 24 |
+ |
|
| 25 |
+ sub ebx, 48 |
|
| 26 |
+ imul esi, 10 |
|
| 27 |
+ add esi, ebx |
|
| 28 |
+ jmp .convert |
|
| 29 |
+ |
|
| 30 |
+ ; Valeur de retour |
|
| 31 |
+ .print: |
|
| 32 |
+ mov eax, 1 |
|
| 33 |
+ xor ebx, ebx |
|
| 34 |
+ int 80h |
| ... | ... |
@@ -0,0 +1,193 @@ |
| 1 |
+global _start |
|
| 2 |
+;On considère le fichier contenant le personnel comme deja existant |
|
| 3 |
+;https://www.tutorialspoint.com/assembly_programming/assembly_file_management.htm |
|
| 4 |
+ |
|
| 5 |
+section .data |
|
| 6 |
+file: db "test.txt", 0 |
|
| 7 |
+lenfile: equ $-file |
|
| 8 |
+out: dw 0 |
|
| 9 |
+coma : db ',' |
|
| 10 |
+space : db ' ' |
|
| 11 |
+buffer : db 0 |
|
| 12 |
+ |
|
| 13 |
+ |
|
| 14 |
+ |
|
| 15 |
+section .text |
|
| 16 |
+; Entrée |
|
| 17 |
+; eax : entier à convertir |
|
| 18 |
+; esi : pointeur vers un buffer |
|
| 19 |
+; Sortie |
|
| 20 |
+; eax = pointeur vers le premier caractère de la chaîne de caractères |
|
| 21 |
+; ecx, longueur de la chaîne de caractères générée |
|
| 22 |
+toString: |
|
| 23 |
+ add esi, 9 |
|
| 24 |
+ mov byte[esi], 0 |
|
| 25 |
+ mov ebx, 10 |
|
| 26 |
+ xor ecx, ecx |
|
| 27 |
+ |
|
| 28 |
+ .while: |
|
| 29 |
+ xor edx, edx ; Nettoyage avant la division de edx:eax par ebx |
|
| 30 |
+ div ebx ; eax /= 10 |
|
| 31 |
+ add dl, '0' ; Convertion du reste en ASCII |
|
| 32 |
+ dec esi ; On stocke les caractère à l'envers |
|
| 33 |
+ mov [esi], dl |
|
| 34 |
+ inc ecx |
|
| 35 |
+ test eax, eax |
|
| 36 |
+ jnz .while ; On répètre jusqu'a ce que eax = 0 |
|
| 37 |
+ |
|
| 38 |
+ mov eax, esi |
|
| 39 |
+ ret |
|
| 40 |
+ |
|
| 41 |
+ |
|
| 42 |
+ |
|
| 43 |
+ |
|
| 44 |
+_start: |
|
| 45 |
+ |
|
| 46 |
+ ;ouverture fichier |
|
| 47 |
+ mov eax, 5 |
|
| 48 |
+ mov ebx, file |
|
| 49 |
+ mov ecx, 0x441 ;append/write/create if not existent |
|
| 50 |
+ mov edx, 0777o ;la totale |
|
| 51 |
+ int 80h |
|
| 52 |
+ mov esi,eax |
|
| 53 |
+ |
|
| 54 |
+ cmp eax,0 |
|
| 55 |
+ jbe end ;erreur ouverture |
|
| 56 |
+ |
|
| 57 |
+ mov esi, eax |
|
| 58 |
+ |
|
| 59 |
+ ;ecriture fichier |
|
| 60 |
+ ;mov eax, 4 |
|
| 61 |
+ ;mov ebx, esi |
|
| 62 |
+ ;mov ecx, msg |
|
| 63 |
+ ;mov edx, len |
|
| 64 |
+ ;int 80h |
|
| 65 |
+ |
|
| 66 |
+ cmp eax,0 |
|
| 67 |
+ jbe close ;erreur ecriture |
|
| 68 |
+ |
|
| 69 |
+ |
|
| 70 |
+ ;fermer fichier |
|
| 71 |
+ mov eax, 6 |
|
| 72 |
+ mov ebx, esi |
|
| 73 |
+ int 80h |
|
| 74 |
+ |
|
| 75 |
+ |
|
| 76 |
+ ;ouverture fichier |
|
| 77 |
+ mov eax, 5 |
|
| 78 |
+ mov ebx, file |
|
| 79 |
+ mov ecx, 0 ;read only |
|
| 80 |
+ mov edx, 0777o ;la totale |
|
| 81 |
+ int 80h |
|
| 82 |
+ mov esi,eax |
|
| 83 |
+ |
|
| 84 |
+ xor edi,edi |
|
| 85 |
+ |
|
| 86 |
+ |
|
| 87 |
+read_list : |
|
| 88 |
+ ;lecture |
|
| 89 |
+ mov eax, 3 |
|
| 90 |
+ mov ebx, esi |
|
| 91 |
+ mov ecx, buffer |
|
| 92 |
+ mov edx, 1 |
|
| 93 |
+ int 80h |
|
| 94 |
+ |
|
| 95 |
+ ;test si erreur |
|
| 96 |
+ cmp eax,0 |
|
| 97 |
+ jbe end_of_file |
|
| 98 |
+ |
|
| 99 |
+ cmp byte [buffer], ',' |
|
| 100 |
+ je inc_compt |
|
| 101 |
+ jmp read_list |
|
| 102 |
+ |
|
| 103 |
+inc_compt: |
|
| 104 |
+ inc edi |
|
| 105 |
+ jmp read_list |
|
| 106 |
+ |
|
| 107 |
+end_of_file: |
|
| 108 |
+ ; close the file |
|
| 109 |
+ mov eax, 6 |
|
| 110 |
+ mov ebx, esi |
|
| 111 |
+ int 80h |
|
| 112 |
+ |
|
| 113 |
+ |
|
| 114 |
+ mov eax,edi |
|
| 115 |
+ xor edx,edx |
|
| 116 |
+ mov ebx,2 |
|
| 117 |
+ div ebx |
|
| 118 |
+ add eax,1 |
|
| 119 |
+ |
|
| 120 |
+ |
|
| 121 |
+ ;On perd des trucs ici |
|
| 122 |
+ mov esi, out |
|
| 123 |
+ call toString |
|
| 124 |
+ mov edi, eax |
|
| 125 |
+ mov esi,ecx |
|
| 126 |
+ |
|
| 127 |
+ ;ouverture fichier |
|
| 128 |
+ mov eax, 5 |
|
| 129 |
+ mov ebx, file |
|
| 130 |
+ mov ecx, 0x401 ;append |
|
| 131 |
+ mov edx, 0777o ;la totale |
|
| 132 |
+ int 80h |
|
| 133 |
+ |
|
| 134 |
+ cmp eax,0 |
|
| 135 |
+ jbe end ;erreur ouverture |
|
| 136 |
+ |
|
| 137 |
+ ;écrit le numero (normalement) |
|
| 138 |
+ mov edx, esi |
|
| 139 |
+ mov ecx, edi |
|
| 140 |
+ mov ebx, eax |
|
| 141 |
+ mov esi,eax |
|
| 142 |
+ mov eax, 4 |
|
| 143 |
+ int 80h |
|
| 144 |
+ |
|
| 145 |
+ ;ecriture , |
|
| 146 |
+ mov eax, 4 |
|
| 147 |
+ mov ebx, esi |
|
| 148 |
+ mov ecx, coma |
|
| 149 |
+ mov edx, 1 |
|
| 150 |
+ int 80h |
|
| 151 |
+ |
|
| 152 |
+ |
|
| 153 |
+writing_loop : |
|
| 154 |
+ mov eax, 3 ;Lecture clavier |
|
| 155 |
+ mov ebx, 0 |
|
| 156 |
+ mov ecx, buffer |
|
| 157 |
+ mov edx, 1 |
|
| 158 |
+ int 80h |
|
| 159 |
+ |
|
| 160 |
+ |
|
| 161 |
+ cmp byte [buffer],' ' |
|
| 162 |
+ je print_coma |
|
| 163 |
+ |
|
| 164 |
+ |
|
| 165 |
+ mov eax, 4 ; Print |
|
| 166 |
+ mov ebx, esi |
|
| 167 |
+ mov ecx, buffer |
|
| 168 |
+ mov edx, 1 |
|
| 169 |
+ int 80h |
|
| 170 |
+ |
|
| 171 |
+ cmp byte [buffer],10 |
|
| 172 |
+ je end |
|
| 173 |
+ jmp writing_loop |
|
| 174 |
+ |
|
| 175 |
+print_coma : |
|
| 176 |
+ mov eax, 4 |
|
| 177 |
+ mov ebx, esi |
|
| 178 |
+ mov ecx, coma |
|
| 179 |
+ mov edx, 1 |
|
| 180 |
+ int 80h |
|
| 181 |
+ jmp writing_loop |
|
| 182 |
+ |
|
| 183 |
+close: |
|
| 184 |
+ ; close the file |
|
| 185 |
+ mov eax, 6 |
|
| 186 |
+ mov ebx, esi |
|
| 187 |
+ int 80h |
|
| 188 |
+ |
|
| 189 |
+ jmp end |
|
| 190 |
+end: |
|
| 191 |
+ mov eax, 1 |
|
| 192 |
+ xor ebx, ebx |
|
| 193 |
+ int 80h |
|
| 0 | 194 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,142 @@ |
| 1 |
+global _start |
|
| 2 |
+;On considère le fichier contenant le personnel comme deja existant |
|
| 3 |
+;https://www.tutorialspoint.com/assembly_programming/assembly_file_management.htm |
|
| 4 |
+ |
|
| 5 |
+section .data |
|
| 6 |
+file: db "test.txt", 0 |
|
| 7 |
+lenfile: equ $-file |
|
| 8 |
+out: dw 0 |
|
| 9 |
+coma : db ',' |
|
| 10 |
+buffer : db 0 |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+ |
|
| 14 |
+section .text |
|
| 15 |
+_start: |
|
| 16 |
+ |
|
| 17 |
+ ;ouverture fichier |
|
| 18 |
+ mov eax, 5 |
|
| 19 |
+ mov ebx, file |
|
| 20 |
+ mov ecx, 0 ;read only |
|
| 21 |
+ mov edx, 0777o ;la totale |
|
| 22 |
+ int 80h |
|
| 23 |
+ mov esi,eax |
|
| 24 |
+ |
|
| 25 |
+ xor edi,edi |
|
| 26 |
+ push edi ;On push 0 dans la pile pour la position du plus jeune |
|
| 27 |
+ mov edi,512 |
|
| 28 |
+ push edi ;Age du plus jeune |
|
| 29 |
+ mov edi, 1 |
|
| 30 |
+ push edi ;Position actuel |
|
| 31 |
+ xor edi,edi |
|
| 32 |
+ push edi ;Age actuelle |
|
| 33 |
+ |
|
| 34 |
+ |
|
| 35 |
+read_list : |
|
| 36 |
+ ;lecture |
|
| 37 |
+ mov eax, 3 |
|
| 38 |
+ mov ebx, esi |
|
| 39 |
+ mov ecx, buffer |
|
| 40 |
+ mov edx, 1 |
|
| 41 |
+ int 80h |
|
| 42 |
+ |
|
| 43 |
+ ;test si erreur |
|
| 44 |
+ cmp eax,0 |
|
| 45 |
+ jbe continue |
|
| 46 |
+ |
|
| 47 |
+ cmp byte [buffer], ',' |
|
| 48 |
+ je inc_compt |
|
| 49 |
+ jmp read_list |
|
| 50 |
+ |
|
| 51 |
+inc_compt: |
|
| 52 |
+ inc edi |
|
| 53 |
+ xor eax,eax |
|
| 54 |
+ xor edx,edx |
|
| 55 |
+ pop eax |
|
| 56 |
+ pop edx |
|
| 57 |
+ inc edx |
|
| 58 |
+ push edx |
|
| 59 |
+ push eax |
|
| 60 |
+ and edi,1 ;Modulo 2 |
|
| 61 |
+ cmp edi,0 |
|
| 62 |
+ je init_toInt |
|
| 63 |
+ jmp read_list |
|
| 64 |
+ |
|
| 65 |
+init_toInt : |
|
| 66 |
+ xor ebx,ebx |
|
| 67 |
+ mov ebx,10d |
|
| 68 |
+ |
|
| 69 |
+ mov eax, 3 ;lecture |
|
| 70 |
+ mov ebx, esi |
|
| 71 |
+ mov ecx, buffer |
|
| 72 |
+ mov edx, 1 |
|
| 73 |
+ int 80h |
|
| 74 |
+ |
|
| 75 |
+loop_toInt : |
|
| 76 |
+ pop eax ;Récupère age en cours de calcul |
|
| 77 |
+ mov ebx,10 |
|
| 78 |
+ xor ecx,ecx |
|
| 79 |
+ mov cl,[buffer] |
|
| 80 |
+ sub ecx, '0' ;Transforme char en sa valeur int |
|
| 81 |
+ mul ebx ;Multiplier eax par 10 |
|
| 82 |
+ add eax,ecx |
|
| 83 |
+ push eax |
|
| 84 |
+ |
|
| 85 |
+ ;lecture |
|
| 86 |
+ mov eax, 3 |
|
| 87 |
+ mov ebx, esi |
|
| 88 |
+ mov ecx, buffer |
|
| 89 |
+ mov edx, 1 |
|
| 90 |
+ int 80h |
|
| 91 |
+ |
|
| 92 |
+ ;test si erreur |
|
| 93 |
+ cmp eax,0 |
|
| 94 |
+ jbe continue |
|
| 95 |
+ |
|
| 96 |
+ cmp byte [buffer], 10 |
|
| 97 |
+ je test_plus_jeune |
|
| 98 |
+ jmp loop_toInt |
|
| 99 |
+ |
|
| 100 |
+test_plus_jeune : |
|
| 101 |
+ pop eax |
|
| 102 |
+ pop edx |
|
| 103 |
+ pop edi |
|
| 104 |
+ push edi |
|
| 105 |
+ inc edx |
|
| 106 |
+ push edx |
|
| 107 |
+ push eax |
|
| 108 |
+ cmp eax,edi |
|
| 109 |
+ jbe est_plus_jeune |
|
| 110 |
+ jmp read_list |
|
| 111 |
+ |
|
| 112 |
+est_plus_jeune : |
|
| 113 |
+ xor eax,eax |
|
| 114 |
+ pop ebx |
|
| 115 |
+ pop eax |
|
| 116 |
+ pop edx |
|
| 117 |
+ pop edx |
|
| 118 |
+ push eax |
|
| 119 |
+ push ebx ; |
|
| 120 |
+ xor eax,eax |
|
| 121 |
+ push eax |
|
| 122 |
+ xor ebx,ebx |
|
| 123 |
+ push ebx |
|
| 124 |
+ jmp read_list |
|
| 125 |
+ |
|
| 126 |
+continue : |
|
| 127 |
+ pop eax |
|
| 128 |
+ pop ebx |
|
| 129 |
+ pop ecx ; Age plus jeune |
|
| 130 |
+ pop edx ; Position plus jeune |
|
| 131 |
+ |
|
| 132 |
+close: |
|
| 133 |
+ ; close the file |
|
| 134 |
+ mov eax, 6 |
|
| 135 |
+ mov ebx, esi |
|
| 136 |
+ int 80h |
|
| 137 |
+ |
|
| 138 |
+ jmp end |
|
| 139 |
+end: |
|
| 140 |
+ mov eax, 1 |
|
| 141 |
+ xor ebx, ebx |
|
| 142 |
+ int 80h |
|
| 0 | 143 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,154 @@ |
| 1 |
+global _start |
|
| 2 |
+;On considère le fichier contenant le personnel comme deja existant |
|
| 3 |
+;https://www.tutorialspoint.com/assembly_programming/assembly_file_management.htm |
|
| 4 |
+ |
|
| 5 |
+section .data |
|
| 6 |
+msg: db "WAK !", 10 |
|
| 7 |
+len: equ $-msg |
|
| 8 |
+file: db "test.txt", 0 |
|
| 9 |
+lenfile: equ $-file |
|
| 10 |
+out: dw 0 |
|
| 11 |
+buffer : db 0 |
|
| 12 |
+name_buffer : db 0 |
|
| 13 |
+name_len : equ $-name_buffer |
|
| 14 |
+age_buffer : db 0 |
|
| 15 |
+age_len : equ $-age_buffer |
|
| 16 |
+space :db ' ' |
|
| 17 |
+break : db 10 |
|
| 18 |
+ |
|
| 19 |
+section .text |
|
| 20 |
+_start: |
|
| 21 |
+ ;ouverture fichier |
|
| 22 |
+ mov eax, 5 |
|
| 23 |
+ mov ebx, file |
|
| 24 |
+ mov ecx, 0x441 ;append/write/create if not existent |
|
| 25 |
+ mov edx, 0777o ;la totale |
|
| 26 |
+ int 80h |
|
| 27 |
+ mov esi,eax |
|
| 28 |
+ |
|
| 29 |
+ cmp eax,0 |
|
| 30 |
+ jbe end ;erreur ouverture |
|
| 31 |
+ |
|
| 32 |
+ mov esi, eax |
|
| 33 |
+ |
|
| 34 |
+ ;ecriture fichier |
|
| 35 |
+ ;mov eax, 4 |
|
| 36 |
+ ;mov ebx, esi |
|
| 37 |
+ ;mov ecx, msg |
|
| 38 |
+ ;mov edx, len |
|
| 39 |
+ ;int 80h |
|
| 40 |
+ |
|
| 41 |
+ cmp eax,0 |
|
| 42 |
+ jbe close ;erreur ecriture |
|
| 43 |
+ |
|
| 44 |
+ |
|
| 45 |
+ ;fermer fichier |
|
| 46 |
+ mov eax, 6 |
|
| 47 |
+ mov ebx, esi |
|
| 48 |
+ int 80h |
|
| 49 |
+ |
|
| 50 |
+ |
|
| 51 |
+ ;ouverture fichier |
|
| 52 |
+ mov eax, 5 |
|
| 53 |
+ mov ebx, file |
|
| 54 |
+ mov ecx, 0 ;read only |
|
| 55 |
+ mov edx, 0777o ;la totale |
|
| 56 |
+ int 80h |
|
| 57 |
+ mov esi,eax |
|
| 58 |
+ |
|
| 59 |
+ cmp eax,0 |
|
| 60 |
+ jbe end ;erreur ouverture |
|
| 61 |
+ |
|
| 62 |
+ mov esi, eax |
|
| 63 |
+ |
|
| 64 |
+ mov edi,0 ;ICI COMMENCE LE LISTAGE |
|
| 65 |
+ jmp read_list |
|
| 66 |
+ |
|
| 67 |
+echo: |
|
| 68 |
+ ;lecture |
|
| 69 |
+ mov eax, 3 |
|
| 70 |
+ mov ebx, esi |
|
| 71 |
+ mov ecx, buffer |
|
| 72 |
+ mov edx, 1 |
|
| 73 |
+ int 80h |
|
| 74 |
+ |
|
| 75 |
+ ;test si erreur |
|
| 76 |
+ cmp eax,0 |
|
| 77 |
+ jbe close |
|
| 78 |
+ |
|
| 79 |
+ |
|
| 80 |
+ ;affichage |
|
| 81 |
+ mov eax, 4 |
|
| 82 |
+ mov ebx, 1 |
|
| 83 |
+ mov ecx, buffer |
|
| 84 |
+ mov edx, 1 |
|
| 85 |
+ int 80h |
|
| 86 |
+ |
|
| 87 |
+ jmp echo |
|
| 88 |
+ |
|
| 89 |
+read_list : |
|
| 90 |
+ ;lecture |
|
| 91 |
+ mov eax, 3 |
|
| 92 |
+ mov ebx, esi |
|
| 93 |
+ mov ecx, buffer |
|
| 94 |
+ mov edx, 1 |
|
| 95 |
+ int 80h |
|
| 96 |
+ |
|
| 97 |
+ ;test si erreur |
|
| 98 |
+ cmp eax,0 |
|
| 99 |
+ jbe close |
|
| 100 |
+ |
|
| 101 |
+ cmp byte [buffer], ',' |
|
| 102 |
+ je inc_compt |
|
| 103 |
+ |
|
| 104 |
+output_list : |
|
| 105 |
+ ;affichage |
|
| 106 |
+ mov eax, 4 |
|
| 107 |
+ mov ebx, 1 |
|
| 108 |
+ mov ecx, buffer |
|
| 109 |
+ mov edx, 1 |
|
| 110 |
+ int 80h |
|
| 111 |
+ |
|
| 112 |
+ jmp read_list |
|
| 113 |
+ |
|
| 114 |
+inc_compt: |
|
| 115 |
+ inc edi |
|
| 116 |
+ |
|
| 117 |
+ mov eax, 4 |
|
| 118 |
+ mov ebx, 1 |
|
| 119 |
+ mov ecx, space |
|
| 120 |
+ mov edx, 1 |
|
| 121 |
+ int 80h |
|
| 122 |
+ |
|
| 123 |
+ mov eax,edi |
|
| 124 |
+ mov bl,3 |
|
| 125 |
+ div bl |
|
| 126 |
+ cmp edx,0 |
|
| 127 |
+ je break_line |
|
| 128 |
+ jmp read_list |
|
| 129 |
+ |
|
| 130 |
+break_line : |
|
| 131 |
+ mov eax, 4 |
|
| 132 |
+ mov ebx, 1 |
|
| 133 |
+ mov ecx, break |
|
| 134 |
+ mov edx, 1 |
|
| 135 |
+ int 80h |
|
| 136 |
+ |
|
| 137 |
+ mov eax,edi |
|
| 138 |
+ mov edx,0 |
|
| 139 |
+ mov bl,2 |
|
| 140 |
+ div bl |
|
| 141 |
+ |
|
| 142 |
+ |
|
| 143 |
+ |
|
| 144 |
+close: |
|
| 145 |
+ ; close the file |
|
| 146 |
+ mov eax, 6 |
|
| 147 |
+ mov ebx, esi |
|
| 148 |
+ int 80h |
|
| 149 |
+ |
|
| 150 |
+ jmp end |
|
| 151 |
+end: |
|
| 152 |
+ mov eax, 1 |
|
| 153 |
+ xor ebx, ebx |
|
| 154 |
+ int 80h |
| ... | ... |
@@ -0,0 +1,596 @@ |
| 1 |
+global _start |
|
| 2 |
+ |
|
| 3 |
+ |
|
| 4 |
+section .data |
|
| 5 |
+ |
|
| 6 |
+; Texte et message à afficher dans la sortie standard |
|
| 7 |
+mainPrompt: db "> " |
|
| 8 |
+mainPromptLength: equ $-mainPrompt |
|
| 9 |
+secondaryPrompt: db ": " |
|
| 10 |
+secondaryPromptLength: equ $-secondaryPrompt |
|
| 11 |
+welcomeMessage: db "COMPUTER ARCHITECTURE PROJET: REGISTRATION PROGRAM", 10, "Press 'h' or return key for a list of the available commands.", 10 |
|
| 12 |
+welcomeMessageLength: equ $-welcomeMessage |
|
| 13 |
+helpMessage: db "Available commands:", 10, " r - Register a new person", 10, " l - Lists all registered persons", 10, " s - Search and display a specific person", 10, " y - Display the youngest person registered", 10, " q - Quit the program", 10 |
|
| 14 |
+helpMessageLength: equ $-helpMessage |
|
| 15 |
+commandErrorMessage: db "ERROR: Unknown command.", 10, 7 |
|
| 16 |
+commandErrorMessageLength: equ $-commandErrorMessage |
|
| 17 |
+fileErrorMessage: db "ERROR: No registry file, please create one.", 10, 7 |
|
| 18 |
+fileErrorMessageLength: equ $-fileErrorMessage |
|
| 19 |
+numberErrorMessage: db "ERROR: Not a number.", 10, 7 |
|
| 20 |
+numberErrorMessageLength: equ $-numberErrorMessage |
|
| 21 |
+searchErrorMessage: db "ERROR: Requested person not found.", 10, 7 |
|
| 22 |
+searchErrorMessageLength: equ $-searchErrorMessage |
|
| 23 |
+space: db ' ' |
|
| 24 |
+spaceLength: equ $-space |
|
| 25 |
+comma: db ',' |
|
| 26 |
+commaLength: equ $-comma |
|
| 27 |
+ |
|
| 28 |
+; Fichier |
|
| 29 |
+fileName: db "registry.csv" |
|
| 30 |
+fd : dw 0 |
|
| 31 |
+ |
|
| 32 |
+; Mémoire tampon |
|
| 33 |
+mainPromptBuffer: db 2 dup(0) |
|
| 34 |
+secondaryPromptBuffer: db 1024 dup(0) |
|
| 35 |
+generalPurposeBuffer: db 8192 dup(0) |
|
| 36 |
+numberBuffer: db 12 |
|
| 37 |
+ |
|
| 38 |
+ |
|
| 39 |
+section .text |
|
| 40 |
+ |
|
| 41 |
+_start: |
|
| 42 |
+ ; Message informatif au démarrage du programme |
|
| 43 |
+ mov eax, 4 |
|
| 44 |
+ mov ebx, 1 |
|
| 45 |
+ mov ecx, welcomeMessage |
|
| 46 |
+ mov edx, welcomeMessageLength |
|
| 47 |
+ int 80h |
|
| 48 |
+ |
|
| 49 |
+ ; Gestion de l'invite de commande principal |
|
| 50 |
+ .prompt: |
|
| 51 |
+ ; Affichage de l'invite de commande |
|
| 52 |
+ mov eax, 4 |
|
| 53 |
+ mov ebx, 1 |
|
| 54 |
+ mov ecx, mainPrompt |
|
| 55 |
+ mov edx, mainPromptLength |
|
| 56 |
+ int 80h |
|
| 57 |
+ ; Lecture de la commande entrée par l'utilisateur |
|
| 58 |
+ mov eax, 3 |
|
| 59 |
+ mov ebx, 0 |
|
| 60 |
+ mov ecx, mainPromptBuffer |
|
| 61 |
+ mov edx, 2 |
|
| 62 |
+ int 80h |
|
| 63 |
+ ; Gestion des différentes opération du programme selon la commande reçue |
|
| 64 |
+ cmp eax, 0 |
|
| 65 |
+ jle .error |
|
| 66 |
+ cmp byte [mainPromptBuffer], 10 ; Affiche l'aide si l'on appuie sur la touche retour |
|
| 67 |
+ je .help |
|
| 68 |
+ cmp byte [mainPromptBuffer + 1], 10 |
|
| 69 |
+ jne .flush |
|
| 70 |
+ cmp byte [mainPromptBuffer], "h" |
|
| 71 |
+ je .help |
|
| 72 |
+ cmp byte [mainPromptBuffer], "r" |
|
| 73 |
+ je .register |
|
| 74 |
+ cmp byte [mainPromptBuffer], "l" |
|
| 75 |
+ je .list |
|
| 76 |
+ cmp byte [mainPromptBuffer], "s" |
|
| 77 |
+ je .search |
|
| 78 |
+ cmp byte [mainPromptBuffer], "y" |
|
| 79 |
+ je .youngest |
|
| 80 |
+ cmp byte [mainPromptBuffer], "q" |
|
| 81 |
+ je .quit |
|
| 82 |
+ jmp .error |
|
| 83 |
+ |
|
| 84 |
+ .help: |
|
| 85 |
+ mov eax, 4 |
|
| 86 |
+ mov ebx, 1 |
|
| 87 |
+ mov ecx, helpMessage |
|
| 88 |
+ mov edx, helpMessageLength |
|
| 89 |
+ int 80h |
|
| 90 |
+ jmp .prompt |
|
| 91 |
+ |
|
| 92 |
+ .register: |
|
| 93 |
+ call register |
|
| 94 |
+ jmp .prompt |
|
| 95 |
+ |
|
| 96 |
+ .list: |
|
| 97 |
+ call list |
|
| 98 |
+ jmp .prompt |
|
| 99 |
+ |
|
| 100 |
+ .search: |
|
| 101 |
+ call search |
|
| 102 |
+ jmp .prompt |
|
| 103 |
+ |
|
| 104 |
+ .youngest: |
|
| 105 |
+ call youngest |
|
| 106 |
+ jmp .prompt |
|
| 107 |
+ |
|
| 108 |
+ .flush: |
|
| 109 |
+ mov eax, 3 |
|
| 110 |
+ mov ebx, 0 |
|
| 111 |
+ mov ecx, mainPromptBuffer |
|
| 112 |
+ mov edx, 1 |
|
| 113 |
+ int 80h |
|
| 114 |
+ cmp byte [mainPromptBuffer], 10 |
|
| 115 |
+ jne .flush |
|
| 116 |
+ jmp .error |
|
| 117 |
+ |
|
| 118 |
+ .error: |
|
| 119 |
+ ; Affichage d'un message d'erreur |
|
| 120 |
+ mov eax, 4 |
|
| 121 |
+ mov ebx, 2 |
|
| 122 |
+ mov ecx, commandErrorMessage |
|
| 123 |
+ mov edx, commandErrorMessageLength |
|
| 124 |
+ int 80h |
|
| 125 |
+ jmp .prompt |
|
| 126 |
+ |
|
| 127 |
+ ; Quitte le programme avec le valeur 0 (Succès) |
|
| 128 |
+ .quit: |
|
| 129 |
+ mov eax, 1 |
|
| 130 |
+ xor ebx, ebx |
|
| 131 |
+ int 80h |
|
| 132 |
+ |
|
| 133 |
+register: |
|
| 134 |
+ ; Ouverture du fichier en lecture seule |
|
| 135 |
+ mov eax, 5 |
|
| 136 |
+ mov ebx, fileName |
|
| 137 |
+ xor ecx, ecx |
|
| 138 |
+ mov edx, 0666o |
|
| 139 |
+ int 80h |
|
| 140 |
+ mov edi, 1 |
|
| 141 |
+ cmp eax, 0 |
|
| 142 |
+ jl .create |
|
| 143 |
+ |
|
| 144 |
+ mov esi, eax |
|
| 145 |
+ |
|
| 146 |
+ ; Calcul du nombre de lignes du fichier |
|
| 147 |
+ .while: |
|
| 148 |
+ mov eax, 3 |
|
| 149 |
+ mov ebx, esi |
|
| 150 |
+ mov ecx, generalPurposeBuffer |
|
| 151 |
+ mov edx, 1 |
|
| 152 |
+ int 80h |
|
| 153 |
+ cmp eax, 0 |
|
| 154 |
+ je .end_while |
|
| 155 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 156 |
+ je .inc |
|
| 157 |
+ jmp .while |
|
| 158 |
+ |
|
| 159 |
+ .inc: |
|
| 160 |
+ inc edi |
|
| 161 |
+ jmp .while |
|
| 162 |
+ |
|
| 163 |
+ .end_while: |
|
| 164 |
+ |
|
| 165 |
+ ; Fermeture du fichier ouvert en lecture |
|
| 166 |
+ mov eax, 6 |
|
| 167 |
+ mov ebx, esi |
|
| 168 |
+ int 80h |
|
| 169 |
+ |
|
| 170 |
+ ; Conversion de l'entier en chaîne de caractères |
|
| 171 |
+ mov eax, edi |
|
| 172 |
+ mov esi, numberBuffer |
|
| 173 |
+ mov byte [esi], 0 |
|
| 174 |
+ mov ebx, 10 |
|
| 175 |
+ xor ecx, ecx |
|
| 176 |
+ |
|
| 177 |
+ .convert: |
|
| 178 |
+ xor edx, edx |
|
| 179 |
+ div ebx |
|
| 180 |
+ add dl, 48 |
|
| 181 |
+ dec esi |
|
| 182 |
+ mov [esi], dl |
|
| 183 |
+ inc ecx |
|
| 184 |
+ cmp eax, 0 |
|
| 185 |
+ jne .convert |
|
| 186 |
+ |
|
| 187 |
+ mov edi, esi |
|
| 188 |
+ |
|
| 189 |
+ ; Affichage de l'invite de commande secondaire |
|
| 190 |
+ .open: |
|
| 191 |
+ push edi |
|
| 192 |
+ push ecx |
|
| 193 |
+ mov eax, 4 |
|
| 194 |
+ mov ebx, 1 |
|
| 195 |
+ mov ecx, secondaryPrompt |
|
| 196 |
+ mov edx, secondaryPromptLength |
|
| 197 |
+ int 80h |
|
| 198 |
+ |
|
| 199 |
+ ; Ouverture du fichier en écriture |
|
| 200 |
+ mov eax, 5 |
|
| 201 |
+ mov ebx, fileName |
|
| 202 |
+ mov ecx, 401h |
|
| 203 |
+ mov edx, 0666o |
|
| 204 |
+ int 80h |
|
| 205 |
+ |
|
| 206 |
+ ;cmp eax, 0 |
|
| 207 |
+ ;jbe .create |
|
| 208 |
+ |
|
| 209 |
+ mov esi, eax |
|
| 210 |
+ |
|
| 211 |
+ mov eax, 4 |
|
| 212 |
+ mov ebx, esi |
|
| 213 |
+ pop ecx |
|
| 214 |
+ mov edx, ecx |
|
| 215 |
+ pop edi |
|
| 216 |
+ mov ecx, edi |
|
| 217 |
+ int 80h |
|
| 218 |
+ |
|
| 219 |
+ mov eax, 4 |
|
| 220 |
+ mov ebx, esi |
|
| 221 |
+ mov ecx, comma |
|
| 222 |
+ mov edx, commaLength |
|
| 223 |
+ int 80h |
|
| 224 |
+ |
|
| 225 |
+ .write: |
|
| 226 |
+ mov eax, 3 |
|
| 227 |
+ xor ebx, ebx |
|
| 228 |
+ mov ecx, secondaryPromptBuffer |
|
| 229 |
+ mov edx, 1 |
|
| 230 |
+ int 80h |
|
| 231 |
+ |
|
| 232 |
+ mov edx, eax |
|
| 233 |
+ |
|
| 234 |
+ mov eax, 4 |
|
| 235 |
+ mov ebx, esi |
|
| 236 |
+ cmp byte [secondaryPromptBuffer], ' ' |
|
| 237 |
+ je .comma |
|
| 238 |
+ jmp .skip |
|
| 239 |
+ .comma: |
|
| 240 |
+ mov ecx, comma |
|
| 241 |
+ jmp .interrupt |
|
| 242 |
+ .skip: |
|
| 243 |
+ mov ecx, secondaryPromptBuffer |
|
| 244 |
+ .interrupt: |
|
| 245 |
+ int 80h |
|
| 246 |
+ cmp byte [secondaryPromptBuffer], 10 |
|
| 247 |
+ je .end |
|
| 248 |
+ jmp .write |
|
| 249 |
+ |
|
| 250 |
+ .create: |
|
| 251 |
+ mov eax, 5 |
|
| 252 |
+ mov ebx, fileName |
|
| 253 |
+ mov ecx, 100o |
|
| 254 |
+ mov edx, 0666o |
|
| 255 |
+ int 80h |
|
| 256 |
+ ; Fermeture du fichier |
|
| 257 |
+ mov ebx, eax |
|
| 258 |
+ mov eax, 6 |
|
| 259 |
+ int 80h |
|
| 260 |
+ jmp register |
|
| 261 |
+ |
|
| 262 |
+ .end: |
|
| 263 |
+ ; Fermeture du fichier |
|
| 264 |
+ mov eax, 6 |
|
| 265 |
+ mov ebx, esi |
|
| 266 |
+ int 80h |
|
| 267 |
+ ret |
|
| 268 |
+ |
|
| 269 |
+list: |
|
| 270 |
+ ; Ouverture du fichier regristry.csv |
|
| 271 |
+ mov eax, 5 |
|
| 272 |
+ mov ebx, fileName |
|
| 273 |
+ xor ecx, ecx |
|
| 274 |
+ mov edx, 0666o |
|
| 275 |
+ int 80h |
|
| 276 |
+ cmp eax, -2 ; Affiche une erreur si le fichier n'existe pas |
|
| 277 |
+ je .error |
|
| 278 |
+ |
|
| 279 |
+ mov esi, eax ; Copie du descripteur de fichier dans esi |
|
| 280 |
+ |
|
| 281 |
+ ; Affichage de la liste |
|
| 282 |
+ .loop: |
|
| 283 |
+ mov eax, 3 |
|
| 284 |
+ mov ebx, esi |
|
| 285 |
+ mov ecx, generalPurposeBuffer |
|
| 286 |
+ mov edx, 1 |
|
| 287 |
+ int 80h |
|
| 288 |
+ cmp eax, 0 |
|
| 289 |
+ jbe .end |
|
| 290 |
+ mov edx, eax |
|
| 291 |
+ mov eax, 4 |
|
| 292 |
+ mov ebx, 1 |
|
| 293 |
+ cmp byte [generalPurposeBuffer], ',' |
|
| 294 |
+ jne .nocomma |
|
| 295 |
+ mov ecx, space |
|
| 296 |
+ jmp .interrupt |
|
| 297 |
+ .nocomma: |
|
| 298 |
+ mov ecx, generalPurposeBuffer |
|
| 299 |
+ .interrupt: |
|
| 300 |
+ int 80h |
|
| 301 |
+ jmp .loop |
|
| 302 |
+ |
|
| 303 |
+ .error: |
|
| 304 |
+ mov eax, 4 |
|
| 305 |
+ mov ebx, 2 |
|
| 306 |
+ mov ecx, fileErrorMessage |
|
| 307 |
+ mov edx, fileErrorMessageLength |
|
| 308 |
+ int 80h |
|
| 309 |
+ ret |
|
| 310 |
+ |
|
| 311 |
+ .end: |
|
| 312 |
+ ; Fermeture du fichier |
|
| 313 |
+ mov eax, 6 |
|
| 314 |
+ mov ebx, esi |
|
| 315 |
+ int 80h |
|
| 316 |
+ ret |
|
| 317 |
+ |
|
| 318 |
+search: |
|
| 319 |
+ ; Affichage de l'invite de commande secondaire |
|
| 320 |
+ mov eax, 4 |
|
| 321 |
+ mov ebx, 1 |
|
| 322 |
+ mov ecx, secondaryPrompt |
|
| 323 |
+ mov edx, secondaryPromptLength |
|
| 324 |
+ int 80h |
|
| 325 |
+ |
|
| 326 |
+ xor edi, edi |
|
| 327 |
+ |
|
| 328 |
+ .convert: |
|
| 329 |
+ ; Lecture de l'entrée standard |
|
| 330 |
+ mov eax, 3 |
|
| 331 |
+ xor ebx, ebx |
|
| 332 |
+ mov ecx, secondaryPromptBuffer |
|
| 333 |
+ mov edx, 1 |
|
| 334 |
+ int 80h |
|
| 335 |
+ |
|
| 336 |
+ ; Conversion en entier |
|
| 337 |
+ xor ebx, ebx |
|
| 338 |
+ mov bl, [secondaryPromptBuffer] |
|
| 339 |
+ cmp ebx, 10 |
|
| 340 |
+ je .print |
|
| 341 |
+ |
|
| 342 |
+ sub ebx, 48 |
|
| 343 |
+ imul edi, 10 |
|
| 344 |
+ add edi, ebx |
|
| 345 |
+ jmp .convert |
|
| 346 |
+ |
|
| 347 |
+ .print: |
|
| 348 |
+ ; Ouverture du fichier regristry.csv |
|
| 349 |
+ mov eax, 5 |
|
| 350 |
+ mov ebx, fileName |
|
| 351 |
+ xor ecx, ecx |
|
| 352 |
+ mov edx, 0666o |
|
| 353 |
+ int 80h |
|
| 354 |
+ cmp eax, -2 ; Affiche une erreur si le fichier n'existe pas |
|
| 355 |
+ je .error |
|
| 356 |
+ |
|
| 357 |
+ mov esi, eax ; Copie du descripteur de fichier dans esi |
|
| 358 |
+ |
|
| 359 |
+ cmp edi, 1 ; Dans le cas où edi = 1, on passe la boucle |
|
| 360 |
+ je .loop |
|
| 361 |
+ |
|
| 362 |
+ .while: |
|
| 363 |
+ mov eax, 3 |
|
| 364 |
+ mov ebx, esi |
|
| 365 |
+ mov ecx, generalPurposeBuffer |
|
| 366 |
+ mov edx, 1 |
|
| 367 |
+ int 80h |
|
| 368 |
+ cmp eax, 0 |
|
| 369 |
+ je .end |
|
| 370 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 371 |
+ je .dec |
|
| 372 |
+ .next: |
|
| 373 |
+ cmp edi, 1 |
|
| 374 |
+ je .loop |
|
| 375 |
+ jmp .while |
|
| 376 |
+ |
|
| 377 |
+ ; Affichage de la ligne |
|
| 378 |
+ .loop: |
|
| 379 |
+ mov eax, 3 |
|
| 380 |
+ mov ebx, esi |
|
| 381 |
+ mov ecx, generalPurposeBuffer |
|
| 382 |
+ mov edx, 1 |
|
| 383 |
+ int 80h |
|
| 384 |
+ cmp eax, 0 |
|
| 385 |
+ jbe .unknown |
|
| 386 |
+ mov edx, eax |
|
| 387 |
+ mov eax, 4 |
|
| 388 |
+ mov ebx, 1 |
|
| 389 |
+ cmp byte [generalPurposeBuffer], ',' |
|
| 390 |
+ jne .nocomma |
|
| 391 |
+ mov ecx, space |
|
| 392 |
+ jmp .interrupt |
|
| 393 |
+ .nocomma: |
|
| 394 |
+ mov ecx, generalPurposeBuffer |
|
| 395 |
+ .interrupt: |
|
| 396 |
+ int 80h |
|
| 397 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 398 |
+ je .end |
|
| 399 |
+ jmp .loop |
|
| 400 |
+ |
|
| 401 |
+ .error: |
|
| 402 |
+ mov eax, 4 |
|
| 403 |
+ mov ebx, 2 |
|
| 404 |
+ mov ecx, fileErrorMessage |
|
| 405 |
+ mov edx, fileErrorMessageLength |
|
| 406 |
+ int 80h |
|
| 407 |
+ ret |
|
| 408 |
+ |
|
| 409 |
+ .unknown: |
|
| 410 |
+ mov eax, 4 |
|
| 411 |
+ mov ebx, 2 |
|
| 412 |
+ mov ecx, searchErrorMessage |
|
| 413 |
+ mov edx, searchErrorMessageLength |
|
| 414 |
+ int 80h |
|
| 415 |
+ ret |
|
| 416 |
+ |
|
| 417 |
+ .end: |
|
| 418 |
+ ; Fermeture du fichier |
|
| 419 |
+ mov eax, 6 |
|
| 420 |
+ mov ebx, esi |
|
| 421 |
+ int 80h |
|
| 422 |
+ ret |
|
| 423 |
+ |
|
| 424 |
+ .dec: |
|
| 425 |
+ dec edi |
|
| 426 |
+ jmp .next |
|
| 427 |
+ |
|
| 428 |
+youngest: |
|
| 429 |
+ ; Ouverture du fichier regristry.csv |
|
| 430 |
+ mov eax, 5 |
|
| 431 |
+ mov ebx, fileName |
|
| 432 |
+ xor ecx, ecx |
|
| 433 |
+ mov edx, 0666o |
|
| 434 |
+ int 80h |
|
| 435 |
+ cmp eax, -2 ; Affiche une erreur si le fichier n'existe pas |
|
| 436 |
+ je .error |
|
| 437 |
+ |
|
| 438 |
+ mov esi, eax |
|
| 439 |
+ |
|
| 440 |
+ xor eax, eax |
|
| 441 |
+ push eax |
|
| 442 |
+ push eax |
|
| 443 |
+ mov eax, 65536 |
|
| 444 |
+ push eax |
|
| 445 |
+ |
|
| 446 |
+ .get_ages: |
|
| 447 |
+ |
|
| 448 |
+ mov edi, 2 |
|
| 449 |
+ |
|
| 450 |
+ .get_to_age: |
|
| 451 |
+ mov eax, 3 |
|
| 452 |
+ mov ebx, esi |
|
| 453 |
+ mov ecx, generalPurposeBuffer |
|
| 454 |
+ mov edx, 1 |
|
| 455 |
+ int 80h |
|
| 456 |
+ |
|
| 457 |
+ cmp eax, 0 |
|
| 458 |
+ jbe .print |
|
| 459 |
+ |
|
| 460 |
+ cmp byte [generalPurposeBuffer], ',' |
|
| 461 |
+ je .dec_comma |
|
| 462 |
+ .dec_comma_ret: |
|
| 463 |
+ cmp edi, 0 |
|
| 464 |
+ jne .get_to_age |
|
| 465 |
+ |
|
| 466 |
+ .convert: |
|
| 467 |
+ mov eax, 3 |
|
| 468 |
+ mov ebx, esi |
|
| 469 |
+ mov ecx, generalPurposeBuffer |
|
| 470 |
+ mov edx, 1 |
|
| 471 |
+ int 80h |
|
| 472 |
+ |
|
| 473 |
+ cmp eax, 0 |
|
| 474 |
+ jbe .print |
|
| 475 |
+ |
|
| 476 |
+ ; Conversion en entier |
|
| 477 |
+ xor ebx, ebx |
|
| 478 |
+ mov bl, [generalPurposeBuffer] |
|
| 479 |
+ cmp ebx, 10 |
|
| 480 |
+ je .newline |
|
| 481 |
+ |
|
| 482 |
+ sub ebx, 48 |
|
| 483 |
+ imul edi, 10 |
|
| 484 |
+ add edi, ebx |
|
| 485 |
+ jmp .convert |
|
| 486 |
+ |
|
| 487 |
+ |
|
| 488 |
+ .newline: |
|
| 489 |
+ pop eax |
|
| 490 |
+ cmp eax, edi |
|
| 491 |
+ pop ebx |
|
| 492 |
+ inc ebx |
|
| 493 |
+ jbe .not_younger |
|
| 494 |
+ pop ecx |
|
| 495 |
+ mov ecx, ebx |
|
| 496 |
+ push ebx |
|
| 497 |
+ push ebx |
|
| 498 |
+ push edi |
|
| 499 |
+ jmp .get_ages |
|
| 500 |
+ .not_younger: |
|
| 501 |
+ push ebx |
|
| 502 |
+ push eax |
|
| 503 |
+ jmp .get_ages |
|
| 504 |
+ |
|
| 505 |
+ .print: |
|
| 506 |
+ pop eax |
|
| 507 |
+ pop edi |
|
| 508 |
+ pop edi |
|
| 509 |
+ |
|
| 510 |
+ cmp edi, 1 ; Dans le cas où edi = 1, on passe la boucle |
|
| 511 |
+ je .loop |
|
| 512 |
+ |
|
| 513 |
+ ; Fermeture du fichier |
|
| 514 |
+ mov eax, 6 |
|
| 515 |
+ mov ebx, esi |
|
| 516 |
+ int 80h |
|
| 517 |
+ ; Ouverture du fichier regristry.csv |
|
| 518 |
+ mov eax, 5 |
|
| 519 |
+ mov ebx, fileName |
|
| 520 |
+ xor ecx, ecx |
|
| 521 |
+ mov edx, 0666o |
|
| 522 |
+ int 80h |
|
| 523 |
+ cmp eax, -2 ; Affiche une erreur si le fichier n'existe pas |
|
| 524 |
+ je .error |
|
| 525 |
+ |
|
| 526 |
+ mov esi, eax ; Copie du descripteur de fichier dans esi |
|
| 527 |
+ |
|
| 528 |
+ .while: |
|
| 529 |
+ mov eax, 3 |
|
| 530 |
+ mov ebx, esi |
|
| 531 |
+ mov ecx, generalPurposeBuffer |
|
| 532 |
+ mov edx, 1 |
|
| 533 |
+ int 80h |
|
| 534 |
+ cmp eax, 0 |
|
| 535 |
+ je .end |
|
| 536 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 537 |
+ je .dec |
|
| 538 |
+ .next: |
|
| 539 |
+ cmp edi, 1 |
|
| 540 |
+ je .loop |
|
| 541 |
+ jmp .while |
|
| 542 |
+ |
|
| 543 |
+ ; Affichage de la ligne |
|
| 544 |
+ .loop: |
|
| 545 |
+ mov eax, 3 |
|
| 546 |
+ mov ebx, esi |
|
| 547 |
+ mov ecx, generalPurposeBuffer |
|
| 548 |
+ mov edx, 1 |
|
| 549 |
+ int 80h |
|
| 550 |
+ cmp eax, 0 |
|
| 551 |
+ jbe .unknown |
|
| 552 |
+ mov edx, eax |
|
| 553 |
+ mov eax, 4 |
|
| 554 |
+ mov ebx, 1 |
|
| 555 |
+ cmp byte [generalPurposeBuffer], ',' |
|
| 556 |
+ jne .nocomma |
|
| 557 |
+ mov ecx, space |
|
| 558 |
+ jmp .interrupt |
|
| 559 |
+ .nocomma: |
|
| 560 |
+ mov ecx, generalPurposeBuffer |
|
| 561 |
+ .interrupt: |
|
| 562 |
+ int 80h |
|
| 563 |
+ cmp byte [generalPurposeBuffer], 10 |
|
| 564 |
+ je .end |
|
| 565 |
+ jmp .loop |
|
| 566 |
+ |
|
| 567 |
+ .error: |
|
| 568 |
+ mov eax, 4 |
|
| 569 |
+ mov ebx, 2 |
|
| 570 |
+ mov ecx, fileErrorMessage |
|
| 571 |
+ mov edx, fileErrorMessageLength |
|
| 572 |
+ int 80h |
|
| 573 |
+ ret |
|
| 574 |
+ |
|
| 575 |
+ .unknown: |
|
| 576 |
+ mov eax, 4 |
|
| 577 |
+ mov ebx, 2 |
|
| 578 |
+ mov ecx, searchErrorMessage |
|
| 579 |
+ mov edx, searchErrorMessageLength |
|
| 580 |
+ int 80h |
|
| 581 |
+ ret |
|
| 582 |
+ |
|
| 583 |
+ .end: |
|
| 584 |
+ ; Fermeture du fichier |
|
| 585 |
+ mov eax, 6 |
|
| 586 |
+ mov ebx, esi |
|
| 587 |
+ int 80h |
|
| 588 |
+ ret |
|
| 589 |
+ |
|
| 590 |
+ .dec: |
|
| 591 |
+ dec edi |
|
| 592 |
+ jmp .next |
|
| 593 |
+ |
|
| 594 |
+ .dec_comma: |
|
| 595 |
+ dec edi |
|
| 596 |
+ jmp .dec_comma_ret |
|
| 0 | 597 |