Skip to content
Snippets Groups Projects
Commit 153b2b09 authored by Lucas B's avatar Lucas B
Browse files

TP3

parent 718af451
No related branches found
No related tags found
No related merge requests found
section .data
symbol1: db '*'
symbol2: db 10
i: db 0
z: db 0
j: db '20'
section .text
global _start
_start:
mov eax, 3
mov ebx, 1
mov ecx, j
mov edx, 1
int 80h
sub byte [j], '0'
mov al, byte [j]
debut_pour:
mov al, byte [j]
cmp byte [z], al
jge fin_pour
mov byte [i], 0
debut_for:
mov al, byte [j]
cmp byte [i], al
jge fin_for
mov eax, 4
mov ebx, 1
mov ecx, symbol1
mov edx, 1
int 80h
inc byte [i]
jmp debut_for
fin_for:
mov eax, 4
mov ebx, 1
mov ecx, symbol2
mov edx, 1
int 80h
inc byte [z]
jmp debut_pour
fin_pour:
mov eax, 1
mov ebx, 0
int 80h
\ No newline at end of file
section .data
newline: db 10 ; Saut de ligne
buffer: db 0 ; Stocke temporairement le caractère lu
section .text
global _start
_start:
read_loop:
; Lire un caractère depuis l'entrée standard
mov eax, 3 ; Syscall read
mov ebx, 0 ; STDIN
mov ecx, buffer ; Lire dans "buffer"
mov edx, 1 ; Lire 1 caractère
int 80h
; Vérifier si le caractère est un espace (ASCII 32)
cmp byte [buffer], 32
je end_program ; Si espace, fin du programme
; Afficher le caractère lu
mov eax, 4 ; Syscall write
mov ebx, 1 ; STDOUT
mov ecx, buffer ; Afficher "buffer"
mov edx, 1 ; Taille 1
int 0x80
jmp read_loop ; Lire le prochain caractère
end_program:
; Afficher un saut de ligne pour terminer proprement
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 0x80
; Quitter le programme
mov eax, 1
xor ebx, ebx
int 0x80
section .data
newline: db 10 ; Saut de ligne
buffer: db 0 ; Stocke temporairement le caractère lu
chaine: db "Bonjour a tous", 10
section .text
global _start
_start:
read_loop:
; Lire un caractère depuis l'entrée standard
mov eax, 3 ; Syscall read
mov ebx, 0 ; STDIN
mov ecx, buffer ; Lire dans "buffer"
mov edx, 1 ; Lire 1 caractère
int 80h
; Vérifier si le caractère est un espace (ASCII 32)
cmp byte [buffer], 32
je end_program ; Si espace, fin du programme
; Afficher le caractère lu
mov eax, 4 ; Syscall write
mov ebx, 1 ; STDOUT
mov ecx, buffer ; Afficher "buffer"
mov edx, 1 ; Taille 1
int 0x80
jmp read_loop ; Lire le prochain caractère
end_program:
; Afficher un saut de ligne pour terminer proprement
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 0x80
; Quitter le programme
mov eax, 1
xor ebx, ebx
int 0x80
/*#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Nombre d'arguments : %d\n", argc);
for (int i = 0; i < argc; i++) {
printf("%s\n", argv[i]);
}
return 0;
}*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Person {
char nom[50];
char prenom[50];
int age;
};
int is_valid_age(int age) {
return (age >= 0 && age <= 127);
}
int main(int argc, char *argv[]) {
if (argc < 4) {
printf("Veuillez fournir un nom, prénom et âge.\n");
return 1;
}
struct Person personne;
// Récupération du nom et prénom
strncpy(personne.nom, argv[1], 49);
personne.nom[49] = '\0'; // Assurer la terminaison de chaîne
strncpy(personne.prenom, argv[2], 49);
personne.prenom[49] = '\0';
// Vérification et récupération de l'âge
personne.age = 0; // Valeur par défaut
for (int i = 3; i < argc; i++) {
int taille = strlen(argv[i]);
int valid = 1;
for (int j = 0; j < taille; j++) {
if (!(argv[i][j] >= '0' && argv[i][j] <= '9')) {
valid = 0;
}
}
if (valid) {
int age = atoi(argv[i]); // Convertit le paramètre en entier
if (is_valid_age(age)) {
personne.age = age;
printf("%s %s %d\n", personne.nom, personne.prenom, age);
break;
}
}
}
// Affichage de la personne
printf("Nom : %s\n", personne.nom);
printf("Prénom : %s\n", personne.prenom);
printf("Âge : %d\n", personne.age);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment