Monday 23 January 2017

Driver Management System in Assembly Language

Code:

INCLUDE irvine32.inc
.data

login_msg BYTE "Enter password: ",0
system BYTE "                          Driver MANAGEMENT SYSTEM                          ",0

login_error BYTE "Invalid password",0
msg1 BYTE "Enter Contact no :                       ",0
msg2 BYTE "Enter Bus no :                             ",0
msg3 BYTE "Enter Route no :                          ",0
msg4 BYTE "Enter No of students assigned :   ",0
msg5 BYTE "Enter Driver ID :                         ",0


msg6 BYTE "Driver ID  :                    ",0


msg7 BYTE "Contact no :                             ",0
msg8 BYTE "Bus no  :                                  ",0
msg9 BYTE "Route no :                                ",0
msg10 BYTE "No of students assigned :       ",0
msg11 BYTE "Back to menu",0

msg12 BYTE "RECORD NOT FOUND",0
msg13 BYTE "Enter Driver id to be deleted: ",0
msg14 BYTE "RECORD NOT FOUND",0
msg15 BYTE "Enter Driver id for seaching: ",0
msg16 BYTE "RECORD DELETED",0
add_record BYTE    "                           1-ADD Driver Record",0
view_record BYTE   "                          2-VIEW Record",0
delete_record BYTE "                          3-DELETE Record",0
search_record BYTE "                         4-SEARCH Record",0
update_record BYTE "                         5-UPDATE Record",0
exit_msg BYTE      "                            6-EXIT",0

driver_id DWORD 10 DUP(0)
contact_num DWORD 10 DUP(0)
bus_num DWORD 10 DUP(0)
route_num DWORD 10 DUP(0)
stud_num DWORD 10 DUP(0)
count DWORD 0

opt BYTE "Enter Option : ",0
err BYTE "Invalid Input",0
var DWORD 0

.code
main PROC
mov eax,brown+(black*15)
call settextcolor
mov edx,offset system
call writestring
call crlf
call crlf

mov ecx, 3

L1:
mov edx, offset login_msg
call writestring
call crlf
call readint

cmp eax,730
jz menu
jmp eror
eror :
mov edx, offset login_error
call writestring
call crlf

loop L1

cmp eax,730
jmp last
last :
exit

menu:
call clrscr
mov eax,brown+(black*15)
call settextcolor
mov edx,offset system
call writestring
call crlf
call crlf
mov edx,offset add_record
call writestring
call crlf
mov edx,offset view_record
call writestring
call crlf
mov edx,offset delete_record
call writestring
call crlf
mov edx,offset search_record
call writestring
call crlf
mov edx,offset update_record
call writestring
call crlf
mov edx,offset exit_msg
call writestring
call crlf
call crlf
mov edx,offset opt
call writestring
call readint
call crlf
cmp eax,1
jne op2
call addl
jmp menu
op2:
cmp eax,2
jne op3
call viewl
jmp menu
op3:
cmp eax,3
jne op4
call deletel
jmp menu
op4:
cmp eax,4
jne op5
call searchl
jmp menu
op5:
cmp eax,5
jne op6
call updatel
jmp menu
op6:
cmp eax,6
jne invalid
jmp endmenu
invalid:
mov edx,offset err
call writestring
jmp menu
endmenu:
exit
main ENDP
;****************************Add procedure***************************
addl PROC
call clrscr
mov edx,offset system
call writestring
call crlf
mov esi,var
mov edx,offset msg5
call writestring
call readint
mov driver_id[esi],eax
call crlf

next1:
call crlf
mov edx,offset msg1
call writestring
call readint
mov contact_num[esi],eax
cmp eax,0
ja next2          ;jump if above, CF=0 , ZF=0

mov edx,offset err
call writestring

jmp next1
next2:
call crlf
mov edx,offset msg2
call writestring
call readint
mov bus_num[esi],eax
cmp eax,10
jbe next3

jmp errr
errr:
mov edx,offset err
call writestring
jmp next2
next3:
mov edx,offset msg3
call writestring
call readint
mov route_num[esi],eax
cmp eax,20
jbe next4
jmp err2
err2:
mov edx,offset err
call writestring

jmp next3
next4:
mov edx,offset msg4
call writestring
call readint
mov stud_num[esi],eax
cmp eax,80
jbe endf
jmp err3
err3:
mov edx,offset err
call writestring

jmp next4
endf:
add esi,4
mov var,esi
inc count
ret
addl ENDP
;*********************View procedure**********************
viewl PROC

