0% found this document useful (0 votes)
49 views5 pages

5 Aa

The document discusses implementing loops in assembly language. It provides an example of using a MOV instruction to set a loop counter, decrementing the counter with DEC, and conditionally jumping back to the start with JNZ. This implements a basic for loop. Code samples are given to print "Hello World" 10 times and print 10 rows of 10 stars each using nested loops. The lab task code prints a triangle pattern using nested loops that decrement counters CX and BX to control row and column printing.

Uploaded by

zibran Hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views5 pages

5 Aa

The document discusses implementing loops in assembly language. It provides an example of using a MOV instruction to set a loop counter, decrementing the counter with DEC, and conditionally jumping back to the start with JNZ. This implements a basic for loop. Code samples are given to print "Hello World" 10 times and print 10 rows of 10 stars each using nested loops. The lab task code prints a triangle pattern using nested loops that decrement counters CX and BX to control row and column printing.

Uploaded by

zibran Hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment No:05

Experiment Name: Loops in Assembly Language.

Requirements:
⦁ PC/Laptop
⦁ EMU8086 software
Objectives:
⦁ To familiar with the basic syntax of assembly language.
⦁ To learn how to implement and execute assembly code in
EMU8086.
Theory:
In assembly language, a loop is typically implemented using a conditional jump
instruction. Here is a basic example of how to implement a loop in emu8086:
MOV CX, 10 ; Set the loop counter to 10
LOOP_START:
; Loop body goes here
DEC CX ; Decrement the loop counter
JNZ LOOP_START ; Jump back to LOOP_START if the counter is not zero
This code initializes the loop counter (CX) to 10, and then jumps to a label called
LOOP_START. The loop body can be any sequence of instructions that you want
to repeat multiple times. After the loop body is executed, the code decrements the
loop counter using the DEC instruction, and then checks whether the counter is
zero using the JNZ instruction. If the counter is not zero, the code jumps back to
the beginning of the loop (at LOOP_START), and the loop body is executed again.
Note that the choice of register to use for the loop counter (CX in this example)
can vary depending on your specific needs. Additionally, there are other variations
of loop constructs in assembly language, such as using a LOOP instruction instead
of the DEC/JNZ combination shown here.

Code:
include 'emu8086.inc'
.model samll
.stack 100h
.data
.code
main proc
mov cx ,10
start:
print 'Hello World'
mov ah,2
mov dl,10

1
int 21h
mov dl,13
int 21h
loop start
exit:
mov ah,4ch
int 21h
main endp
end main

Code for printing 10*10 stars:

.model small
.stack 100h
.data
a db 10,13,'printing star $'
.code
main proc
mov ax, @data
mov ds,ax
mov ah,9
lea dx,a
int 21h
mov ah, 2
mov dl,10
int 21h
mov dl,13
int 21h
mov cx, 10 ;loop cx register e cole
lev:
mov dl,'*'
mov ah,2
int 21h
int 21h
int 21h
int 21h
int 21h
int 21h
int 21h
int 21h
int 21h
2
int 21h
mov ah,2
mov dl,10
int 21h
mov dl,13
int 21h
loop lev
exit:
mov ah,4ch
int 21h
main endp
end main

Lab Task:

.model small
.stack 100h

.data
nl db 0Dh, 0Ah, '$' ; New line character

.code
mov ax, @data
mov ds, ax

mov cx, 4 ; Initialize CX with the number of rows in the triangle

outer_loop:
mov bx, cx ; Initialize BX with the current row number

inner_loop:
mov dl, '*' ; Set DL to the character to be printed
mov ah, 02h ; Function to display character
int 21h ; Print the character in DL

dec bx ; Decrement BX to move to the next column


cmp bx, 0 ; Compare BX with 0
jnz inner_loop ; Jump to inner_loop if BX is not zero

3
lea dx, nl ; Load DX with the address of the new line character
mov ah, 09h ; Function to display string
int 21h ; Print the new line character

dec cx ; Decrement CX to move to the next row


cmp cx, 0 ; Compare CX with 0
jnz outer_loop ; Jump to outer_loop if CX is not zero

mov ah, 4Ch ; Exit program function


int 21h ; Exit program

end

4
Discussion:
In this experiment, we learned about Loops in Assembly Language .After
completing my experiments about loop, i knew that it is a block of
statements that are repeatedly executed until a condition is satisfied.Then i
also knew about connection between JMP instruction to implement loops. In
this process, processor set can use the LOOP instruction to implement loops
conveniently.

You might also like