Assembly 为什么我的汇编程序没有创建/删除目录/文件
我的老师分配给我一个项目,用汇编语言编写DOS程序。程序应创建/删除/重命名文件/目录并更改文件属性。我正在使用masm611。 我的程序中包括了dos.inc。该程序分为两个文件,第一个是pro.asm,第二个是code.asm //多斯公司Assembly 为什么我的汇编程序没有创建/删除目录/文件,assembly,dos,masm,Assembly,Dos,Masm,我的老师分配给我一个项目,用汇编语言编写DOS程序。程序应创建/删除/重命名文件/目录并更改文件属性。我正在使用masm611。 我的程序中包括了dos.inc。该程序分为两个文件,第一个是pro.asm,第二个是code.asm //多斯公司 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Syntax: @MkDir path [,segment] ; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; 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
//代码.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
那么问题是什么呢?不创建目录不可见的代码真的很难调试!我敢打赌,
路径
应该是以零结尾的,但它似乎不是。进位标志是否设置在(不可见)int 21h
之后?如果是,ax中的错误号是多少?好的,这很有帮助。我看到你的路径是零终止的PATH
。还是不工作?好的,宏返回时带有进位标志,ax
未触及(这是我看不到的部分)。因此,检查@MkDir
之后的进位标志-要么jc error
要么jnc good
。如果不起作用,应该设置。如果您没有显示ax
的例程,请逐步执行它(不要尝试“逐步”执行dos-在进入int 21h
…假设调试时使用p
)。在RBIL中查找错误代码(如果没有,请获取!)。我觉得你的代码“看起来”不错。“应该”起作用。:)对C\:
的权限可能有问题?好的,“拒绝访问”的错误代码是5。任何其他错误都是个谜。如果你明白了,试着以root用户身份运行(我认为Windows称之为“admin”)。。。或者尝试在当前目录中创建一个子目录(只需关闭c\:
)。勇气!
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