汇编PTA
1 判断数字
分数 20
作者 mll
单位 郑州大学
4.17 编写一个程序,先提示输入数字“Input Number :0~9”, 然后在下一行显示输入的数字,结束。如果不是键入了0~9数字,就提示错误“Error!”, 继续等待输入数字。
输入格式:
输入在一行中给出1个数字
输出格式:
每组输入输出对应的数字或“Error!”
输入样例:
a
9
输出样例:
在这里给出相应的输出。例如:
Input Number :0~9
Error!
Input Number :0~9
9
输入样例:
9
输出样例:
在这里给出相应的输出。例如:
Input Number :0~9
9
我们在这里给出答案
extern printf
extern scanf
section .data
tip db "Input Number :0~9",10,0
err db "Error!",10,0
outfrm1 db "%s",0
intfrm1 db "%d",0
chfrm1 db "%c",0
x db 0
y db 0
section .code
global main
main:
begin:push tip
push outfrm1
call printf
add esp,8
push x
push chfrm1
call scanf
add esp,8
push y
push chfrm1
call scanf
add esp,8
mov eax,0
mov al,[x]
cmp al,'0'
jb errlab
cmp al,'9'
ja errlab
jmp end
errlab:push err
push outfrm1
call printf
add esp,8
jmp begin
end:
push eax
push chfrm1
call printf
add esp,8
mov eax,0
ret
这个题我也不会,试了好久,最后和我对象要的答案,好怪,为什么输入的时候,用两个变量来进行输入,而且后来的那个输入的Y还没有用,我真服了。
懂了,Y字符是用来输入换行字符的。