How to do inverse subtraction in TASM?

50 views Asked by At

So we have a TASM program that will ask the user for 2 8-bit numbers. The program shall then solve for the difference and the inverse subtraction (but i could not get it working in this code)

;SUBTRACTION PROGRAM
.MODEL small
.STACK 100h
.DATA

first db 10,13,'First double-digit number: $'
second db 10,13,'Second double-digit number: $'
diff db 10,13,'Difference is: $'
retry db 10,13,'Try again (Y)?: $'


.CODE
mov ax,@data
mov ds,ax

again:
 mov ah,9
 mov dx, OFFSET first
 int 21h

mov ah,1
int 21h
mov bh,al
mov ah,1
int 21h
mov bl,al

mov ah,9
mov dx, OFFSET second
int 21h

mov ah,1
int 21h
mov ch,al
mov ah,1
int 21h
mov cl,al


and bx,0f0fh                    ;EXTRACT ASCII
and cx,0f0fh

mov ax,00h                        ;CLEAR REGISTRY

This part solves the least significant number first

SUB bl,cl                         
mov al,bl
AAS
mov dx,ax

2nd least significant

SUB bh,ch                         ;subtract 2sn
mov ah,0
mov al,bh
AAS

SUB al,dh                        


or dl, 30h
or ax,3030h
mov bx,ax
mov cl,dl

mov ah,9
mov dx, offset diff
int 21h


mov ah,2
mov dl,bh
int 21h
mov ah,2
mov dl,bl
int 21h
mov ah,2
mov dl,cl
int 21h

mov ah,9
mov dx, offset retry
int 21h

mov ah,1
int 21h
cmp al, 'y'
jz again
cmp al, 'Y'
jnz done

done:
mov ah, 4ch
int 21h
END
0

There are 0 answers