我的汇编语言代码有什么问题
What is wrong with my assembly language code
我对这段代码有疑问,它的目的是收集一个数字并将其加倍,但它只接受 1 到 9 之间的数字,并输出 5 到 9 之间所有加倍数字的第二个值,什么可以做到让它输出正确的值
;DOUBLE THIS PROGRAM PROMPTS THE USER TO ENTER A NUMBER
;DOUBLE THE NUMBER,AMD OUTPUT THE RESULT
.model small
.stack
.data
prompt db 0ah,0dh, 'enter the number : $'
msg db 0ah,0dh, 'Double your number is : '
result db 0ah,0dh, '$'
.code
start:
mov ax,@data
mov ds,ax
lea dx,prompt
mov ah, 9 ;dos fn to output string up to $
int 21h
mov ah,1 ;dos fn to input byte into al
int 21h
sub al,30h ;convert from ascii to integer
add al,al ;sum inputted value to itself
aaa
or al,30h
mov result,al ;add the double value of the value to result
lea dx, msg
mov ah, 9
int 21h
mov ah,4ch
int 21h
end start
你的程序有几个问题:
您没有保留必要的 space 来存储 字节大小的 结果。 db
指令后需要一个额外的零。
result db 0, 0ah, 0dh, '$'
因为将数字从 5 加倍到 9 将不可避免地产生两位数的结果,您只需将结果更改为 字数。
result db 0, 0, 0ah, 0dh, '$'
您使用的 aaa
指令有误。幸运的是,有适合您目的的 aam
指令。
AAM divides AL by ten and stores the quotient in AH, leaving the remainder in AL.
下一个代码将始终显示 2 位数字的结果。如果需要,您可以在将 AX 写入结果变量之前将 AL 中的字符“0”替换为“”。
aam
or ax, 3030h
xchg al, ah
mov result, ax
我对这段代码有疑问,它的目的是收集一个数字并将其加倍,但它只接受 1 到 9 之间的数字,并输出 5 到 9 之间所有加倍数字的第二个值,什么可以做到让它输出正确的值
;DOUBLE THIS PROGRAM PROMPTS THE USER TO ENTER A NUMBER
;DOUBLE THE NUMBER,AMD OUTPUT THE RESULT
.model small
.stack
.data
prompt db 0ah,0dh, 'enter the number : $'
msg db 0ah,0dh, 'Double your number is : '
result db 0ah,0dh, '$'
.code
start:
mov ax,@data
mov ds,ax
lea dx,prompt
mov ah, 9 ;dos fn to output string up to $
int 21h
mov ah,1 ;dos fn to input byte into al
int 21h
sub al,30h ;convert from ascii to integer
add al,al ;sum inputted value to itself
aaa
or al,30h
mov result,al ;add the double value of the value to result
lea dx, msg
mov ah, 9
int 21h
mov ah,4ch
int 21h
end start
你的程序有几个问题:
您没有保留必要的 space 来存储 字节大小的 结果。
db
指令后需要一个额外的零。result db 0, 0ah, 0dh, '$'
因为将数字从 5 加倍到 9 将不可避免地产生两位数的结果,您只需将结果更改为 字数。
result db 0, 0, 0ah, 0dh, '$'
您使用的
aaa
指令有误。幸运的是,有适合您目的的aam
指令。AAM divides AL by ten and stores the quotient in AH, leaving the remainder in AL.
下一个代码将始终显示 2 位数字的结果。如果需要,您可以在将 AX 写入结果变量之前将 AL 中的字符“0”替换为“”。
aam or ax, 3030h xchg al, ah mov result, ax