Factor of two integers not displayed in an assembly
A piece of my code should get the sum, difference, product and quotient of two integers and display them. It works great for amount, difference and product. However, when it comes to private, it doesn't display anything. Can someone explain why this is the case and is there a way to get around it? Thanks in advance!
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 looks like this:
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 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
For example, if I enter 9 as the first number and 3 as the second, this happens:
+3
source to share