汇编PTA

汇编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字符是用来输入换行字符的。



  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值