News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

For Loop To Assembly

Started by jwill22, February 26, 2011, 05:02:19 PM

Previous topic - Next topic

Shooter

So, why IS he getting 650 as an answer in his original sample?
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

clive

Quote from: Shooter on February 27, 2011, 01:41:51 PM
So, why IS he getting 650 as an answer in his original sample?

Because the C/C++ code is correct, the first assembler version adds the sum to ebx which it doesn't need too, and then prints the value in ebx instead of the one in sum.

Or am I missing your point?

To extend Lingo's solution for different values of N, we could make a table. The point however is to understand the math.

Sum at each iteration :

0 :    0
1 :    2
2 :    6
3 :   12
4 :   20
5 :   30
6 :   42
7 :   56
8 :   72
9 :   90
10 :  110
11 :  132
12 :  156
13 :  182
14 :  210
15 :  240
16 :  272
17 :  306
18 :  342
19 :  380
20 :  420
21 :  462
22 :  506
23 :  552
24 :  600
25 :  650


Where he got 675 was from iteration ebx = 25, ebx += sum (650), ebx = 675
It could be a random act of randomness. Those happen a lot as well.

jwill22

Sorry for being so late...but thanks you all..You really helped me out :dance: :dance: :dance: