0% found this document useful (0 votes)
42 views2 pages

Even or Odd

The document contains assembly code that prints whether numbers from 1 to 25 are even or odd. It uses loops and conditionals to check each number and output the corresponding message.

Uploaded by

Janhvi Bhangale
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)
42 views2 pages

Even or Odd

The document contains assembly code that prints whether numbers from 1 to 25 are even or odd. It uses loops and conditionals to check each number and output the corresponding message.

Uploaded by

Janhvi Bhangale
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/ 2

ANUSHKA SHRIVASTAVA, 2907, C22019881907

MINI PROJECT PROBLEM STATEMENT :- PRINT IF THE NUMBER IS EVEN OR ODD FROM 1-25.
---------------------------------------------------------------------------------------------------------------------------------------------------------
CODE:

%macro write 2 ;macro for write


mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

section .data
even_msg db ' is an Even Number!',13,10
len1 equ $ - even_msg
odd_msg db ' is an Odd Number!',13,10
len2 equ $ - odd_msg
cur db 0

section .bss
num resb 5 ;Reserved 5 Bytes for Input

section .text

global _start ;must be declared for linker (gcc)

_start:

xor ch,ch
xor cx,cx
inc cx
loop1:

push cx

mov ax,cx
MOV AH,0
mov bl,0x0A
div bl

mov cx,ax
mov cl,ch
mov ch,0
push cx

mov ah,0
mov bl,0x0A
div bl
mov cx,ax
mov cl,ch
mov ch,0
push cx

pop cx
add cx, '0'
mov [cur], cx ;
write cur,len2 ;printing the number
pop cx
add cx, '0'
mov [cur], cx ;
write cur,len2
pop cx

push cx

mov ax,cx
inc cx
and ax, 1
jz evnn

;Printing No. is Odd


write odd_msg,len2
pop cx
inc cx
cmp cx,0x1A
je outprog

jmp loop1

;Printing No. is Even


evnn:
write even_msg,len1

pop cx
inc cx

jmp loop1

;Exit
outprog:
mov eax, 1 ;system call number (sys_exit)
int 0x80 ;call kernel

----------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT:

$nasm -f elf *.asm; ld -m elf_i386 -s -o demo *.o


$demo
01 is an Odd Number!
02 is an Even Number!
03 is an Odd Number!
04 is an Even Number!
05 is an Odd Number!
06 is an Even Number!
07 is an Odd Number!
08 is an Even Number!
09 is an Odd Number!
10 is an Even Number!
11 is an Odd Number!
12 is an Even Number!
13 is an Odd Number!
14 is an Even Number!
15 is an Odd Number!
16 is an Even Number!
17 is an Odd Number!
18 is an Even Number!
19 is an Odd Number!
20 is an Even Number!
21 is an Odd Number!
22 is an Even Number!
23 is an Odd Number!
24 is an Even Number!
25 is an Odd Number!

You might also like