0

I am currently working on an assembly assignment for school, where I need to declare a 10 element array, initialize the array with the successive squares of the integers from 1 to 10 and then calculate the average of those values and store them into a variable. However, when I go to retrieve the first value from memory for calculating the average instead of returning 0001 as expected it returns 0401 in the AX register which is way higher than it should be. Would someone be able to look over my code quickly and point out what I am doing wrong? Code down below, thanks:

        .model small
        .stack  32 
        .data

arr DW 10 DUP(0)
RES DW ?

        .code 
MAIN    proc FAR
    MOV AX, @data 
    MOV DS, AX 

    CALL INIT
    CALL AVG

    MOV RES, AX
    MOV AX, 4C00H

    INT 21H

MAIN endp


INIT proc NEAR 
    MOV CX, 10
    LEA BX, arr
    MOV SI, 1 
    

    A: MOV AX, SI 
           MUL SI 
           MOV [BX], AX 
           INC SI 
           INC BX
           LOOP A 
    RET
INIT endp

AVG proc NEAR 
    MOV CX, 10 
    LEA BX, arr
    MOV AX,0
    MOV DX,10 
    
    B: ADD AX, [BX]
           INC BX  
    LOOP B 
    
    DIV DX 
      RET

AVG endp
           
    end MAIN

0 Answers0