Prev: HLA wont compile!!
Next: Structs in Assembly
From: Richard Cooper on 8 Oct 2005 05:43 On Sat, 08 Oct 2005 02:18:48 -0400, ?a\/b <al(a)f.g> wrote: > i think the division in the book "Handbook of Applied Cryptography" > with the base 2^32 is 100x faster than its binary base form I don't like the way those cryptography people do math. According to them, you can solve x = a + b with the following code: mov eax, [a] mov edx, [b] or eax, edx mov [x], eax What I think has happened is that they're for some reason against using words like "or" and "xor" and so they use "+" and "*" instead. So when they say divide, god only knows what they're actually talking about. Anyway, if you're mearly dividing large numerators by 32-bit or smaller denominators, that's actually pretty easy and you can do it with an algorithm using the divide instruction, so that you're doing it 32 bits per interation instead of 1 bit per interation. However, once the denominator exceeds the capabilities of the CPU's divide instruction, I don't know what else to do besides shift and subtract. (Of course that doesn't mean that there isn't an easier way, I frequently find that I don't know everything. Well, at least on occasion.)
From: ?a/b on 8 Oct 2005 13:05 On Sat, 08 Oct 2005 09:43:33 GMT, "Richard Cooper" <spamandviruses(a)rr.com> wrote: >On Sat, 08 Oct 2005 02:18:48 -0400, ?a\/b <al(a)f.g> wrote: > >> i think the division in the book "Handbook of Applied Cryptography" >> with the base 2^32 is 100x faster than its binary base form > >I don't like the way those cryptography people do math. According to >them, you can solve x = a + b with the following code: > > mov eax, [a] > mov edx, [b] > or eax, edx > mov [x], eax > >What I think has happened is that they're for some reason against using >words like "or" and "xor" and so they use "+" and "*" instead. So when >they say divide, god only knows what they're actually talking about. > >Anyway, if you're mearly dividing large numerators by 32-bit or smaller >denominators, that's actually pretty easy and you can do it with an >algorithm using the divide instruction, so that you're doing it 32 bits >per interation instead of 1 bit per interation. However, once the >denominator exceeds the capabilities of the CPU's divide instruction, I >don't know what else to do besides shift and subtract. if the case adjust the result of partial computation (doing -1) >(Of course that >doesn't mean that there isn't an easier way, I frequently find that I >don't know everything. Well, at least on occasion.)
From: randyhyde@earthlink.net on 8 Oct 2005 13:03 knowledgehungry wrote: > Dear Sir, > I know how to do maths using maths co-processor. I can also do > addition/substraction/multiplication WITHOUT maths co-processor. > But I am stuck up with Division. Can anybody tell me how to perform > division without getting divide overflow and WITHOUT using maths > co-processor using assembly language ? > > I would also like to know hoe to calculate log and antilog WITHOUT > using maths co-processor. > > I know how to convert ascii to float or double using maths co-processor > but do not know how to do conversion WITHOUT using maths coprocessor. > Please tell me how to do these things in assembly language. Are there > any good sites for mathematics using assembly language ? > > -Mahesh Shrikrishna Chavan > chavanmaheshs(a)yahoo.co.in You might want to read this chapter in Art of Assembly: http://webster.cs.ucr.edu/AoA/Windows/HTML/AdvancedArithmetic.html#998258 Also, if you want to learn how to do floating point arithmetic in software, you might check out the floating point routines in the Standard Library for 80x86 Assembly Language Programmers found here: http://webster.cs.ucr.edu/AsmTools/MASM/MASMLibs.html Cheers, Randy Hyde
From: Richard Cooper on 8 Oct 2005 13:15 On Sat, 08 Oct 2005 13:05:21 -0400, ?a\/b <al(a)f.g> wrote: > if the case adjust the result of partial computation (doing -1) How do you do that?
From: ?a/b on 9 Oct 2005 02:21
On Sat, 08 Oct 2005 17:15:15 GMT, "Richard Cooper" <spamandviruses(a)rr.com> wrote: >On Sat, 08 Oct 2005 13:05:21 -0400, ?a\/b <al(a)f.g> wrote: > >> if the case adjust the result of partial computation (doing -1) > >How do you do that? i say only where the book algo do it: in point 3.2 and in 3.4 for reference see the book; it is in internet 14.20 Algorithm Multiple-precision division INPUT: positive integers x = (xn, ... x1,x0)b, y = (yt,... y1,y0)b with n >= t >= 1, yt != 0. OUTPUT: the quotient q = (qn-t, ... q1,q0)b and remainder r = (rt,... r1r0)b such that x = qy + r, 0 <= r < y. 1. For j from 0 to (n - t) do: qj 0. 2. While (x ybn-t) do the following: qn-t qn-t + 1, x x - ybn-t. 3. For i from n down to (t + 1) do the following: 3.1 If xi = yt then set qi-t-1 b - 1; otherwise set qi-t-1 b(xib + xi-1)=yt)c. ####################### 3.2 While (q[i-t-1](y_tb +y_t-1) > x_ib^2 +x_i-1b + x_i-2) do: q[i-t-1]= q[i-t-1] -1. ####################### 3.3 x = x - q[i-t-1]yb^(i-t-1). ####################### 3.4 If x < 0 then set x=x + yb^(i-t-1) and q[i-t-1]= q[i-t-1] - 1. ####################### 4. r x. 5. Return(q,r). |