Advertisement
Sanchi285

Assignment on assembly_array

Sep 15th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. org 100h
  3.  
  4. .DATA
  5.    arr dw 1,2,3,4,5,6,7,8
  6.    n   dw 8  ;the size of array
  7.    n1  dw 4  ;first half of the array index
  8.    t_sum dw 0  
  9.    
  10.  .code
  11.     proc main
  12.     mov cx,n
  13.     mov dx,0
  14.     mov si,0
  15.    
  16.     ;push array element into the stack
  17.     st:
  18.     mov ah,2
  19.     mov dx,arr[si]
  20.     add dx,48
  21.     push dx
  22.     add si,2
  23.     loop st                  
  24.     call rev_show ;call the reverse proc
  25.     call sum      ;call the sum proc
  26.     call mult     ;call mult proc
  27.     endp
  28.    
  29.    
  30.    
  31.    
  32.      
  33.     ;show the array element in to reverse order
  34.     proc rev_show
  35.         mov si,0
  36.         mov cx,n
  37.         add sp,2        
  38.         revst:
  39.         pop bx
  40.         mov arr[si],bx
  41.         mov dx,arr[si]
  42.         int 21h
  43.         mov dx,' '
  44.         int 21h
  45.         sub arr[si],48
  46.         add si,2
  47.         loop revst
  48.      endp rev_show
  49.    
  50.    
  51.     ;sum proc
  52.     proc sum
  53.       mov si,0
  54.       mov cx,n1
  55.       mov ax,0
  56.       sum_up:
  57.       add ax,arr[si]
  58.       add si,2        
  59.       loop sum_up
  60.       mov t_sum,ax ;store the value of ax in a t_sum      
  61.     endp sum
  62.    
  63.    
  64.    ;mult proc
  65.    proc mult      
  66.        mov cx,n1
  67.        mov ax,1
  68.        mul_up:
  69.        mul arr[si]
  70.        add si,2
  71.        loop mul_up:
  72.    endp mult
  73.    
  74.    ;move in to the register
  75.    mov bx,ax
  76.    mov ax,t_sum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement