这是我第一次写在这里......我试着解释我的问题! 我在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读过的char('y')... 请帮帮我!
答案 0 :(得分:0)
printf
和scanf
的格式字符串非常不同。 scanf
format string控件仅输入,scanf
不输出内容(只是回显输入的字符)。 scanf
只会产生res db "x = %c",10,0
错误。添加一行scanf_res db "%c",0
并将mov eax, offset res
更改为mov eax, offset scanf_res
。
printf
format string res db "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