我正在用8086汇编语言编写一个程序,它要求一个介于1-9之间的个位数,然后存储它。如果不是介于1-9之间,它就应该返回。
有什么好方法来测试它并让它返回(并允许您输入另一个数字),直到它满足了要求?
到目前为止我的代码是:
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发布于 2017-02-25 23:15:23
我还没有对其进行测试,但通常情况下,代码应该检查BL是否小于31h或大于39h。这些是1和9的ASCII值。
因此,一些示例代码可能如下所示:
; 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 30hhttps://stackoverflow.com/questions/42462567
复制相似问题