Created
July 31, 2012 17:18
-
-
Save tanayseven/3218660 to your computer and use it in GitHub Desktop.
Count odd and even numbers using rotate in 8086 compatible assembly language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include io.h | |
cr equ 0dh | |
lf equ 0ah | |
stack SEGMENT STACK | |
DW 100h dup(?) | |
stack ends | |
data SEGMENT | |
p_n db cr, lf, 'Enter n: ',0 | |
p_num db cr, lf, 'Enter the array:',cr, lf,0 | |
p_even db cr, lf, 'Even nos: ',0 | |
p_odd db cr, lf, 'Odd nos: ',0 | |
n dw ? | |
evn dw ? | |
odd dw ? | |
two dw ? | |
num dw 100 DUP (?) | |
tmpstr dw 40 DUP (?) | |
data ENDS | |
code SEGMENT | |
ASSUME cs:code,ds:data | |
start: mov ax,SEG data | |
mov ds,ax | |
output p_n ;input n | |
inputs tmpstr, 10 | |
atoi tmpstr | |
mov n, ax | |
mov dx, n ;initilize 4 inp | |
lea bx, num | |
output p_num ;input iterate array | |
nxtinp: inputs tmpstr, 10 | |
atoi tmpstr | |
mov [bx], ax | |
add bx, 02h | |
dec dx | |
jnz nxtinp | |
mov cx, n ;initilize to check | |
mov ax, 0 | |
mov evn, ax | |
mov odd, ax | |
lea bx, num | |
mov two, 02h | |
chknxt: mov ax, [bx] ;iterate to count even and odd | |
rcr ax, 1 | |
jc l_odd | |
l_evn:add evn, 1 | |
jmp nxt | |
l_odd:add odd, 1 | |
nxt:add bx, 02h | |
dec cx | |
jnz chknxt | |
output p_even ;output even | |
mov ax, evn | |
itoa tmpstr, ax | |
output tmpstr | |
output p_odd ;output odd | |
mov ax, odd | |
itoa tmpstr, ax | |
output tmpstr | |
quit: mov al,0 ;quit | |
mov ah,4ch | |
int 21h | |
code ENDS | |
END start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment