此问题已在此处有答案:
Displaying numbers with DOS(1个答案)
Counting Hex in Assembly(2个答案)
6天前关闭
我在汇编8086中做了一个简单的加法计算器,当你在键盘上输入一个值时,它会把它们加起来。我可以把2+2加起来,得到正确的答案,但是当我把9+9加起来时,它输出的是B
.model small
.data
message db "Enter a number: $"
message2 db 0xA, 0xD, "Enter another number: $" ; 0xA = new line, 0xD = carriage return, 0x24 = '$'
plus db " + $"
equal db " = $"
.code
main proc
mov ax, seg message ; ax = message
mov ds, ax ; dx = ax = message
mov dx, offset message
mov ah, 9h ; output of a string at DS:DX
int 21h
mov ah, 01h ; Read character (stores in al)
int 21h
mov bl, al ; saving our input into bl
mov ax, seg message
mov ds, ax ; dx = ax = message2
mov ds, ax ; dx = ax = message2
mov dx, offset message2
mov ah, 9h ; output of a string at DS:DX
int 21h
mov ah, 1h ; Read character
int 21h
mov cl, al ; stores 2nd input
;mov dl, bl ; print 1st input
;mov ah, 02h ; Write character
;int 21h
; print +
mov ax, seg plus
mov ds, ax
mov dx, offset plus
mov ah, 9h
int 21h
; print 2nd number
mov dl, cl
mov ah, 02h
int 21h
; print =
mov ax, seg equal
mov ds, ax
mov dx, offset equal
mov ah, 9h
int 21h
; This is were its having problems adding
; print sum
sub bl, 48
sub cl, 48
add bl, cl
mov dl, bl
add dl, 48
mov ah, 02h
int 21h
endp
end main
我试着调试它,看看它在做什么,它做的一切都是正确的,但当它到达添加部分时,它会说0x12而不是0x9(当做9+9时)
1条答案
按热度按时间fnatzsnv1#
十六进制的。十六进制为12 =十进制为18: