I am trying to read a character in a loop from keyboard until I pass '&'. The code seems to work if I try to read numbers and with format "%d", but not with "%c".
.386
.model flat,stdcall
includelib msvcrt.lib
extern exit:proc
extern printf:proc
extern scanf:proc
public start
.data
string db 100 dup(?)
msg db "Read until &",13,10,0
format db "%c",0
caracter db " "
.code
start:
mov ecx,3
mov esi,0
reader:
push ecx
push offset msg
call printf
add esp,4
pop edx
push edx
push offset caracter
push offset format
call scanf
add esp,8
pop ecx
loop reader
exit_from:
push 0
call exit
end start
The result is something like this:
Read until &
a
Read until &
Read until &
b
exit
What am I missing, and how do I fix it?