¡¡¡¡ÔÚÈ·¶¨ÁËÄ£¿é×éÖ¯¼°¹«¹²Êý¾ÝÏîÖ®ºó£¬Ó¦¸Ãд³ö¸÷Ä£¿éµÄÄ£¿é˵Ã÷£¬È»ºó±àÖƸ÷Ä£¿é³ÌÐò¡£
¡¡¡¡ÔÚÕâÀÎÒÃÇÖ»ÒÔ²¿·Ö³ÌÐò¼°ÆäÄ£¿é˵Ã÷ΪÀýÀ´ËµÃ÷ÕâÒ»¹ý³Ì¡£ÏÂÃæ¸ø³öUPDATE¼°SEARCHµÄÄ£¿é˵Ã÷¡£UPDATEÄ£¿éµÄÊý¾Ý¶ÎÒÔ¼°UPDATEºÍSEARCH¹ý³ÌµÄ³ÌÐòÏÂËùʾ¡£
¡¡¡¡(1) UPDATE
¡¡¡¡Name: UPDATE
¡¡¡¡Common: Areas in common that may be affected or used DIRECTORY,UPDAT_DATA,ERR_CODE
¡¡¡¡Function: To determine the command code letter 2I2(insert),
2D2(delete) or 2C2(change) and call
¡¡¡¡the submodules SEARCH,INSERT,DELETE and CHANGE to perform the
requested action. (
¡¡¡¡A check for 2S2(stop) is made in MAIN) It first puts 0 in ERR_CODE
and then ,if it¡¡cannot identify the command letter,it changes
the content of ERR_CODE to 1 and returns to MAIN. Its submodules
may change ERR_CODE to 2 if they detect an error.
¡¡¡¡(2)SEARCH
¡¡¡¡Name: SEARCH
¡¡¡¡Input: From UPDATE_the local variables KEY
¡¡¡¡Output: To UPDATE_the local variables PRIOR_ELE,CUR_ELE,SRCH_CODE
¡¡¡¡Common: Area in common that is used DIRECTORY,ERR_CODE
¡¡¡¡Function: It sets ERR_CODE to 2 and returns if (KEY) are outside
the range 1000 to 9999.
¡¡¡¡Otherwise it searches DIRCTORY for the key in KEY and returns
to UPDATE the indices to the elements which are such that:
¡¡¡¡The key is the largest key less than (KEY).
¡¡¡¡The key is the smallest key greater than or equal to (KEY).
¡¡¡¡It puts 1 in SRCH_CODE if (KEY) are matched and 0 in SRCH_CODE
if they are not matched.
¡¡¡¡ÎÒÃÇËäÈ»²¢Î´¿´µ½ÍêÕûµÄ³ÌÐò£¬µ«ÊÇ£¬´ÓÕâ¸öÀý×ÓÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½Ä£¿éµÄ»®·ÖÒÔ¼°°Ñ¸÷¸öÄ£¿é×é³ÉÎļþµÄ·½·¨¡£Í¬Ê±ÎÒÃÇÒ²¿´µ½Á˹«¹²Êý¾ÝÇøµÄ¶¨ÒåºÍʹÓ÷½·¨¡£ÎÒÃÇÏàÐÅͨ¹ý±¾¿Î³Ì°üÀ¨±¾½ÚÄÚÈݵÄѧϰ£¬Í¬Ñ§ÃÇÊÇÄܹ»±àÖƳöºÜºÃµÄ»ã±àÓïÑÔ³ÌÐòµÄ¡£
¡¡¡¡;************************************************************
¡¡¡¡¡¡public ¡¡update
¡¡¡¡¡¡extrn ¡¡ locate:far,inputm:far,outputm:far
¡¡¡¡;************************************************************
¡¡¡¡¡¡data_seg ¡¡¡¡segment
¡¡¡¡¡¡srch_code ¡¡ db ?
¡¡¡¡¡¡prior_ele ¡¡ dw ?
¡¡¡¡¡¡cur_ele ¡¡¡¡ dw ?
¡¡¡¡¡¡key ¡¡¡¡¡¡¡¡ dw ?
¡¡¡¡¡¡data_seg ¡¡¡¡ends
¡¡¡¡;************************************************************
¡¡¡¡¡¡com_seg ¡¡¡¡ segment ¡¡¡¡common
¡¡¡¡¡¡d_element ¡¡ struc
¡¡¡¡¡¡empnum ¡¡¡¡¡¡dw ?
¡¡¡¡¡¡info ¡¡¡¡¡¡¡¡dw 3 ¡¡¡¡¡¡ dup(?)
¡¡¡¡¡¡pointer ¡¡¡¡ dw ?
¡¡¡¡¡¡d_element ¡¡ ends
¡¡¡¡¡¡;
¡¡¡¡¡¡u_data ¡¡¡¡¡¡struc
¡¡¡¡¡¡command ¡¡¡¡ db ?
¡¡¡¡¡¡com_key ¡¡¡¡ dw ?
¡¡¡¡¡¡com_data ¡¡¡¡db 256 ¡¡¡¡ dup(?)
¡¡¡¡¡¡u_data ¡¡¡¡¡¡ends
¡¡¡¡¡¡;
¡¡¡¡¡¡directory ¡¡ d_element 1000 dup(< >)
¡¡¡¡¡¡err_code ¡¡¡¡db ?
¡¡¡¡¡¡update_data¡¡u_data < >
¡¡¡¡¡¡com_seg ¡¡¡¡ ends
¡¡¡¡;************************************************************
¡¡¡¡¡¡update_seg ¡¡segment
¡¡¡¡;------------------------------------------------------------
¡¡¡¡¡¡¡¡¡¡¡¡assume cs:update_seg,ds:data_seg,es:com_seg
¡¡¡¡¡¡update ¡¡¡¡¡¡proc far
¡¡¡¡¡¡push ¡¡¡¡¡¡¡¡ax ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡;save registers on stack
¡¡¡¡¡¡push ¡¡¡¡¡¡¡¡bx
¡¡¡¡¡¡push ¡¡¡¡¡¡¡¡cx
¡¡¡¡¡¡push ¡¡¡¡¡¡¡¡dx
¡¡¡¡¡¡push ¡¡¡¡¡¡¡¡si
¡¡¡¡¡¡push ¡¡¡¡¡¡¡¡di
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ err_code,0 ¡¡¡¡¡¡¡¡¡¡;zero err_code
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ ax,update_data.com_key
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡;move command key to AX
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ key,ax ¡¡¡¡¡¡¡¡¡¡¡¡¡¡; and key
¡¡¡¡¡¡call ¡¡¡¡¡¡¡¡near ptr search ¡¡¡¡ ;search for key
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ dl,update_data.command
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡;put command in DL
¡¡¡¡¡¡cmp ¡¡¡¡¡¡¡¡ dl,'I' ¡¡¡¡¡¡¡¡¡¡¡¡¡¡;if command letter is not 'I'
¡¡¡¡¡¡jnz ¡¡¡¡¡¡¡¡ not_i ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ; branch to not_i
¡¡¡¡¡¡call ¡¡¡¡¡¡¡¡near ptr insert ¡¡¡¡ ;otherwise,make insertion
¡¡¡¡¡¡jmp ¡¡¡¡¡¡¡¡ short exit ¡¡¡¡¡¡¡¡¡¡; and branch to exit
¡¡¡¡¡¡not_i: ¡¡¡¡¡¡cmp dl,'D' ¡¡¡¡¡¡¡¡¡¡;if command is not 'D'
¡¡¡¡¡¡jnz ¡¡¡¡¡¡¡¡ not_d ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ; branch to not_d
¡¡¡¡¡¡call ¡¡¡¡¡¡¡¡near ptr delete ¡¡¡¡ ;otherwise,make delete
¡¡¡¡¡¡jmp ¡¡¡¡¡¡¡¡ short exit ¡¡¡¡¡¡¡¡¡¡; and branch to exit
¡¡¡¡¡¡not_d: ¡¡¡¡¡¡cmp dl,'C' ¡¡¡¡¡¡¡¡¡¡;if command is not 'C'
¡¡¡¡¡¡jnz ¡¡¡¡¡¡¡¡ not_c ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ; branch to not_c
¡¡¡¡¡¡call ¡¡¡¡¡¡¡¡near ptr change ¡¡¡¡ ;otherwise,make change
¡¡¡¡¡¡jmp ¡¡¡¡¡¡¡¡ short exit ¡¡¡¡¡¡¡¡¡¡; and branch to exit
¡¡¡¡¡¡not_c: ¡¡¡¡¡¡mov err_code,1 ¡¡¡¡¡¡;set err_code to 1
¡¡¡¡¡¡exit: ¡¡¡¡¡¡ pop di ¡¡¡¡¡¡¡¡¡¡¡¡¡¡;restore registers
¡¡¡¡¡¡pop ¡¡¡¡¡¡¡¡ si
¡¡¡¡¡¡pop ¡¡¡¡¡¡¡¡ dx
¡¡¡¡¡¡pop ¡¡¡¡¡¡¡¡ cx
¡¡¡¡¡¡pop ¡¡¡¡¡¡¡¡ bx
¡¡¡¡¡¡pop ¡¡¡¡¡¡¡¡ ax
¡¡¡¡¡¡ret ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡; and return
¡¡¡¡¡¡update ¡¡¡¡¡¡endp
¡¡¡¡;------------------------------------------------------------
¡¡¡¡¡¡.
¡¡¡¡¡¡.
¡¡¡¡¡¡.
¡¡¡¡;------------------------------------------------------------
¡¡¡¡¡¡search ¡¡¡¡¡¡proc near
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ srch_code,0 ¡¡¡¡¡¡¡¡ ;zero srch_code
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ ax,key ¡¡¡¡¡¡¡¡¡¡¡¡¡¡;put key in AX
¡¡¡¡¡¡cmp ¡¡¡¡¡¡¡¡ ax,1000 ¡¡¡¡¡¡¡¡¡¡¡¡ ;check if key is
¡¡¡¡¡¡jb ¡¡¡¡¡¡¡¡¡¡error ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ; in the range 1000
¡¡¡¡¡¡cmp ¡¡¡¡¡¡¡¡ ax,9999 ¡¡¡¡¡¡¡¡¡¡¡¡ ; to 9999,if so
¡¡¡¡¡¡ja ¡¡¡¡¡¡¡¡¡¡error ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ; branch to ok
¡¡¡¡¡¡jmp ¡¡¡¡¡¡¡¡ short ok
¡¡¡¡¡¡error: ¡¡¡¡¡¡mov err_code,2 ¡¡¡¡¡¡;else,put 2 in err_code
¡¡¡¡¡¡jmp ¡¡¡¡¡¡¡¡ short not_found ¡¡¡¡ ; and exit to not_found
¡¡ok: lea ¡¡¡¡¡¡¡¡ bx,directory.empnum¡¡;put base addr in BX
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ si,es:[bx+8] ¡¡¡¡¡¡¡¡;put pointer in SI and
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ prior_ele,0 ¡¡¡¡¡¡¡¡ ; prior index in prior_ele
¡¡¡¡¡¡again: ¡¡¡¡¡¡cmp ax,es:[bx][si] ¡¡;compare keys and
¡¡¡¡¡¡je ¡¡¡¡¡¡¡¡¡¡found ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ; branch to found if equal
¡¡¡¡¡¡jl ¡¡¡¡¡¡¡¡¡¡greater ¡¡¡¡¡¡¡¡¡¡¡¡ ;if less than go to greater
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ prior_ele,si ¡¡¡¡¡¡¡¡;else,update prior_ele
¡¡¡¡¡¡mov ¡¡¡¡¡¡¡¡ si,es:[bx][si+8]¡¡¡¡ ; and SI
¡¡¡¡¡¡jmp ¡¡¡¡¡¡¡¡ short again
¡¡¡¡¡¡found: ¡¡¡¡¡¡mov srch_code,1
¡¡¡¡¡¡greater:¡¡¡¡ mov cur_ele,si
¡¡¡¡¡¡not_found:
¡¡¡¡¡¡ret
¡¡¡¡¡¡search ¡¡¡¡¡¡endp
¡¡¡¡;------------------------------------------------------------
¡¡¡¡¡¡.
¡¡¡¡¡¡.
¡¡¡¡¡¡.
¡¡¡¡;------------------------------------------------------------
¡¡¡¡¡¡update_seg ends ;end of code segment
¡¡¡¡;************************************************************
¡¡¡¡¡¡end ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡;end of assembly