求编写一道汇编语言程序,要求完成一定功能(任意)【高分追加】

2024-12-25 12:04:53
推荐回答(2个)
回答1:

到我的 百度空间 挑选一个即可。

回答2:

DATASEG segment
MSGDIR DB 'PLEASE INPUT THE DIR(eg d:):',13,10,'$'
MSGFILENAM DB 13,10,'PLEASE INPUT THE FILENAME:',13,10,'$'
RESULT DB 'RESULT.TXT',0,'$'
SUMFILE DB 13,10,'SUM OF FILES ARE:',13,10,'$'
SUMFILEN DB ?,?,?,?,0DH,0AH ;STRING OF THE SUMNUM
FOUNDFILE DB 13,10,'FOUND FILES ARE:',13,10,'$'
FOUNDFILEN DB ?,?,?,?,0DH,0AH ;STRING OF TEH FOUNDNUM
SP_CRE_ERR DB 'CREATE RESULT FILE ERR!',13,10,'$'
SP_OPE_ERR DB 'OPEN THE RESULT FILE ERR!',13,10,'$'
SP_WRI_ERR DB 'WRITE TO THE RESULT FILE ERR!',13,10,'$'
SUMNUM DW 0 ;NUM OF ALL THE FILES
FOUNDNUM DW 0 ;NUM OF GOAL FILE
;PATH_PRS DW ? ;POINTER TO THE PRESENT DIR
PATH_NEXT DW ? ;ADDRESS OF NEXT FILE
PATH_END DW ? ;END OF PATHBUFF
PATH_BUFF DB 0a000H DUP ('$')
FIND_NAME DB 127,0,'XZX.TXT',0,0,111 DUP('$'),0dh,0ah,'$'
FINDING_PATH DB 128 DUP (?) ;FILE OF THE FOUND
MYDTA DB 128 DUP(0),0DH,0AH,'$' ;SET DATA TRANSFER AREA
DIR DB 127,0,'G:\X',126 DUP('$'),0DH,0AH,'$' ;DIR OF SEARCH
FOUNDPATH_END DW ? ;POINTER OF THE END OF FOUND_PATH
FOUND_PATH DB 0AH,0DH,100H DUP('$') ;PATH BUFFER OF THE FILES FOUND
DIRFLAG DB ?
DATASEG ENDS

CODESEG SEGMENT
MAIN PROC FAR
ASSUME CS:CODESEG,DS:DATASEG,ES:DATASEG
START:
MOV AX,DATASEG
MOV DS,AX
MOV ES,AX
;;SET NEW DTA
MOV DX,OFFSET MYDTA
MOV AH,1AH
INT 21H
CALL INPUTN
CALL SCAN_DIR
CALL CRLF
CALL CRLF
MOV DX,OFFSET FOUND_PATH
MOV AH,9H
INT 21H
CALL CRLF
MOV SI,OFFSET SUMFILEN
MOV BX,SUMNUM
CALL BINIDEC
CALL CRLF
MOV SI,OFFSET FOUNDFILEN
MOV BX,FOUNDNUM
CALL BINIDEC
CALL SAVE_PATH ;save the found path to file
MOV AH,01H
INT 21H
MOV AX,4C00H
INT 21H
MAIN ENDP

INPUTN PROC NEAR
MOV DX,OFFSET MSGDIR
MOV AH,9h
INT 21H
MOV DX,OFFSET DIR
MOV AH,10
INT 21H
MOV DX,OFFSET MSGFILENAM
MOV AH,9h
INT 21H
MOV DX,OFFSET FIND_NAME
MOV AH,10
INT 21h
MOV BL,FIND_NAME+1 ;MAKE END OF THE NAME IS 0
XOR BH,BH
MOV FIND_NAME[BX+2],0
RET
INPUTN ENDP

