Advertisement
alvsjo

suma parnih iz niza

Jun 8th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small
  2. .stack
  3. .data
  4. niz dw 9 dup (45,0,-2,95,91,-36,14,-15,108)
  5. sum dw ?
  6.  
  7.  
  8. .code
  9.  
  10. main:
  11.  
  12.      mov ax,@data
  13.     mov ds, ax
  14.  
  15.     mov dx,0
  16.     mov bx,0
  17.     mov sum,0
  18.     mov cx,2
  19.    
  20.    
  21.     suma:
  22.     cmp bx, length niz
  23.     je done
  24.  
  25.     shl bx,1
  26.     mov ax, niz[bx]
  27.    
  28.     mov dx,0
  29.     div cx
  30.     cmp dx,0
  31.     jne d1
  32.     mov ax, niz[bx]
  33.     add ax,sum
  34.     mov sum,ax
  35.    
  36.    
  37.     d1:
  38.    
  39.     shr bx,1
  40.     inc bx
  41.     jmp  suma
  42.    
  43.    
  44.    
  45.    
  46.    
  47.    
  48.    
  49.    
  50.    
  51.    
  52.    
  53.    
  54.    
  55.    
  56.    
  57.    
  58.     done:
  59.    
  60.  
  61.     mov ax,sum
  62.     cmp ax,0
  63.     je nula
  64.    
  65.     cmp ax, 0
  66.     jg dalje
  67.    
  68.     negativ:
  69.     mov dx, '-'
  70.    mov ah,2
  71.    int 21h
  72.    
  73.  
  74.   mov ax, niz[bx]
  75.   neg ax
  76.  
  77. dalje:
  78.   mov cx,0
  79.     mov bx, 10
  80.  
  81.    
  82.     cifre:
  83.     cmp ax,0
  84.     jng stampa
  85.     mov dx,0
  86.     div bx
  87.     push dx
  88.     inc cx
  89.     jmp cifre
  90.    
  91.     stampa:
  92.    cmp cx,0
  93.    jng kraj1
  94.    pop dx
  95.    add dx, '0'
  96.    mov ah,2
  97.    int 21h
  98.    dec cx
  99.    jmp stampa
  100.  
  101.   nula:
  102.      mov dx, '0'
  103.    mov ah,2
  104.    int 21h
  105.    
  106.  
  107. kraj1:
  108.    
  109.    
  110.    
  111.      mov ah,4ch
  112.     int 21h
  113. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement