Say I have a huge number....

150! = 5.7133839564458575e+262

Say I wanted to just list all of the numbers in this 150!, how would i do this (since it's 250+ digits long)

I believe you use the stack, but I'm not sure...

Can someone point me to or help me with how this is done exactly?

I'm not exactly sure if using the stack is like using a register...

I'd also like to know how to add and multiply, but I'll take whatever someone knows

Posted on 2002-03-09 04:40:04 by Sliver
you have to code a bignumber library =)
i coded a lame one if you want, it' s on my website (
Posted on 2002-03-09 05:40:42 by roy
Took a look at the source, but it's not a beginners tool...

Can you explain (or someone else perhaps) how you add two large numbers together? at least the idea behind it?

Posted on 2002-03-09 12:37:38 by Sliver

Can you explain (or someone else perhaps) how you add two large numbers together?

remember the pen & paper method you learned in school?
it's just the same here, the only difference is that you're working with dwords instead of single decimal digits.
Posted on 2002-03-09 12:57:19 by Tola
I'd appreciate it if it could be explained a little more indebth

Posted on 2002-03-09 13:29:35 by Sliver

+ 67
In elementary school we learn to add big numbers we just work a couple digits at a time and keep track of the overflow (carry). So, in the above example, we start with 9+7 = 16. We put down the six and carry the one. (etc...)

; 1. Clear carry flag

; 2. Get two digits
; 3. Add digits and carry
; 4. Store result
; 5. Goto (2) until number is added

BigNumAdd MACRO Result, Number1, Number2, SizeOfNumber

mov ecx, SizeOfNumber
; Note: the only instruction in the loop effecting the carry flag is ADC
mov eax, [Number1]
lea Number1, [Number1 + 4]
adc eax, [Number2]
lea Number2, [Number2 + 4]
mov [Result], eax
lea Result, [Result + 4]
dec ecx
jne nLoop

jc NumberOverflow ; Error: loss of percision

; ...more optimized version:
; Note: order of number data: CDEF 89AB 4567 0123
; each number is a byte, number of byte is significance
BigNumAdd MACRO Result, Number, SizeOfNumber

mov ecx, SizeOfNumber
mov eax, [Number + ecx*8 - 4]
mov edx, [Number + ecx*8 - 8]
adc [Result + ecx*8 - 4], eax
adc [Result + ecx*8 - 8], edx
dec ecx
jne nLoop
Posted on 2002-03-09 15:06:08 by bitRAKE
Thanks alot... I appreciate the break down (although I sometimes feel stupid having to ask, but hey... if you want to learn)

Two quick questions:
1) jc NumberOverflow (jumps when there is a caryy... but where does it jump to?)

2) How would you call and display this macro...

Posted on 2002-03-10 14:04:03 by Sliver
1) Your error handler - sometimes this isn't an error, or the number is just made bigger to hold the result.

2) All (but the last) the parameters to the first macro have to be registers:
  mov esi, OFFSET MyBigSpecialNumber

mov edi, OFFSET MyBigSillyNumber
mov ebx, OFFSET Result
BigNumAdd ebx, esi, edi, 256
BigNumAdd ebx, esi, edi, [edi - 4] ; dynamic count
BigNumAdd esi, esi, edi, [edi - 4] ; dest is source1
Displaying the results requires converting the number to ASCII (divide by ten, add '0' to the remainder, store, loop until zero). You need a BigNumDivide.

When your new to something it takes much effort. The other math operations are handled in a similar manner to what was learned in school. Look over roy's code - try to read through it, stopping to research where ever you don't understand what is going on. Before long the reading will become much easier and your will see the algorithms beyond the code, but it does take time.
Posted on 2002-03-10 15:03:27 by bitRAKE