Advertisement
alvsjo

suma niza

Jun 8th, 2017
113
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 ax,0
  16.     mov bx,0
  17.     mov sum,0
  18.     suma:
  19.     cmp bx, length niz
  20.     je done
  21.     shl bx,1
  22.     mov cx, niz[bx]
  23.     add ax,cx
  24.     shr bx,1
  25.     inc bx
  26.     jmp  suma
  27.    
  28.    
  29.    
  30.    
  31.    
  32.    
  33.    
  34.    
  35.    
  36.    
  37.    
  38.    
  39.    
  40.    
  41.    
  42.    
  43.     done:
  44.    
  45.     mov sum, ax
  46.     cmp ax,0
  47.     je nula
  48.    
  49.     cmp ax, 0
  50.     jg dalje
  51.    
  52.     negativ:
  53.     mov dx, '-'
  54.    mov ah,2
  55.    int 21h
  56.    
  57.  
  58.   mov ax, niz[bx]
  59.   neg ax
  60.  
  61. dalje:
  62.   mov cx,0
  63.     mov bx, 10
  64.  
  65.    
  66.     cifre:
  67.     cmp ax,0
  68.     jng stampa
  69.     mov dx,0
  70.     div bx
  71.     push dx
  72.     inc cx
  73.     jmp cifre
  74.    
  75.     stampa:
  76.    cmp cx,0
  77.    jng kraj1
  78.    pop dx
  79.    add dx, '0'
  80.    mov ah,2
  81.    int 21h
  82.    dec cx
  83.    jmp stampa
  84.  
  85.   nula:
  86.      mov dx, '0'
  87.    mov ah,2
  88.    int 21h
  89.    
  90.  
  91. kraj1:
  92.    
  93.    
  94.    
  95.      mov ah,4ch
  96.     int 21h
  97. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement