Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo loops nested inside another loop in x86 assembly
    primarykey
    data
    text
    <p>I've got a problem looping in assembly language.</p> <p>When we want to use the counter register for looping in nested loop, what we first do is move the value of counter register into the stack for outer loop and then fetch it back when we're done with the inner loop, this way we're capable of using one counter register for looping into the nested loop with different number of iteration on each loop.</p> <p>But what about nested loop inside a nested loop?</p> <p>I want to print a pyramid made of of the character <code>S</code>. What I am getting is,</p> <pre><code>SSSSSSSSSS SSSSSSSSS SSSSSSSS SSSSSSS SSSSSS SSSSS SSSS SSS SS S </code></pre> <p>What I actually want is,</p> <pre><code> SSSSSSSSSS SSSSSSSS SSSSSS SSSS SS S </code></pre> <p>Here is my code for the program</p> <pre><code>MOV BX,10 ; HOLD 10 IN BX FOR INNER LOOP MOV AX,0 ; START ITERATIONS FROM 0 MOV CX,10 ; MAX NUMBER OF ITERATIONS L2: PUSH CX ;PUSH CX IN A STACK MOV CX,BX ;STORE NEW VALUE IN CX FOR INNER LOOP ITERATION L1: MOV DX, [SI] ; MOVE THE STRING INTO DX MOV AH,02H ; DISPLAY EVERYTHING FROM DX INT 21H LOOP L1 MOV DX,0AH ;PRINT LINE FEED AFTER PRINTING EACH LINE OF ASTERIKS MOV AH,02H INT 21H SUB BX,01 ;DECREASE THE VALUE OF BX BY 1 POP CX ;RESTORE ORIGINAL VALUE OF CX FOR OUTER LOOP ADD AX,01 ;INCREMENT VALUE OF AX BY 1 LOOP L2 MOV AH, 4CH ;RETURN CONTROL TO DOS INT 21H </code></pre> <p>In order to achieve what I want, i need to add another loop inside the nested loop that prints space characters (i.e 020H). But for this I need another counter register and I am not able to do it. How can I solve this problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload