5 Aa
5 Aa
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
.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
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
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
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.