Link to home
Start Free TrialLog in
Avatar of proziath
proziath

asked on

keyboard input and arithmetic operations using assembly language

I am playing with assembly language and I can read single digits from the keyboard and perform arithmetic operations on them and get sensible answers if the result is not greater than 9 because I read the numbers as ascii characters. I would like to be able to handle larger numbers. How can I go about doing this?

My current simple program is as follows. I expect the program that would read numbers of any size  and perform arithmetic calculations on them would be different and more complex.

jmp start
msg: db "Enter first number",13,10,"$"
msg2: db "Enter Second number",13,10,"$"

start:
;ask for first number
mov ah,09 ;
lea dx,msg ;display prompt
int 21h  

;read first number
mov ah,01 ;
int 21h
mov dl, al ;
push dx ;preserve the data in dl

;prompt for second number
mov ah,09 ;
lea dx,msg2 ;load second message
int 21h    ;dos interrupt


;read second number
mov ah,01 ;request keyboard input
int 21h


sub al,30h ;convert ascii to actual integer
pop dx
add dl, al


;display the sum of the two numbers
mov ah,2        
int 21h
int 20h ;end program
ASKER CERTIFIED SOLUTION
Avatar of kenspencer
kenspencer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial