Solved

keyboard input and arithmetic operations using assembly language

Posted on 2003-11-21
1
10,574 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Binary bomb phase 3 10 2,037
explanation required 5 380
Modulo in assembly 5 2,492
Fill in the missing parts of the C code to get a program equivalent to the generated assembly code 1 1,687
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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