Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include io.h
- cr equ 0dh
- lf equ 0ah
- data segment
- prompt1 db 'enter the number of elements',0
- prompt2 db cr,lf, 'Enter elements ',0
- x dw 40 dup(?)
- string dw 40 dup(?)
- prompt3 db cr,lf,'The sum of even numbers is '
- esum dw 2 dup(?)
- db cr ,lf,0
- prompt4 db cr,lf,'The sum of odd numbers is '
- osum dw 2 dup (?)
- db cr ,lf,0
- sum1 dw ?
- count dw ?
- sum2 dw ?
- two db 02h
- data ends
- code segment
- assume cs:code, ds:data
- start: mov ax, seg data
- mov ds, ax
- mov si, offset x
- output prompt1
- inputs string, 40
- atoi string
- mov count,ax
- mov dx, ax
- output prompt2
- repet: inputs string,40
- atoi string
- mov [si], ax
- add si,2
- dec dx
- jnz repet
- mov si, offset x
- mov bx, count
- mov sum1,00 ;even counter
- mov sum2,00 ; odd counter
- again: mov ax,[si]
- ;cwd
- and ax,01
- cmp ax,00
- jz a
- b: mov dx, [si]
- add sum1,dx
- inc si
- inc si
- dec bx
- jnz again
- jz last
- a: MOV DX, [SI]
- add sum2,dx
- inc si
- inc si
- dec bx
- jnz again
- jz last
- last:
- mov bx, sum1
- mov dx, sum2
- itoa esum, bx
- itoa osum, dx
- output prompt3
- output prompt4
- mov al,00
- int 21h
- code ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment