我需要读取和打印存储在两个变量中的数字(我正在做一个菜单程序),但当我打印它们时,它打印的是ASCII表中的小写字母(如a,b,c,而不是2,3,4)。我知道我应该减去48并乘以48,但我没有找到一个很好的解决方案,如何在我的程序中实现这种转换。我使用的是汇编x86,TASM。
这是阅读输入的代码:
情节:
mov dx, offset prompt1
mov ah, 9
int 21h
input_x:
mov bx, offset x ; point BX to the start of the array x
mov cx, 10 ; set the counter to the number of elements in the array x
input_loop1:
mov ah, 01h ; function to read a single character
int 21h ; call DOS function
mov [bx], al ; store the character in the current array element
inc bx ; move to the next array element
loop input_loop1 ; repeat until counter reaches 0
jmp input_y
input_y:
mov dx, offset prompt2
mov ah, 9
int 21h
mov bx, offset y ; point BX to the start of the array y
mov cx, 10 ; set the counter to the number of elements in the array y
input_loop2:
mov ah, 01h ; function to read a single character
int 21h ; call DOS function
mov [bx], al ; store the character in the current array element
inc bx ; move to the next array element
loop input_loop2 ; repeat until counter reaches 0
jmp bucla
我认为问题出在我的打印代码上
阿菲萨雷:
mov dx, offset prompt3
mov ah, 9
int 21h
print_x:
mov bx, offset x ; point BX to the start of the array x
mov cx, 10 ; set the counter to the number of elements in the array x
print_loop1:
mov dl, [bx] ; move the value of the current array element to DL
add dl, 48 ; convert the number to its ASCII equivalent
mov ah, 02h ; function to print a single character
int 21h ; call DOS function
inc bx ; move to the next array element
loop print_loop1 ; repeat until counter reaches 0
jmp print_y
print_y:
mov dx, offset prompt4
mov ah, 9
int 21h
mov bx, offset y ; point BX to the start of the array y
mov cx, 10 ; set the counter to the number of elements in the array y
print_loop2:
mov dl, [bx] ; move the value of the current array element to DL
add dl, 48 ; convert the number to its ASCII equivalent
mov ah, 02h ; function to print a single character
int 21h ; call DOS function
inc bx ; move to the next array element
loop print_loop2 ; repeat until counter reaches 0
jmp bucla ; return to main loop
1条答案
按热度按时间1wnzp6jl1#
我实际上如何打印变量X和Y中存储的数字呢?
您已经将数字的ASCII表示存储在X和Y变量中。因此,打印数字不需要任何转换。只需从 afisare 代码中删除
add dl, 48
行。但是如果您确实想将输入的数字从文本转换为整数,那么请阅读Inputting multi-radix multi-digit signed numbers with DOS中的内容。
显示此类整数时,应读取Displaying numbers with DOS。