Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with reading integers from the keyboard

Status
Not open for further replies.

matthius

Programmer
Jun 1, 2004
1
AU
Has anyone out there got some sample code for reading in numbers (in ASCII) and converting these to actual numbers to be used in calculations?

I amd using TASM and I need to get the user to enter in 2 32bit numbers and then I will add them. I know the code for reading in from the keyboard (ie. mov al, o1h int 21h) but I do not know what to do then to convert them into numbers which I can use. If you have any example source code it would be appreciated.
 
Im presuming you know the amount of digits the person entered. Hope this routine works, I wrote it on the fly, didnt have one avail.

mov ebx,LenofInval ;get amount of chars entered
mov ecx,1 ;init our mutliplier
mov newval,0 ;value to be stored here
@loop
mov eax, inval[bx] ;get digit - start at lowest(last)
cmp eax, 30h ;check for good value to convert
jl toolow ; error - not a number
cmp eax, 39h
jg toohigh ; error - not a number

sub eax,30h ;get value
mul ecx ;get digit offset value
add newval,eax ;our new value
mov eax,10 ;next digit multi
mul ecx
mov ecx, eax ;save it
dec ebx ;next offset
jnz @loop
;value in newval is number



Thaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top