SF40
SF40

Reputation: 81

Finding how many words start with the letter a in assembly

I have to read from a file words and print how many of them start with the letter a or A. The problem is that when I am trying to read the words, the program never ends. It reads the last word over and over again.

What changes can I bring to this code to fix this problem?

.data
fisier db "input.txt", 0
mode db "r", 0
format db "%s", 0
cuvant dd 100 dup (?)
format2 db "%d", 0
    
.code

count proc
    push ebp
    mov ebp, esp
    sub esp, 4
    cmp [cuvant], 'a'
    jne final
    cmp [cuvant], 'A'
    jne final
    
    add edx, 1
    
    final:
    mov esp, ebp
    pop ebp
    ret 
count endp

start:
    mov edx, 0
    push offset mode
    push offset fisier
    call fopen
    add ESP, 8
    mov ebx, eax  
    
read:
    push offset cuvant
    push offset format
    push ebx
    call fscanf
    add esp, 8
    
    test eax, eax
    jz end_reading

    mov eax, [cuvant]
    push eax
    call count

    jmp read

end_reading:
    mov eax, edx
    push edx
    push offset format2
    call printf
    add esp, 8

    ;apel functie exit
    push 0
    call exit
end start

Upvotes: 0

Views: 45

Answers (0)

Related Questions