我正在尝试添加两位数字并将结果打印到VDU,返回的最大数字不会超过3位数。
到目前为止,我已经能够为我的VDU添加一个两位数字,但我不确定如何重新复制这个数字并将数字加在一起。
我到目前为止所编写的代码是:
In 00
sub al, 30
mul al, 0a
push al
in 00
sub al, 30
pop bl
add al, bl
push al
mod al, 0a
add al, 30
mov [c1], al
pop al
div al, 0a
add al, 30
mov [c0], al
end
答案 0 :(得分:0)
您似乎使用了大量无效8086或x86代码的指令!
in 00 Use a DOS function to get a character
mul al, 0a Move the number 10 to an extra register
push al Push a complete word to to stack
pop bl Pop a complete word off the stack
mod al, 0a Use the remainder you get from a division
div al, 0a Move the number 10 to an extra register
这就是它的样子(没有应用优化):
mov ah, 01h Input a character for the tens
int 21h
sub al, 30h Turn into number
mov bl, 10
mul al, bl Multiplies AL by BL : So times 10
push ax
mov ah, 01h Input a character for the units
int 21h
sub al, 30h Turn into number
mov ah, 0 Clear AH so addition works correctly
pop bx
add ax, bx Add tens and units
Here anything else!
mov bl, 10
div bl Divides AX by BL : Gives remainder in AH, quotient in AL
add ah, 30h Turn into character
mov [c1], ah
add al, 30h Turn into character
mov [c0], al