.model small
.data
array db 5 dup(00)
m1 db 10,13, "Enter 5 Subject Marks $"
sum dw 0000h ;sum variable 00 (16Bit)
m2 db 10,13, "Failed $"
m3 db 10,13, "C Grade $"
m4 db 10,13, "B Grade $"
m5 db 10,13, "A Grade $"
.code
mov ax,@data ; Initialize the data seg address
mov ds,ax
mov ah,09h
lea dx,m1 ; Display message
int 21h
mov ch, 05 ; set Counter
mov si, offset array ;pointing memory location to store
X3:
call accept ; PC pushes address of next instr on top of the stack
mov [si], bl ; transfer data to that location pointed by si
mov bh, 00h
add sum, bx
;add bl, [si]
inc si
dec ch
JNZ X3 ; unless ZF is not set jump to accept proc
mov ax, sum ;Divident Must be in a AX reg
mov bl, 05h ;5 subject marks thats why we wrote 5
div bl
;remainder = ah quotient = al
cmp al, 40h
JBE N1 ;Jump if BELOW or EQUAL
cmp al, 60h
JBE N2
cmp al, 80h
JBE N3
cmp al, 90h
JBE N4
N1:
mov ah, 09h
lea dx, m2
int 21h
jmp exit
N2:
mov ah, 09h
lea dx, m3
int 21h
jmp exit
N3:
mov ah, 09h
lea dx, m1
int 21h
jmp exit
N4:
mov ah, 09h
lea dx, m5
int 21h
jmp exit
exit:
mov ah,4ch
int 21h
accept proc near
mov ah,01h ; ascii code goes in to AL(0 to F)
int 21h
mov bl, al ; make free al
sub bl, 30h ; seperate the accepted no forms ascii code
cmp bl, 09h ; if single digit is >9 then need to sub 07h
JLE X1 ; bl=5 bl=50 bl=50+8 = 58
sub bl,07h ;bh = 8
X1:
mov cl, 04h ; create tens place value for 2 digit no
SHL bl,cl
mov ah,01h ; second no.accept (0-F) unit value
int 21h
mov bh, al
sub bh,30h
cmp bh,09h
JLE X2
sub bh, 07h
X2:
add bl, bh ; two digit no is created
ret ;pop the next instruction address from the stack
endp
end