Bonjour a tous,
je dois recoder la fonction memset(char *str, char c, int len) en ASM x86, le probleme c'est que je ne vois pas trop comment faire. j'ais creer un petit bout de code qui ne fonctionne pas des masse, si quelqu'un pourait m'aider.
Pour info le resultat de mon code est super etrange puisqu'il remplace ma "str" par un bon de text d'un printf appeler 4 ligne plus haut dans mon code c.
merci de votre aide !
==== CODE C ====
int main(void)
{
char *txt;
txt = malloc(sizeof(*txt) * 20);
write(1, "START\n", 6);
printf("LEN : %d\n", strlen("Bonjour"));
printf("LEN : %d\n", _strlen("Bonjour"));
printf("POS DE 'p' : %s\n", _strchr("Bonjour", 'p'));
printf("POS DE 'n' : %s\n", _strchr("Bonjour", 'n'));
strcpy(txt, "Salut les amis");
printf("BEFORE MEMSET : %s\n", txt);
txt = (char *)_memset(txt, 'c', 20);
printf("AFTER MEMSET : %s\n", txt);
write(1, "STOP\n", 5);
return (0);
}
===== CODE ASM DU MEMSET =====
section .txt
global _memset
_memset:
push edi
push esi
mov edi, [esp + 4] ; PREND LE PREMIER ARGUMENT (CHAR *)
lea eax, [edi] ; LA VALEUR DE RETOUR
mov esi, [esp + 8] ; LE CHAR A UTILISER POUR SETx
mov ecx, 0 ; INIT. A ZERO LE COMPTEUR
_loop:
mov edi, [esi]
cmp ecx, [esp + 12] ; TEST SI COMPTEUR EST EGALE A ARGU. 3
je _end ; IL EST TROUVE DONC ON SE CASSE
inc ecx ; INCREMENT ESI POUR CE PROMENER DANS LA CHAINE
inc edi ; INCREMENT LE COMPTEUR DE +1
jmp _loop ; ON RECOMMENCE LE TRAITEMENT
_end:
pop esi
pop edi
ret
____________________
Ma Quete n'est pas Terminee