Assembly Language Lab report even or odd
Experiment No:
Experiment Name: Flow control if else (An assembly program that can take as input and print as an output find the number is even or odd).
Objectives: To be able to print the number is even or odd.
Apparatus: MICROPROCESSOR EMULATOR 8086, Computer etc
Introduction: Conditions in assembly language control the execution of loops and branches. The program evaluates the conditional instruction and executes certain instructions based on the evaluation. The CMP and JMP instructions implement conditional instructions.
- Compare and jump instructions
The CMP instruction takes two operands and subtracts one from the other, then sets O, S, Z, A, P, and C flags accordingly. CMP discards the result of subtraction and leaves the operands unaffected. The following syntax is used for CMP instructions: CMP DST SRC
The JMP instruction transfers the program control to a new set of instructions indicated by the label in the instruction. The following syntax is used for JMP instructions: JMP label
Procedure:
1. Create: open emu8086 write a program after that save the program with .asm extension.
2. Compile: Emulator
3. Execute: Run
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 |
newline macro
lea dx,nl
mov ah,9
int 21h
endm
.model small
.stack 100h
.data
msg1 db 'number is even', '$'
msg2 db 'number is odd', '$'
nl db 0dh,0ah, '$'
.code
.startup
mov ax,@data
mov ds,ax
mov ah,1
int 21h
mov bl,2
div bl
mov al,ah
cmp al,0
jg odd
even:
newline
lea dx,msg1
mov ah,9
int 21h
jmp exit
odd:
newline
lea dx,msg2
mov ah,9
int 21h
exit:
.exit |
Result:
Conclusion: The program code of taking input a number and printing it even or odd successfully.
Tags:
write a program in assembly language to check whether a number is even or odd, write a program to check whether the given number is even or odd, write a program to find whether the given number is even or odd using if else statement, write a program to check whether the given number is even or odd in assembly, write a program to check whether the given number is even or odd in assembly, write a program to check whether the given number is even or odd in assembly, print even numbers in assembly language, even odd program in al using for loop