s

8086 assembly language loop instruction edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 10 February 2021 | 7573

a loop instruction is used to loop a group of instructions until the condition satisfies, i.e., CX = 0. To get the loop instruction to work first you have to define a label, set the value in cx which would be the number of times the loop should execute. The LOOP instruction is mainly used to simulate the different loops in HLL. The Loop instructions use the CX register to indicate the loop count. The Loop instruction decrements CX without changing any flags, If CX is not zero after the decrement, control is transferred to the destination label.


Here is the algorithm




CX = CX - 1
if CX <> 0 then
jump to label
else
no jump, continue

8086 assembly language sample code to display a character 10 times.

.model tiny
.code
org 100h

main proc near
    

mov cx,10
loop1:
    mov ah,02h  ; Dos function 02h to Write character to STDOUT
    mov dl,'*'  ; character to write
    int 21h     ; dos interrupt 21h
loop loop1


mov ah,4ch  ; Dos function to terminate the return to dos
mov al,00   ; return code
int 21h     ; dos interrupt 21

endp   
end main

              
                    

Output