SCAN_DIR PROC NEAR
MOV AX,OFFSET FOUND_PATH
MOV FOUNDPATH_END,AX
MOV AX,OFFSET PATH_BUFF
MOV PATH_NEXT,AX
;MOV PATH_PRS,AX
MOV PATH_END,AX
CALL MPHASE_DIR ;PREPROCESS OF THE DIR(C:)
SC_LOP:
MOV DX,PATH_NEXT
MOV CX,37H
MOV AH,4EH
INT 21H
JC SC_RE ;*.*IN THIS MODEL FIRST IS PRESENT DIR
NEXT:
MOV CX,37H
MOV AH,4FH
INT 21H
JC SC_RE
INC SUMNUM ;SUM OF FILE INCREASE ONE
CALL DISPLAY_PATH ;DILAY THE PATH
CALL FILEPROC ;PROCESS OF THE PRESENT FILE:FIRST CHECK IF IT IS THE GOAL NEXT CHECK IF IT IS DIR
JMP NEXT
SC_RE:
MOV SI,PATH_NEXT
CMP SI,PATH_END
;PATH_BUFF IS EMPTY?
JE SC_RET
MOV SI,PATH_NEXT ;FIND THE NEXT DIR
CLD
SC_NEXT_LOP:
LODSB
CMP AL,0
JNE SC_NEXT_LOP
MOV PATH_NEXT,SI
JMP SC_LOP
SC_RET:
RET
SCAN_DIR ENDP

MPHASE_DIR PROC NEAR
MOV SI,OFFSET DIR
MOV DI,path_NEXT
add si,2
cld
LODSW ;ASSUME PATH IS LIKE D:
STOSW
; LODSW
; STOSW
MOV AX,'*\'
STOSW
MOV AX,'*.'
STOSW
MOV AL,0
STOSB
mov al,'$'
stosb
dec di
MOV PATH_END,DI
RET
MPHASE_DIR ENDP

;IF DIR IS THE PRESENT DIR OF FATHER DIR ,NOT DISPLAY
DISPLAY_PATH PROC NEAR
; mov the path_prs to FINDING_PATH and display
CALL CHECK_IS_LEGAL_DIR
CMP AX,1
JNE DISP_END
MOV SI,PATH_NEXT
MOV DI,OFFSET FINDING_PATH
cld
DISP_LOP:
LODSB
STOSB
CMP AL,'\'
JNE DISP_LOP
lodsb
stosb
CMP AL,'*'
JNE DISP_LOP
MOV SI,OFFSET MYDTA
ADD SI,1EH
dec di ;more a '*'
CLD
DISP_LOP2:
LODSB
STOSB
CMP AL,'.'
JNE DISP_N
STOSB
LODSB
CMP AL,'.'
JE DISP_END
DISP_N:
CMP AL,0
JNE DISP_LOP2
mov al,'$'
stosb
CALL CRLF
MOV DX,OFFSET FINDING_PATH
MOV AH,9
INT 21H
DISP_END:
RET
DISPLAY_PATH ENDP

;ENTRY MYDTA[1E]:THE NAME OF THE PRESENT FILE NAME
FILEPROC PROC NEAR
CALL CHECK_FIND ;FIND IT ?
MOV BP,OFFSET MYDTA
ADD BP,15H
XOR AX,AX
MOV AL,[BP]
TEST AL,10H ;IS DIR?
JZ FP_END ;NOT A DIR,DON'T PROCESS AND QUIT
CALL CHECK_IS_LEGAL_DIR
CMP AX,1
JNE FP_END ;NOT A FATHER DIR
MOV SI,OFFSET FINDING_PATH
MOV DI,PATH_END
CLD
FP_LOP1:
LODSB
CMP AL,0
JE FP_RET
STOSB
JMP FP_LOP1
FP_RET:
MOV AX,'*\'
STOSW
MOV AX,'*.'
STOSW
MOV AL,0
STOSB
MOV PATH_END,DI ;RESET END OF BUFF
FP_END:
RET
FILEPROC ENDP

;CHECK WEATHER DIR IS FATHER OR PRESENT DIR
;OUT:AX:1 LEGAL
; AX:0 ILEGAL
CHECK_IS_LEGAL_DIR PROC NEAR
CMP BYTE PTR MYDTA[1eH],'.'
JZ CHECK_FATHEND
CMP BYTE PTR MYDTA[1eH],0
JZ CHECK_FATHEND
MOV AX,1
JMP CHECK_LEGAL_RETU
CHECK_FATHEND:
MOV AX,0
CHECK_LEGAL_RETU:
RET
CHECK_IS_LEGAL_DIR ENDP

