upsidedown

regregh

Feb 24th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. include io.h
  2.  
  3. cr equ 0dh
  4. lf equ 0ah
  5.  
  6. data segment
  7. prompt     db'enter the number of elements:',0
  8. number     db 8 dup(?)
  9. num        db 8 dup(?)
  10. num1       dw ?
  11. num2       dw ?
  12. num_elem   dw ?
  13. num_prompt db cr,lf,'enter the numbers',0
  14. number_arr dw 100 dup(?)
  15. elem       db 8 dup(?)
  16. msg1       db cr,lf,'the array entered is:',cr,lf,0
  17. msg2       db cr,lf,'the number of even numbers is:'
  18. elem1      db 8 dup(?)
  19. msg3       db cr,lf,'the number of odd number is:'
  20. elem2      db 8 dup(?)
  21. data ends
  22.  
  23.  
  24. code segment
  25. assume cs:code,ds:data
  26. start: mov ax,seg data
  27.        mov ds,ax
  28.  
  29.        output prompt
  30.        inputs number,8
  31.        atoi number
  32.        cmp ax,0
  33.        jg continue
  34.        jmp quit
  35.  
  36. continue:mov num_elem,ax
  37.     mov si,0000h
  38.     mov bx,num_elem
  39.     output num_prompt
  40.  
  41. while: inputs num,8
  42.         atoi num
  43.         mov number_arr[si],ax
  44.         add si,2
  45.         dec bx
  46.         cmp bx,0
  47.         jg while
  48.  
  49. end_while:
  50.         mov cx,num_elem
  51.         output msg1
  52.         mov si,0000h
  53. for1:   itoa elem,number_arr[si]
  54.         output elem
  55.         add si,2
  56.         loop for1
  57.     mov cx,num_elem
  58.         mov si,0000h
  59.         mov bx,2
  60.  
  61. for2:   mov ax,number_arr[si]
  62.         cwd
  63.         idiv bx
  64.         cmp dx,0
  65.         jne down2
  66.         inc num1
  67.         add si,2
  68.         loop for2
  69.         jmp down3
  70.  
  71. down2:  inc num2
  72.         add si,2
  73.         loop for2
  74.  
  75. down3:  mov ax,num1
  76.     itoa elem1,ax
  77.     output msg2
  78.  
  79.     mov bx,num2
  80.     itoa elem2,bx
  81.     output msg3
  82.  
  83. quit: mov al,0
  84.        mov ah,4ch
  85.        int 21h
  86.  
  87. code ends
  88.  
  89.      end start
  90.  
  91.  
  92.  
  93. enter the number of elements:5
  94.  
  95. enter the numbers12
  96. 15
  97. 13
  98. 14
  99. 11
  100.  
  101. the array entered is:
  102.     12    15    13    14    11
  103. the number of even numbers is:     2
  104. the number of odd number is:     3
Advertisement
Add Comment
Please, Sign In to add comment