Search code examples
loopsassemblycountcontinuoushla

HLA High Level Assembly Continuous Loop


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?


Solution

  • 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: