upsidedown

knlnkldnklnasjkfbASDFUuawebfjkbuiwheqfionjegj

Feb 24th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. include io.h
  2. cr equ 0dh
  3. lf equ 0ah
  4.  
  5. data segment
  6. prompt1 db 'enter the number of elements',0
  7. prompt2 db cr,lf, 'Enter elements ',0
  8.  
  9. x dw 40 dup(?)
  10.  
  11.  
  12. string dw 40 dup(?)
  13.  
  14. prompt3 db cr,lf,'The sum of even numbers is '
  15. esum dw 2 dup(?)
  16.     db cr ,lf,0
  17.  
  18. prompt4 db cr,lf,'The sum of odd numbers is '
  19. osum dw 2 dup (?)
  20.     db cr ,lf,0
  21.    
  22.    
  23.    
  24. sum1 dw ?
  25. count dw ?
  26. sum2 dw ?
  27. two db 02h
  28.  
  29. data ends
  30.  
  31.  
  32.         code segment
  33.         assume cs:code, ds:data
  34. start:  mov ax, seg data
  35.         mov ds, ax
  36.        
  37.         mov si, offset x
  38.         output prompt1
  39.         inputs string, 40
  40.         atoi string
  41.         mov count,ax
  42.         mov dx, ax
  43.         output prompt2
  44.        
  45. repet:  inputs string,40
  46.         atoi string
  47.         mov [si], ax
  48.         add si,2
  49.         dec dx
  50.         jnz repet
  51.        
  52.        
  53.         mov si, offset x
  54.         mov bx, count
  55.         mov sum1,00 ;even counter
  56.         mov sum2,00 ; odd counter
  57.        
  58. again:  mov ax,[si]
  59.         ;cwd
  60.        
  61.        
  62.         and ax,01      
  63.         cmp ax,00
  64.         jz a
  65.        
  66. b:      mov dx, [si]
  67.         add sum1,dx
  68.         inc si
  69.         inc si
  70.         dec bx
  71.         jnz again
  72.         jz last
  73. a:      MOV DX, [SI]
  74.         add sum2,dx
  75.         inc si
  76.         inc si
  77.         dec bx
  78.         jnz again
  79.         jz last
  80.  
  81. last:  
  82.         mov bx, sum1
  83.         mov dx, sum2
  84.         itoa esum, bx
  85.        itoa osum, dx
  86.        output prompt3
  87.        output prompt4    
  88.         mov al,00
  89.         int 21h
  90.         code ends
  91.     end start
Advertisement
Add Comment
Please, Sign In to add comment