A Assembly program to calculate average of numbers in an Array – IGNOU MCA Assignment 2013

By | October 18, 2013

MASTER OF COMPUTER APPLICATIONS
Course Code : MCSL-017
Course Title : C and Assembly Language Programming
Assignment Number : MCA(1)/L017/Assign/2013

 

A program in assembly language to calculate the average of numbers in an array.

 

DATA SEGMENT
     ARRAY DB 1,4,2,3,8,6,7,5,9
     AVG DB ?
     MSG DB "AVERAGE = $"
ENDS

CODE SEGMENT 
    ASSUME DS:DATA CS:CODE
START:
      MOV AX,DATA
      MOV DS,AX

      LEA SI,ARRAY 
      LEA DX,MSG
      MOV AH,9
      INT 21H

      MOV AX,00
      MOV BL,9

      MOV CX,9 
      LOOP1:
           ADD AL,ARRAY[SI]
           INC SI
      LOOP LOOP1

      DIV BL

      ADD AL,30H

      MOV DL,AL
      MOV AH,2
      INT 21H

      MOV AH,4CH
      INT 21H     
ENDS
END START

program code :

  1. DATA SEGMENT
  2. ARRAY DB 1,4,2,3,8,6,7,5,9
  3. AVG DB ?
  4. MSG DB "AVERAGE = $"
  5. ENDS
  6.  
  7. CODE SEGMENT
  8. ASSUME DS:DATA CS:CODE
  9. START:
  10. MOV AX,DATA
  11. MOV DS,AX
  12.  
  13. LEA SI,ARRAY
  14. LEA DX,MSG
  15. MOV AH,9
  16. INT 21H
  17.  
  18. MOV AX,00
  19. MOV BL,9
  20.  
  21. MOV CX,9
  22. LOOP1:
  23. ADD AL,ARRAY[SI]
  24. INC SI
  25. LOOP LOOP1
  26.  
  27. DIV BL
  28.  
  29. ADD AL,30H
  30.  
  31. MOV DL,AL
  32. MOV AH,2
  33. INT 21H
  34.  
  35. MOV AH,4CH
  36. INT 21H
  37. ENDS
  38. END START

Screen shots :-

MCS017_S2_Q1_A

MCS017_S2_Q1_A_Ouput

Leave a Reply