Pb assembleur cmp caractère
Lulu_n10
-
Manu -
Manu -
Bonjour, voici mon code, je comprend pas pourquoi le cmp ebx,'A' ne fonctionne pas.
global main extern printf extern scanf extern malloc extern free extern fopen extern fclose extern fscanf extern fgets section .data SIZE EQU 256 buffer times SIZE db 0 c dd 0 com db 'A' _in_ dd 0 opening_mode db "r",0 nom_fichier db "val.txt",0 msg db "valeur:%s",10,0 msg_testc db "car:%c",10,0 msg_vect db "[%f, %f, %f, %f]",10,0 msg_fscanf db "%c",10,0 msg_com db "ceci est un commentaire",10,0 msg_test db "bug",10,0 struc Vector v_1: resd 1 v_2: resd 1 v_3: resd 1 v_4: resd 1 v_suivant: resd 1 endstruc section .text ;------------------------------------------------------------------------------------------------------------------------------ traite_fichier: push ebp mov ebp,esp push dword [_in_] push dword SIZE push dword buffer call fgets add esp,12 push dword buffer push dword msg call printf mov ebx,[buffer] push dword ebx push dword msg_testc call printf cmp ebx,'A' jne .endcom push dword msg_com call printf jmp .endcom2 .endcom: push dword msg_test call printf .endcom2: mov esp,ebp pop ebp ret ;------------------------------------------------------------------------------------------------------------------------------ main: push ebp mov ebp,esp pushad push dword opening_mode push dword nom_fichier call fopen add esp,8 mov [_in_],eax cmp eax,0 je .end call traite_fichier .end: popad mov esp,ebp pop ebp
A voir également:
- Pb assembleur cmp caractère
- Caractère spéciaux - Guide
- Caractère ascii - Guide
- Caractere speciaux - Guide
- Caractere vide - Guide
- Caractere speciaux mac - Guide
1 réponse
Bonjour,
mov ebx,[buffer]
push dword ebx
push dword msg_testc
call printf
cmp ebx,'A'
Je ne sais pas comment votre buffer est rempli, par contre je vois que vous en prenez 4 octets pour les mettre en ebx et comparer au caractère 'A'.
Soit vous remplissez votre buffer de manière inhabituelle, soit vous vouliez n'en prendre qu'un seul octet. Dans ce pas il faut remplacer :
mov ebx,[buffer]
par
movzx ebx,[buffer]
Manu
mov ebx,[buffer]
push dword ebx
push dword msg_testc
call printf
cmp ebx,'A'
Je ne sais pas comment votre buffer est rempli, par contre je vois que vous en prenez 4 octets pour les mettre en ebx et comparer au caractère 'A'.
Soit vous remplissez votre buffer de manière inhabituelle, soit vous vouliez n'en prendre qu'un seul octet. Dans ce pas il faut remplacer :
mov ebx,[buffer]
par
movzx ebx,[buffer]
Manu