Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

keyboard input and arithmetic operations using assembly language

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modulo in assembly 5 2,727
convert array of bytes  into hex string and back 11 642
writing Bios 6 448
Return (ret) value over-writing on x64 8 671
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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