HCS12 assembly programming please, will rate it after giving right solution.
[20 points] Write a program at $4000 to compute the average (nearest integer) of an array of 20 your answer at location $4500. (Hint: The computed average may be 16 bits long, so set-up a 16 bit location at $4500)
Expert Answer
DATA SEGMENT
ARRAY DB 1,4,2,3,8,6,7,5,9,10,11,12,14,15,16,17,18,19,20
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,20
INT 21H
MOV AX,00
MOV BL,20
MOV CX,20
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