I know this is so simple but...Is there any algo out there that calculates the least significant digit faster than using div or sub?
I'm thinking of the shifts instructions, but i'm not sure...I can't think of any other methods.
Posted on 2002-01-30 17:27:09 by stryker
; your number is in EAX, you want the least significant digit
mov edx,19999999h ; 1/10 * 2^32
mul edx
mov edx,10
mul edx
; darn rounding errors...
add eax,0FFFFh
adc edx,0
; EDX is the least significant digit

...you just said faster without divide. ;)
(I don't know if this is faster)

One_Tenth dd 1999999Ah ; 1/10 * 2^32
Ten dd 10

; your number is in EAX, you want the least significant digit
mul One_Tenth
; put some code here for free
mul Ten
; EDX is the least significant digit
Posted on 2002-01-30 18:44:50 by bitRAKE
bitrake, I haven't tested your algo yet, thanks for the help...I'll try it soon and post my next project in the algo and source code section.
Posted on 2002-01-31 12:14:58 by stryker
mov eax 112415
and eax 0F
aam ; >>> al = 05

Posted on 2002-01-31 13:48:27 by Betov
Ah no, doesn't work if greater than the Base.
Sorry, too fast. upper example worked due
to hazard... :[

There is one other way with 'FBSTP':

mov F?FPUvalue 15649
fild F?FPUvalue
FBSTP T?BCDtext ; 10 Bytes record.
mov al B?BCDtext
and al 0F ; al = 9

Should not be faster than /10 upper way,
but may help for other digits...

Posted on 2002-01-31 14:55:12 by Betov