The MASM Forum Archive 2004 to 2012

Project Support Forums => HLA Forum => Topic started by: TmX on November 07, 2010, 03:16:38 PM

Title: Number triangle
Post by: TmX on November 07, 2010, 03:16:38 PM
This the output I want:
Quote
3
3 4
3 4 5
3 4 5 6
3 4 5 6 7

My code:

program triangle;
#include("stdlib.hhf")

begin triangle;
mov(7, edx);
for (mov (3, ecx); ecx <= edx; inc(ecx)) do
for (mov (ecx, eax); eax <= ecx; inc(eax)) do
stdout.put((type uns32 eax)," ");
endfor;
stdout.put(nl);
endfor;
end triangle;


The output is:
Quote
3
4
5
6
7

Hmm what is wrong here?
Quote
Title: Re: Number triangle
Post by: Emil_halim on November 07, 2010, 04:50:29 PM

note well , the second for-endfor loop will always execute only one time.

here is the correct code

program triangle;
#include("stdlib.hhf")

begin triangle;
mov(7, edx);
for (mov (3, ecx); ecx <= edx; inc(ecx)) do
for (mov (3, eax); eax <= ecx; inc(eax)) do
stdout.put((type uns32 eax)," ");
endfor;
stdout.put(nl);
endfor;
end triangle;


Title: Re: Number triangle
Post by: TmX on November 08, 2010, 06:30:14 AM
Ah, I didn't notice that.  :red

Thanks!