我的代码的一部分应该得到两个整数的和,差,乘积和商并显示它们。它适用于总和,差异和产品。但是,当谈到商时,它没有显示任何东西。任何人都可以解释为什么会这样,如果有任何方法可以解决它? 提前谢谢!
printString result1
plus:
mov ax, firstInteger
mov bx, secondInteger
add ax, bx
call printAns
call printNewLine
; ---------------------------------------------------------------------------
printString result2
minus:
mov ax, firstInteger
mov bx, secondInteger
sub ax, bx
call printAns
call printNewLine
; ---------------------------------------------------------------------------
printString result3
multiply:
mov ax, firstInteger
mov bx, secondInteger
mul bx
call printAns
call printNewLine
; ---------------------------------------------------------------------------
printString result4
divide:
mov ax, firstInteger
mov bx, secondInteger
div bx
call printAns
call printNewLine
printAns看起来像这样:
printAns proc
xor cx, cx
xor dx, dx
xor bx, bx
mov bx, 10
loop1:
mov dx, 0000h ;clears dx during jump
div bx ;divides ax by bx
push dx ;pushes dx(remainder) to stack
inc cx ;increments counter to track the number of digits
cmp ax, 0 ;checks if there is still something in ax to divide
jne loop1 ;jumps if ax is not zero
loop2:
pop dx ;pops from stack to dx
add dx, 30h ;converts to it's ascii equivalent
mov ah, 02h
int 21h ;calls dos to display character
loop loop2 ;loops till cx equals zero
xor ax, ax
xor bx, bx
ret
printAns endp
例如,如果我输入9作为第一个数字而输入3作为第二个数字,则会发生以下情况:
答案 0 :(得分:0)
分区错过了DX寄存器的清除,因为分词总是将DX:AX除以指定的操作数。
printString result4
divide:
mov ax, firstInteger
xor dx, dx
div secondInteger
call printAns
call printNewLine