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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert AScii string to 64 bit integer

Status
Not open for further replies.

dukely

Technical User
Sep 18, 2002
6
US
Hi,
I am to take an input from user. Then, I need to convert that Ascii string to a 64-bit integer. I can do this with 32-bit, but I have no idea how to do it in 64-bit.

Anybody know, please give me a hint. Thanks a lot.
 
First you need to know how to perform multi-word addition and subtraction, as well as multi-word shifts.

This is done using the adc and sbb instructions. For shifts you must use rcl and rcr.

Basically, to add two 64-bit numbers:
.data
num1 dq 100
num2 dq 200
.code
mov ecx,dword ptr num1
add dword ptr num2,ecx
mov ecx,dword ptr num1[4]
ADC dword ptr num2[4],ecx

Subtraction is performed by replacing ADD with SUB and ADC with SBB.


For shift, you must shift by only one bit at a time.
To shift a 64-bit number left (i.e. x2)
shl dword ptr num1,1
rcl dword ptr num1[4],1

To shift a 64-bit number right (i.e. /2)
shr dword ptr num1[4],1
rcr dword ptr num1,1


So why do you need to know about addition and shifting? Because you CAN'T use the 32-bit mul and div reliably! Remember you are using 64-bit numbers and mul and div can't hack 64-bit numbers.

So how to multiply by 10 (which is needed to convert to integer, right?)??

Well, multiply by 10 is:
10X
2(5X)
2(4X + 1X)

So you need to multiply by powers of two. And how to multiply by powers of two? Why shift, of course!!!

So, to multiply by 10, put the number in two registers, shift the registers left twice, add the original number, then shift the registers again.

Have fun! And make sure you check your numbers...
"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top