;FIND_FILE:THE FILE TO SEARCH
;IF=,THEN FOUNDNUM+1
CHECK_FIND PROC NEAR ;USE SI
MOV BX,OFFSET MYDTA
ADD BX,1DH
MOV SI,OFFSET FIND_NAME
cld
ADD SI,2
CHF_LOP:
LODSB
INC BX
CMP AL,[BX]
JNE CHF_RET
CMP AL,0
JNE CHF_LOP
CALL FINDIT
CHF_RET:
RET
CHECK_FIND ENDP

;IF FOUND
;STORE THE PRESENT PATH TO FOUNDPATH
;FOUNDNUM++
FINDIT PROC NEAR
INC FOUNDNUM ;FOUND FILE NUM +1
MOV SI,OFFSET FINDING_PATH
MOV DI,FOUNDPATH_END
FINDIT_LOP1:
cld
LODSB
STOSB
CMP AL,0
JE FINDIT_RET
JMP FINDIT_LOP1
FINDIT_RET:
MOV AL,0DH ;STORE CRLF TO FOUND_PATH
STOSB
MOV AL,0AH
STOSB
MOV AL,'$' ;MAKE SURE END IS '$'
STOSB
MOV AX,DI
DEC AX
MOV FOUNDPATH_END,AX
RET
FINDIT ENDP

SAVE_PATH PROC NEAR
MOV AH,3CH
MOV CX,20H ;ATTRIB GUIDANG
MOV DX,OFFSET RESULT
INT 21H
JC SP_CREATE_ERR
MOV BX,AX
MOV AX,3E00H
INT 21H ;CLOSE THE FILE
MOV AX,3D02H
MOV DX,OFFSET RESULT
INT 21H ;OPEN WITH READ ATTRIB
JC SP_OPEN_ERR
MOV BX,AX
MOV AX,4000H

MOV SI,OFFSET FOUND_PATH ;SUM OF CHARS
MOV DI,FOUNDPATH_END
SUB DI,SI
MOV CX,DI

MOV CX,DI
MOV DX,OFFSET FOUND_PATH
INT 21H
CMP AX,DI
JNE SP_WRITE_ERR
MOV AX,4000H
MOV CX,15H
MOV DX,OFFSET SUMFILE
INT 21H
CMP AX,15H
JNE SP_WRITE_ERR
MOV AX,4000H
MOV CX,6H
MOV DX,OFFSET SUMFILEN
INT 21H
CMP AX,6H
JNE SP_WRITE_ERR
MOV AX,4000H
MOV CX,14H
MOV DX,OFFSET FOUNDFILE
INT 21H
CMP AX,14H
JC SP_WRITE_ERR
MOV AX,4000H
MOV CX,6
MOV DX,OFFSET FOUNDFILEN
INT 21H
CMP AX,6H
JC SP_WRITE_ERR
MOV AX,3E00H
INT 21H
EXIT:
RET
SP_CREATE_ERR:
MOV DX,OFFSET SP_CRE_ERR
JMP SP_SHOWERR
SP_OPEN_ERR:
MOV DX,OFFSET SP_OPE_ERR
JMP SP_SHOWERR
SP_WRITE_ERR:
MOV DX,OFFSET SP_WRI_ERR
JMP SP_SHOWERR
SP_SHOWERR:
MOV AX,900H
INT 21H
JMP EXIT
SAVE_PATH ENDP

BINIDEC PROC NEAR
;SUBROUTINE TO CONVERT BINARY NUMBER IN BX
;TO DECIMAL ON CONSOLE SCREEN
MOV CX,10000D
CALL DEC_DIV
MOV [SI],DL
MOV CX,1000D
CALL DEC_DIV
MOV [SI+1],DL
MOV CX,100D
CALL DEC_DIV
MOV [SI+2],DL
MOV CX,10D
CALL DEC_DIV
MOV [SI+3],DL
MOV CX,1D
CALL DEC_DIV
MOV [SI+4],DL
RET
BINIDEC ENDP

DEC_DIV PROC NEAR
;SUBROUTINE TO divideNUMBER IN BX BY NUMBER IN CX
;PRINT QUOTIENT ON SCREEN
;(NUMBERATOR IN DX+AX,DENOM IN CX)
MOV AX,BX
MOV DX,0
DIV CX
MOV BX,DX
MOV DL,AL
ADD DL,30H
MOV AH,2H
INT 21H
RET
DEC_DIV ENDP

CRLF PROC NEAR
MOV DL,0DH
MOV AH,2
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
RET
CRLF ENDP
CODESEG ENDS
END START

磁盘扫描程序