Write a complete assembly program to read 8 digits, each digit separated by a single space from the keyboard (use single key input function). Convert them from character to numbers and calculate the average, lowest and highest score and display them on the screen.
Hint: Subtract
30h
from each character to get actual digit. Before display, add30h
to each digit. For division operation, use appropriate shift instruction.
Average is showing the wrong answer! Where did I do wrong? Plz help me understand division by SRH instruction.
Include emu8086.inc
.model small
.stack 100h
.data
.code
mov bh,0
mov bl,9
mov ah,1
mov dh,0
mov cx,0
input:
int 21H
putc 20h
sub al,30h
inc cx
add dh,al
cmp al,bh
JA _max
cmp al,bl
JB _min
cmp cx,8
JB input
print:
mov ah,2
printn
mov dl,bh
add dl,30h
printn "Max: "
int 21h
printn
mov dl,bl
add dl,30h
printn "Min: "
int 21h
AND dh, 0FH
mov Cl,3
shr dh,cl
or dh,30H
printn
mov dl,dh
printn "Avg: "
int 21h
exit:
mov ah,4ch
int 21h
_max:
mov bh,al
cmp al,bl
JB _min
cmp cx,8
jae print
jb input
_min:
mov bl,al
cmp cx,10
jae print
jb input