首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何测试输入字符是否介于1-9之间?

如何测试输入字符是否介于1-9之间?
EN

Stack Overflow用户
提问于 2017-02-25 22:52:43
回答 1查看 4.7K关注 0票数 0

我正在用8086汇编语言编写一个程序,它要求一个介于1-9之间的个位数,然后存储它。如果不是介于1-9之间,它就应该返回。

有什么好方法来测试它并让它返回(并允许您输入另一个数字),直到它满足了要求?

到目前为止我的代码是:

代码语言:javascript
复制
section .data
  prompt1 db "Enter a single digit  digit between 1-9 --> $"
section .text   
  ;Display prompt
  mov   ah,9        ; print prompt
  mov   dx,prompt1  ; load register with prompt1
  int   21h         ; display it
  ; Input character and store.
  mov   ah,1        ; reach char fcn
  int   21h         ; read character into al
  mov   bl,al       ; store character into bl
EN

回答 1

Stack Overflow用户

发布于 2017-02-25 23:15:23

我还没有对其进行测试,但通常情况下,代码应该检查BL是否小于31h或大于39h。这些是19的ASCII值。

因此,一些示例代码可能如下所示:

代码语言:javascript
复制
  ; Input character and store.
loop1:              ; added label
  mov   ah,1        ; read char fcn
  int   21h         ; read character into AL
  mov   bl, al      ; store character into BL
  ; now comes the additional code
  cmp   bl, 31h     ; compare BL to the ASCII value of '1'
  jb    loop1       ; jump back if ASCII value is less than '1' = 31h
  cmp   bl, 39h     ; compare BL to the ASCII value of '9'
  ja    loop1       ; jump back if ASCII value is greater than '9' = 39h
  ; BL contains an ASCII value between '1' and '9' which integer value can be acquired by subtracting the value 30h
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42462567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档