Solved

keyboard input and arithmetic operations using assembly language

Posted on 2003-11-21
1
10,544 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:proziath
1 Comment
 
LVL 3

Accepted Solution

by:
kenspencer earned 125 total points
ID: 9827449
Hi,
I suggest you do a buffered keyboard input and convert the input string (you may want to verify that it's a number and within a certain range) to a number.  Then you should be able to add the numbers, convert the result to a string and display it.  All I am doing here is describing the methodology (rather than providing code) -- this is to encourage you to experiment more.

Ken
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FIR_filter 2 222
programming/ use of multiple cores - theoretical optimization of threads/cores 7 572
How to join a 9V power supply cable 4 447
Binary Bomb: Phase 4 func4 3 310
There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now