I have written the code so far as:
.code
main
Clrscr
mov dh,10 ;row 10
mov dl,20 ;column 20
call Gotoxy ;locate cursor
PromptForIntegers
WriteString ;display string
ReadInt ;input integer
ArraySum
WriteString ;display string
WriteInt ;display integer
DisplaySum ENDP
END main
How do I get it to repeat the same steps three times using a loop, clearing the screen after each loop iteration?
mov cx,3
loopstart:
do stuff
dec cx ;Note: decrementing cx and jumping on result is
jnz loopstart ;much faster on Intel (and possibly AMD as I haven't
;tested in maybe 12 years) rather than using loop loopstart
Yet another method is using the LOOP instruction:
mov cx, 3
myloop:
; Your loop content
loop myloop
The loop instruction automatically decrements cx, and only jumps if cx != 0. There are also LOOPE, and LOOPNE variants, if you want to do some additional check for your loop to break out early.
If you want to modify cx during your loop, make sure to push it onto the stack before the loop content, and pop it off after:
mov cx, 3
myloop:
push cx
; Your loop content
pop cx
loop myloop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With