我的老师给我分配了一个在汇编中编写DOS程序的项目。程序应该创建/删除/重命名文件/目录并更改文件属性。我正在使用masm611。 我在我的程序中包含了dos.inc。该程序分为两个文件,第一个是pro.asm,第二个是code.asm。
// dos.inc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Syntax: @MkDir path [,segment]
;
; @RmDir path [,segment]
;
; @ChDir path [,segment]
;
; Summary: Creates, deletes, or changes to the specified directory
;
; Arguments: <path> Offset of ASCIIZ string containing
; directory. Must be offset address.
;
; <segment> Segment of path; DS if none given.
;
; Returns: If carry: set, error code in AX
;
; Modifies: AX, DX; DS if segment changed
;
; Uses: Interrupt 21h Function 39h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@MkDir MACRO path:REQ, segmnt
__LdAdr dx, <path>
IFNB <segmnt>
__LdSeg ds, <segmnt>
ENDIF
mov ah, 39h
int 21h
ENDM
; 3Ah
@RmDir MACRO path:REQ, segmnt
__LdAdr dx, <path>
IFNB <segmnt>
__LdSeg ds, <segmnt>
ENDIF
mov ah, 3Ah
int 21h
ENDM
; 3Bh
@ChDir MACRO path:REQ, segmnt
__LdAdr dx, <path>
IFNB <segmnt>
__LdSeg ds, <segmnt>
ENDIF
mov ah, 3Bh
int 21h
ENDM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Syntax: @DelFile path [,segment]
;
; Summary: Deletes a specified file
;
; Arguments: <path> Offset of ASCIIZ file specification. Must
; be an offset address.
;
; <segment> Segment of path; DS if none given.
;
; Returns: If carry: set, error code in AX
;
; Modifies: AX, DX; DS if segment changed
;
; Uses: Interrupt 21h Function 41h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@DelFile MACRO path:REQ, segmnt
__LdAdr dx, <path>
IFNB <segmnt>
__LdSeg ds, <segmnt>
ENDIF
mov ah, 41h
int 21h
ENDM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Syntax: @MakeFile path [,[attrib] [,[segment] [,kind]]]
;
; Summary: Creates a file
;
; Arguments: <path> ASCIIZ string of file. Must be an offset
; address.
;
; <attrib> File attribute; 0 is default if none given.
;
; <segment> Segment of address string; DS if not given.
;
; <kind> If none given, a file is created even if one
; already exists. Under DOS 3.x, "tmp" can be
; given to create a unique file or "new" to
; create a file only if one doesn't already
; exist.
;
; Returns: If carry: clear, file handle in AX
;
; Modifies: AX, DX, CX; DS if segment changed
;
; Uses: Interrupt 21h Function 3Ch, 5Ah, 5Bh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@MakeFile MACRO path:REQ, atrib:=<0>, segmnt, kind
IFDIF <atrib>, <0>
mov cx, atrib
ELSE
sub cx, cx
ENDIF
__LdAdr dx, <path>
IFNB <segmnt>
__LdSeg ds, <segmnt>
ENDIF
IFIDNI <kind>, <tmp>
mov ah, 5Ah
ELSEIFIDNI <kind>, <new>
mov ah, 5Bh
ELSE
mov ah, 3Ch
ENDIF
int 21h
ENDM
// pro.asm
enter code here
include dos.inc
include bios.inc
.model small
.stack 100h
.data
LF EQU 0ah
CR EQU 0dh
MSG1 DB 0ah,0dh,"1. Create directory",LF,CR
MSG2 DB "2. Create file",LF,CR
MSG3 DB "3. Delete directory",LF,CR
MSG4 DB "4. Delete file",LF,CR
MSG5 DB "5. Rename directory",LF,CR
MSG6 DB "6. Rename file",LF,CR
MSG7 DB "7. Change attributes",LF,CR
MSG8 DB "8. Exit $",LF,CR
PATH DB "c:\mydir",0
PATHF DB "C:\abc.exe",0
AnyKeyMsg DB LF,CR,"Press any key to continue...$",LF,CR
.code
main PROC
MOV AX,@DATA
MOV DS,AX
CALL clearAllReg
CALL start
main ENDP
include code.asm
End main
// code.asm
start PROC
;this function starts the program
;input=none ouput=none
;MOV ah,0ah
;MOV DX,SI
;INT 21h
do:
@cls
CALL showDate
CALL showMenu
CALL newLine
CALL getCharInput
CMP BL,49 ;49 is ASCI for 1
JE CDirectory ;if BL is equals to 49 then jump to create directory
CMP BL,50 ;50 is ASCI for 2
JE CFile ;if BL is equals to 50 then jump to create file
CMP BL,51 ;51 is ASCI for 3
JE DDirectory ;if BL is equals to 51 then jump to delete directory
CMP BL,52 ;52 is ASCI for 4
JE DFile ;if BL is equals to 52 then jump to delete file
CMP BL,53 ;53 is ASCI for 5
JE RDirectory ;if BL is equals to 53 then jump to rename directory
CMP BL,54 ;54 is ASCI for 6
JE RFile ;if BL is equals to 54 then jump to rename file
CMP BL,55 ;55 is ASCI for 7
JE ChAttributes ;if BL is equals to 55 then jump to change attributes of a file
CMP BL,56 ; 56 is ASCI for 8
JE Exit ; until BL equals to 56
JMP do
CDirectory:
CALL makeDir
JMP do
CFile:
CALL makeFile
JMP do
DDirectory:
CALL rmDir
JMP do
DFile:
CALL rmFile
JMP do
RDirectory:
CALL rnDir
JMP do
RFile:
CALL rnFile
JMP do
ChAttributes:
CALL chFAttrib
JMP do
Exit:
@exit
RET
start EndP
clearAllReg PROC
;this function sets AX,BX,CX and DX equals to 0
;input=none output=none
MOV AX,0
MOV BX,0
MOV CX,0
MOV DX,0
RET
clearAllReg EndP
showMenu PROC
;this function show menu on the screen
;input=none output=DX
LEA DX,MSG1
MOV AH,9
INT 21h
RET
showMenu EndP
makeDir PROC
;MOV ah,2
;MOV dl,'a'
;INT 21h
MOV AX,offset PATH
@MkDir AX
CALL pressAnyKey
RET
makeDir EndP
makeFile PROC
;MOV ah,2
;MOV dl,'b'
;INT 21h
MOV AX,offset PATHF
@MakeFile AX
CALL pressAnyKey
RET
makeFile EndP
rmDir PROC
;MOV ah,2
;MOV dl,'c'
;INT 21h
MOV AX,offset PATH
@RmDir AX
CALL pressAnyKey
RET
rmDir EndP
rmFile PROC
;MOV ah,2
;MOV dl,'d'
;INT 21h
MOV AX,offset PATHF
@DelFile AX
CALL pressAnyKey
RET
rmFile EndP
rnDir PROC
MOV ah,2
MOV dl,'e'
INT 21h
CALL pressAnyKey
RET
rnDir EndP
rnFile PROC
MOV ah,2
MOV dl,'f'
INT 21h
CALL pressAnyKey
RET
rnFile EndP
chFAttrib PROC
MOV ah,2
MOV dl,'g'
INT 21h
CALL pressAnyKey
RET
chFAttrib EndP
newLine PROC
;Adds new line
;Input=none output=none
MOV DL,LF
MOV AH,2
INT 21h
MOV DL,CR
INT 21h
RET
newLine ENDP
getCharInput PROC
;this function takes input from user
;input=none output=BX
PUSH AX ;saving state
CALL newLine
MOV dl,'?'
MOV AH,2
INT 21h
MOV AH,1
INT 21h
MOV BX,AX
POP AX ;restoring state
RET
getCharInput EndP
pressAnyKey PROC
PUSH AX ;Saving state
LEA DX,AnyKeyMsg
MOV AH,9
INT 21h
MOV AH,1
INT 21h
POP AX ;restoring state
RET
pressAnyKey EndP
showDate PROC
@GetTime
RET
showDate EndP