Loops/Downward for: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) m (→{{header|8086 Assembly}}: added some clarification) |
||
Line 109: | Line 109: | ||
=={{header|8086 Assembly}}== |
=={{header|8086 Assembly}}== |
||
It is typically much easier for assembly languages to loop downwards than forwards, as they can do so without using a redundant equality check. The 8086's <code>LOOP</code> instruction will loop a section of code, using the <code>CX</code> register as the loop counter. |
|||
<lang asm> .model small ;.exe file, max 128 KB |
<lang asm> .model small ;.exe file, max 128 KB |
||
.stack 1024 ;reserve 1 KB for the stack pointer. |
.stack 1024 ;reserve 1 KB for the stack pointer. |
||
Line 137: | Line 139: | ||
;these 6 lines of code are the "new line" function |
;these 6 lines of code are the "new line" function |
||
pop ax |
pop ax |
||
loop repeat_countdown |
loop repeat_countdown ;decrement CX and jump back to the label "repeat_countdown" if CX != 0 |
||