Assembly printf在masm32中打印字符时出错

Assembly printf在masm32中打印字符时出错,assembly,printf,scanf,masm,masm32,Assembly,Printf,Scanf,Masm,Masm32,这是我第一次在这里写作。。。我试着解释我的问题! 我用masm32编写了这段代码 .586 .model flat .data mess db "digita un carattere ",0 res db "x = %c",10,0 .data? salva db ? .code extern _printf:proc extern _scanf:proc _funzione proc ;pre push ebp mov ebp,esp push ebx push edi pus

这是我第一次在这里写作。。。我试着解释我的问题! 我用masm32编写了这段代码

.586
.model flat
.data

mess db "digita un carattere    ",0
res db "x = %c",10,0

.data?
salva db ?

.code
extern _printf:proc
extern _scanf:proc

_funzione proc
;pre
push ebp
mov ebp,esp
push ebx
push edi
push esi

mov eax, offset mess
push eax
call _printf ;puting out the message
mov eax, offset salva
push eax
mov eax, offset res
push eax
call _scanf ;taking the char and saving it in "salva"
add esp,12
xor eax,eax
mov eax,offset salva
push eax
mov eax, offset res
push eax
call _printf ;printing the char
add esp,8

;post
pop esi
pop edi
pop ebx
pop ebp

ret
_funzione endp
end
当我编译它时,输出是:

我不明白为什么printf不打印scanf读过的字符('y')。。。
请帮帮我

printf和scanf的格式字符串非常不同。仅控制输入,
scanf
不输出内容(仅回显输入字符)
scanf
只会产生一个错误,即
resdb“x=%c”,10,0
。添加一行
scanf_res db“%c”,0
并将
mov eax,offset res
更改为
mov eax,offset scanf_res

resdb“x=%c”,10,0
要求推送一个直接值,而不是字符串的偏移量。将
mov eax,offset salva
更改为
mov al,salva

.586
.model flat
.data

mess db "digita un carattere    ",0
scanf_res db "%c",0
res db "x = %c",10,0

.data?
salva db ?

.code
extern _printf:proc
extern _scanf:proc
extern _fflush:proc

_funzione proc
;pre
push ebp
mov ebp,esp
push ebx
push edi
push esi

mov eax, offset mess
push eax
call _printf ;puting out the message
mov eax, offset salva
push eax
mov eax, offset scanf_res
push eax
call _scanf ;taking the char and saving it in "salva"
add esp,12

xor eax,eax
mov al, salva
push eax
mov eax, offset res
push eax
call _printf ;printing the char
add esp,8

;post
pop esi
pop edi
pop ebx
pop ebp

ret
_funzione endp
end

printf
scanf
的格式字符串非常不同。仅控制输入,
scanf
不输出内容(仅回显输入字符)
scanf
只会产生一个错误,即
resdb“x=%c”,10,0
。添加一行
scanf_res db“%c”,0
并将
mov eax,offset res
更改为
mov eax,offset scanf_res

resdb“x=%c”,10,0
要求推送一个直接值,而不是字符串的偏移量。将
mov eax,offset salva
更改为
mov al,salva

.586
.model flat
.data

mess db "digita un carattere    ",0
scanf_res db "%c",0
res db "x = %c",10,0

.data?
salva db ?

.code
extern _printf:proc
extern _scanf:proc
extern _fflush:proc

_funzione proc
;pre
push ebp
mov ebp,esp
push ebx
push edi
push esi

mov eax, offset mess
push eax
call _printf ;puting out the message
mov eax, offset salva
push eax
mov eax, offset scanf_res
push eax
call _scanf ;taking the char and saving it in "salva"
add esp,12

xor eax,eax
mov al, salva
push eax
mov eax, offset res
push eax
call _printf ;printing the char
add esp,8

;post
pop esi
pop edi
pop ebx
pop ebp

ret
_funzione endp
end