;********************** Clear Function *************************
clear macro
mov ah,6h
mov al,50
mov ch,0
mov cl,0
mov dh,24
mov dl,79
mov bh,80h
int 10h
endm
;********************** Xy Function ****************************
xy macro row,col
mov ah,2h
mov dh,row
mov dl,col
mov bh, 0
int 10h
endm
;****************** Print string Function **********************
print macro buff
lea dx,buff
mov ah,9h
int 21h
endm
;**************** Print List of Students Struct ****************
printls macro sta
print sta.nam
print space
print sta.num
print newline
endm
;*********************** Read Function *************************
read macro max
mov ah,10
lea dx,max
int 21h
endm
;************************* Read Struct *************************
reads macro maxn,maxm
read maxn
print newline
read maxm
print newline
print msg1
endm
;******************* Read Struct And Replace *******************
readsr macro maxn,maxm,lenn,lenm,numm,name,stu
local up_1,up_2
reads maxn,maxm
mov bl,0
up_1: mov bh,0
mov dh,0
mov dl,name[bx]
mov stu.nam[bx],dl
inc bl
cmp bl,lenn
jb up_1
mov bl,0
up_2: mov bh,0
mov ch,0
mov cl,numm[bx]
mov stu.num[bx],cl
inc bl
cmp bl,lenm
jb up_2
endm
;************************* Compare st1,st2 *********************
compare macro st1,st2
local up_1,up_2,up_3,up_4,up_5,up_6,up_7
mov counts1,0
mov counts2,0
mov bl,0
up_4: mov bh,0
cmp st1.num[bx],0
je up_6
inc counts1
up_6: inc bl
cmp bl,4
jne up_4
mov bl,0
up_5: mov bh,0
cmp st2.num[bx],0
je up_7
inc counts2
up_7: inc bl
cmp bl,4
jne up_5
mov flag,0
comp st1.num,st2.num,counts1,counts2
add flag,30h
cmp flag,'1'
je up_2
jne up_1
up_1: jmp up_3
up_2: change st1,st2
up_3: endm
;************************* Comp Function ************************
Comp macro num1,num2,len1,len2
local up_1,up_2,up_3
mov bl,len1
mov bh,0
mov cl,len2
mov ch,0
cmp bl,cl
ja up_2
jb up_3
mov bl,0
up_1: mov bh,0
mov dl,num1[bx]
sub dl,30h
mov dh,num2[bx]
sub dh,30h
cmp dl,dh
ja up_2
jb up_3
inc bl
cmp bl,len1
jb up_1
up_2: mov flag,1
up_3: endm
;*********************** Sum marks Function *********************
summs macro stun
local up_1,up_2,up_3,up_4,up_5,up_6,up_7,up_8
mov cdigit,0
mov bl,0
up_5: mov bh,0
cmp stun.num[bx],0
je up_4
inc cdigit
up_4: inc bl
cmp bl,4
jne up_5
mov maxa,3
up_6: mov bl,maxa
mov bh,0
push bx
mov bx,cdigit
mov ah,0
mov al,stun.num[bx-1]
pop bx
mov strnum[bx],al
dec maxa
dec cdigit
cmp cdigit,0
ja up_6
mov cx,0
mov dl,maxa
mov dh,0
mov cx,cdigit
sub dx,cx
mov bx,0
up_7: mov strnum[bx],'0'
inc bx
cmp bx,dx
jbe up_7
mov lenn,4
mov maxa,3
mov maxb,3
mov maxc,3
mov dx,0
push dx
up_1: mov bh,0
mov bl,maxb
mov ah,0
mov al,summ[bx]
push ax
dec maxb
mov bh,0
mov bl,maxa
mov bh,0
mov bl,strnum[bx]
push bx
dec maxa
pop bx
pop ax
sub al,30h
sub bl,30h
add ax,bx
pop dx
add ax,dx
mov cl,10
div cl
mov dh,0
mov dl,al
push dx
or ax,3030h
mov bl,maxc
mov bh,0
mov summ[bx],ah
dec maxc
dec lenn
cmp lenn,1
jne up_2
je up_3
up_2: jmp up_1
up_3: pop dx
or dx,3030h
mov bl,maxc
mov bh,0
cmp dx,0
jbe up_8
mov summ[bx],dl
up_8: endm
;************************* Change struct ************************
change macro sta,stb
local up_1,up_2
mov bl,4
up_1: mov bh,0
mov ch,sta.num[bx]
mov cl,stb.num[bx]
mov sta.num[bx],cl
mov cl,ch
mov ch,0
mov stb.num[bx],cl
dec bl
cmp bl,0
jge up_1
mov bl,20
up_2: mov bh,0
mov ch,sta.nam[bx]
mov cl,stb.nam[bx]
mov sta.nam[bx],cl
mov cl,ch
mov ch,0
mov stb.nam[bx],cl
dec bl
cmp bl,0
jge up_2
endm
;************************* Avrage Function **********************
avragem macro summ
local up_1,up_2,up_3
mov ax,0
lea bx,summ
mov cx,4
mov si,10
up_1: mul si
mov dl,[bx]
and dl,15
xor dh,dh
add ax,dx
inc bx
loop up_1
mov bh,0
mov bl,12
div bl
mov si,2
up_2: mov bl,10
mov ah,0
div bl
add ah,30h
mov avrage[si],ah
dec si
cmp al,0
jne up_2
je up_3
up_3: endm
;****************************************************************
.model small
stu struc
nam db 20 dup(?),'$'
num db 4 dup(?),'$'
stu ends
.Data
msg1 db 'Please Enter your name & your mark :',10,13,"$"
msg2 db ' Total of Marks = ',"$"
msg3 db ' Avrage of Marks = ',"$"
msg4 db 'Name Mark',"$"
msg5 db '===============================',"$"
newline db 10,13,'$'
space db ' ',"$"
max1 db 20
len1 db ?
name1 db 20 dup(?)
max11 db 4
len11 db ?
num1 db 4 dup(?)
st1 stu <>
d1 db '$'
st2 stu <>
d2 db '$'
st3 stu <>
d3 db '$'
st4 stu <>
d4 db '$'
st5 stu <>
d5 db '$'
st6 stu <>
d6 db '$'
st7 stu <>
d7 db '$'
st8 stu <>
d8 db '$'
st9 stu <>
d9 db '$'
st10 stu <>
d10 db '$'
st11 stu <>
d11 db '$'
st12 stu <>
d12 db '$'
count db ?
summ db 4 dup('0'),'$'
avrage db 3 dup('0'),'$'
flag db ?,'$'
counts1 db ?
counts2 db ?
cdigit dw 0,'$'
strnum db 4 dup('0')
lenn db ?
maxa db ?
maxc db ?
maxb db ?
;*****************************************************************
.code
main proc
mov ax,@data
mov ds,ax
clear
xy 0,0
print msg1
readsr max1,max11,len1,len11,num1,name1,st1
readsr max1,max11,len1,len11,num1,name1,st2
readsr max1,max11,len1,len11,num1,name1,st3
readsr max1,max11,len1,len11,num1,name1,st4
readsr max1,max11,len1,len11,num1,name1,st5
readsr max1,max11,len1,len11,num1,name1,st6
readsr max1,max11,len1,len11,num1,name1,st7
readsr max1,max11,len1,len11,num1,name1,st8
readsr max1,max11,len1,len11,num1,name1,st9
readsr max1,max11,len1,len11,num1,name1,st10
readsr max1,max11,len1,len11,num1,name1,st11
readsr max1,max11,len1,len11,num1,name1,st12
mov count,0
up_1: compare st1,st2
compare st2,st3
compare st3,st4
compare st4,st5
compare st5,st6
compare st6,st7
compare st7,st8
compare st8,st9
compare st9,st10
compare st10,st11
compare st11,st12
inc count
cmp count,12
je up_3
jne up_2
up_2: jmp up_1
up_3: clear
xy 0,0
print msg4
print newline
print msg5
print newline
printls st12
printls st11
printls st10
printls st9
printls st8
printls st7
printls st6
printls st5
printls st4
printls st3
printls st2
printls st1
summs st1
summs st2
summs st3
summs st4
summs st5
summs st6
summs st7
summs st8
summs st9
summs st10
summs st11
summs st12
print newline
print msg2
print summ
avragem summ
print newline
print msg3
print avrage
print newline
mov ax,4c00h
int 21h
main endp
end main