Solved

keyboard input and arithmetic operations using assembly language

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

21 Experts available now in Live!

Get 1:1 Help Now