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
Sliver
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
Sliver
you have to code a bignumber library =)
i coded a lame one if you want, it' s on my website (http://www.effervescence.com)
i coded a lame one if you want, it' s on my website (http://www.effervescence.com)
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?
Sliver
Can you explain (or someone else perhaps) how you add two large numbers together? at least the idea behind it?
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.
I'd appreciate it if it could be explained a little more indebth
Sliver
Sliver
[COLOR=blue][size=9]1[/SIZE][/COLOR]
89
+ 67
----
[COLOR=red]1[/COLOR]56
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...)
In ASM:
; 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
LOCAL nLoop
mov ecx, SizeOfNumber
clc
nLoop:
; 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
ENDM
; ...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
LOCAL nLoop
mov ecx, SizeOfNumber
clc
nLoop:
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
ENDM
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...
Sliver
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...
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:
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.
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
...or...
BigNumAdd ebx, esi, edi, [edi - 4] ; dynamic count
...or...
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.