How to calculate the difference of two numbers in x8086 assembly language

ConantheBarbarian

Senior member
Nov 8, 2000
239
0
0
I need to calculate the difference of two numbers ex: 90-18 = 72
I am able to code the proram with single digits but I need help with double digits. This is coded in the x8086. Any help will be appreciated.

Single digit subtraction code:

.MODEL SMALL
.STACK 100H
.DATA

MSG1 DB 'FIRST > $'
MSG2 DB 'SECOND > $'
MSG3 DB 'THE SUBTRACTION OF '
VALUE1 DB ?
MSG4 DB ' AND '


VALUE2 DB ?, ' IS '

SUM DB ?,'.$'

CR DB 0DH, 0AH, '$'

.CODE
MAIN PROC
;INITIALIZE DS
MOV AX, @DATA
MOV DS, AX
;PROMPT FOR FIRST INPUT
LEA DX, MSG1
MOV AH, 9H
INT 21H
MOV AH, 1H
INT 21H
MOV VALUE1, AL
MOV BH, AL
SUB BH, '0'
;CARRIAGE RETURN FORM FEED
LEA DX, CR
MOV AH, 9H
INT 21H
;PROMPT FOR SECOND INPUT
LEA DX, MSG2
MOV AH, 9H
INT 21H
MOV AH, 1H
INT 21H
MOV VALUE2, AL
MOV BL, AL
SUB BL, '0'
;SUB THE VALUES CONVERT TO CHARACTER AND SAVE
SUB BH, BL
ADD BH, '0'
MOV SUM, BH
;CARRIAGE RETURN FORM FEED
LEA DX, CR
MOV AH, 9H
INT 21H
;OUTPUT THE RESULT
LEA DX, MSG3
MOV AH, 9H
INT 21H
;RETURN TO DOS
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
 

YaKuZa

Senior member
Aug 26, 2000
995
0
0
What's assembly? I have no idea what any of this is about.

You're using the wrong interrupt if you want to allow for double digit stuff. You can't use AH=01H / int 21H because that just waits for a key to be pressed and then it moves on. You have to use AH=0AH / int 21H. That will read in a string. Then you can make a translate table if you want, or do something else. Good luck.
 

onelin

Senior member
Dec 11, 2001
874
0
0
Ahh, assembly. Sounds like my homework :D

Here's how you'd go about this:
You already know how to read in single digits and convert them to 'numeric quantities' as we dub them, that's great. All you have to do for two digits is read one character in as a digit, multiply it by 10 (add it to itself 9 times with a loop would be the simplest way...but you could use MUL), store it in a safe place, read in the second digit of the number, then add it to the first. Ditto for your second 2 digit number.
i.e. to read in:
79
read in the 7, subtract '0', multiply by 10, you have 70. get it out of AL. read in the 9, add it to the 70.

Rinse, repeat ;) If you need more help just reply.