获取当前目录路径或命名Assembly 8086

时间:2015-04-23 17:59:05

标签: assembly directory interrupt x86-16

我已经看到AH = 47h中断(int 21h)但我无法使用它。我的问题是显示(在屏幕上打印)目录的名称。有人可以帮帮我吗?你有代码吗?谢谢。

到目前为止,我已尝试过这段代码,但显然它不起作用

.model tiny

.data

handle   dw ? 

filename db  26        ;MAX NUMBER OF CHARACTERS ALLOWED (25).
         db  ?         ;LENGTH (NUMBER OF CHARACTERS ENTERED BY USER).
         db  26 dup(0) ;CHARACTERS ENTERED BY USER. END WITH CHR(13).

msj      db 'ENTER FILE NAME HERE: $' 

text     db 'text for file'  ;LENGTH = 13.

.code
    org 100h

inizio: 

;DISPLAY MESSAGE.
    mov dx, offset msj
    mov ah, 9
    int 21h      

;REATE FILE.
    mov ah, 47h
    mov dl, 03h
    mov dx, offset filename 
    int 21h

;CAPTURED STRING ENDS WITH CHR(13), BUT TO CREATE FILE WE NEED
;THE FILENAME TO END WITH CHR(0), SO LET'S CHANGE IT.
    mov si, offset filename + 1 ;NUMBER OF CHARACTERS ENTERED.
    mov cl, [ si ] ;MOVE LENGTH TO CL.
    mov ch, 0      ;CLEAR CH TO USE CX. 
    inc cx         ;TO REACH CHR(13).
    add si, cx     ;NOW SI POINTS TO CHR(13).
    mov al, 36d
    mov [ si ], al ;REPLACE CHR(13) BY 0.            

    mov ah,9
    lea dx,filename     ; DISPLAY NAME
    int 21h

;END PROGRAM.
    mov ah, 4ch
    int 21h

end inizio

1 个答案:

答案 0 :(得分:0)

下一个小程序(用EMU8086制作)只做两件事:获取当前目录名,并显示它:

.model tiny

.data

directory db 50 dup('$')  ;NECESSARY TO DISPLAY ON SCREEN.

.code

;INITIALIZE DATA SEGMENT.
    mov ax, @data
    mov ds, ax

;GET CURRENT DIRECTORY NAME.
    mov ah, 47h
    mov dl, 0                ;DRIVE, 0 = CURRENT DRIVE.
    mov si, offset directory ;VARIABLE TO STORE DIRECTORY NAME.
    int 21h

;DISPLAY DIRECTORY NAME.
    mov  ah, 9
    mov  dx, offset directory
    int  21h

;WAIT FOR ANY KEY.    
  mov  ah, 7
  int  21h

;END PROGRAM.
    mov ah, 4ch
    int 21h

我摆脱了" inizio"因为我们实际上并不需要它。