call clrscr
mov edx,offset system
call writestring
call crlf
mov ecx,count
cmp ecx,0
je norec
mov esi,0
rview:
call crlf
mov edx,offset msg6
call writestring
mov eax,driver_id[esi]
call writedec
call crlf

next:
call crlf
mov edx,offset msg7
call writestring
mov eax,contact_num[esi]
call writedec
call crlf
mov edx,offset msg8
call writestring
mov eax,bus_num[esi]
call writedec
call crlf
mov edx,offset msg9
call writestring
mov eax,route_num[esi]
call writedec
call crlf
mov edx,offset msg10
call writestring
mov eax,stud_num[esi]
call writedec
call crlf
add esi,4
dec ecx
cmp ecx,0
ja rview
jmp viewending
norec:
call crlf
mov edx,offset msg12
call writestring
call crlf
viewending:
mov edx,offset msg11
call writestring
call readchar
ret
viewl ENDP
;*****************************Delete procedure*******************
deletel PROC
call clrscr
mov edx,offset system
call writestring
call crlf
mov edx,offset msg13
call writestring
call readint
mov ecx,count
mov esi,0
mov ebp,0
lc:
inc ebp
cmp driver_id[esi],eax
je delt
add esi,4
loop lc
mov edx,offset msg14
call writestring
call crlf
jmp enddel
delt:
mov ecx,count
sub ecx,ebp
add ecx,1
re:
mov eax,driver_id[esi+4]
mov driver_id[esi],eax
mov contact_num[esi],eax
mov eax,bus_num[esi+4]
mov bus_num[esi],eax
mov eax,route_num[esi+4]
mov route_num[esi],eax
mov eax,stud_num[esi+4]
mov stud_num[esi],eax
add esi,4
loop re
mov eax,1
sub count,eax
mov eax,4
sub var,eax
mov edx,offset msg16
mov eax,1000
call delay
call writestring
enddel:
mov eax,3000
call delay
ret
deletel ENDP
;#####################Search procedure##########################
searchl PROC
call clrscr
mov edx,offset system
call writestring
call crlf
mov eax,count
cmp eax,0
je norecord
mov edx,offset msg15
call writestring
call readint
mov ecx,count
mov esi,0
mov ebp,0
lc:
inc ebp
cmp driver_id[esi],eax
je viewit
add esi,4
loop lc
mov edx,offset msg14
call writestring
call crlf
jmp endsearch

viewit:                        
mov edx,offset msg6
call writestring
mov eax,driver_id[esi]
call writedec
call crlf

nextt:
call crlf
mov edx,offset msg7
call writestring
mov eax,contact_num[esi]
call writedec
call crlf
mov edx,offset msg8
call writestring
mov eax,bus_num[esi]
call writedec
call crlf
mov edx,offset msg9
call writestring
mov eax,route_num[esi]
call writedec
call crlf
mov edx,offset msg10
call writestring
mov eax,stud_num[esi]
call writedec
call crlf
jmp endsearch
norecord:
mov edx,offset msg12
call writestring
endsearch:
call readchar
ret
searchl ENDP
;******************************Update procedure***************************
updatel PROC
call clrscr
mov edx,offset system
call writestring
call crlf
mov eax,count
cmp eax,0
je norecord
mov edx,offset msg15
call writestring
call readint


mov ecx,count
mov esi,0
mov ebp,0
lc:
inc ebp
cmp driver_id[esi],eax
je updateit
add esi,4
loop lc
mov edx,offset msg14
call writestring
call crlf
jmp endupdate
updateit:
mov edx,offset msg5
call writestring
call readint
mov driver_id[esi],eax
call crlf

next1:
call crlf
mov edx,offset msg1
call writestring
call readint
mov contact_num[esi],eax
cmp eax,0
ja next2

mov edx,offset err
call writestring

jmp next1
next2:
call crlf
mov edx,offset msg2
call writestring
call readint
mov bus_num[esi],eax
cmp eax,10
jbe next3

jmp errr
errr:
mov edx,offset err
call writestring

jmp next2
next3:
mov edx,offset msg3
call writestring
call readint
mov route_num[esi],eax
cmp eax,20
jbe next4
jmp err2
err2:
mov edx,offset err
call writestring

jmp next3
next4:
mov edx,offset msg4
call writestring
call readint
mov stud_num[esi],eax
cmp eax,80
jbe endupdate
jmp err3
err3:
mov edx,offset err
call writestring

jmp next4
jmp endupdate
norecord:
mov edx,offset msg12
call writestring
endupdate:

ret
updatel ENDP
END main

No comments:

Post a Comment