0

The problem wants to loop through a decimal from input until the only number left is one. However, once first loop reaches 0 it should beging looping again from first digit minus 1 like this,

Input decimal for loop: 4
Your loop result is: 4321 321 21 1

Or,

Input decimal for loop: 6
Your loop result is: 654321 54321 4321 321 21 1

I now have,

DoWhileLoop:
DoWhileBody:
    stdout.put( " I => ", I );
    dec( I );
DoWhileTermination:
    cmp( I, 0 );
    jng DoWhileLoopDone;
    jmp DoWhileLoopBody;
DoWhileLoopDone:  

Which prints if input is 4,

I => 4 I => 3 I => 2 I => 1

I've tried a nested for loop inside to get the continuity needed but I do not know how to increment it without crashing my computer...help?

  • You'll definitely need nested loops. The outer loop should decrement your counter and your inner loop should use a temp counter to count from the outer counter value down to one. Pseudo-code: while (co > 0) ci = co; while (ci > 0) output c1; c1--; endwhile output space; co--; endwhile. – 500 - Internal Server Error Mar 29 '13 at 22:11
  • Thanks, what I needed was the sense on how to pass values between variables and get used to the "nested" loops syntax in assembly. –  Mar 30 '13 at 01:45

1 Answers1

2

Solved. I needed an inner loop and a second variable (J) to transfer this value to. Like this ( dummy code ),

myWhileLoop:
myWhileLoopTermination:
    cmp( Y, 0 );
    jng WhileLoopDone;
myWhileLoopBody:

// Inner for loop goes in the body

    innerForLoop:
    InitializeinnerForLoop:        
    // Passing value of Y to Z
        mov( Y, Z );
    innerForLoopTerminationTest:
        cmp( Z, 0 );
        jng innerForLoopDone;
    innerForLoopBody:
        stdout.put( Z );
    innerForLoopDecrement:
        dec( Z );
        jmp innerForLoopTerminationTest;
    innerForLoopDone:

    dec( Y );
    jmp myWhileLoop;
myWhileLoopDone: