INT 21h AH=3Bh sets the current directory: CD (CHDIR) at the prompt. A relative path starts from the current directory, a path starting with "\" from the root, and ".." means the parent:
| Path | Result |
|---|---|
| SUB | into SUB, below the current directory |
| .. | up one level |
| \ | the root of the current drive |
| \TOOLS\BIN | an absolute path on the current drive |
| D:\GAMES | the current directory of D:; the current drive does not change |
The drive in the path does not become the current drive; that takes INT 21h AH=0Eh. This is why CD D:\GAMES at a C:\> prompt leaves you on C:. To go somewhere on another drive, a program makes both calls.
Pitfalls: a trailing backslash (\TOOLS\) fails with error 3, except for the root itself; the path must be ASCIIZ, and name a directory, not a file. The whole path, drive included, must fit in 64 characters.
Coming back
The current directory belongs to the drive, not to the program. DOS keeps one per drive in its current directory structure, and a program that changes it and exits leaves the user there. Save it with INT 21h AH=47h first and change back before exiting. 47h returns the path without the leading backslash, so the example keeps a "\" in front of its buffer to make the saved path absolute:
MOV AH, 47h ; DOS: the current directory, for laterMOV DL, 0 ; 0 = the current driveMOV SI, OFFSET OLD1+1 ; after the "\" already thereINT 21hMOV AH, 3Bh ; DOS: change the directory to DS:DXMOV DX, OFFSET ROOT1 ; "\": the rootINT 21hCALL PCWD ; prints "C:\"MOV AH, 3Bh ; and back: "\" and the old pathMOV DX, OFFSET OLD1INT 21hMOV AH, 47h ; where are we now?MOV DL, 0MOV SI, OFFSET NOW1INT 21hCLDMOV SI, OFFSET OLD1+1MOV DI, OFFSET NOW1 ; ES = DS in a .COMMOV CX, 64REPE CMPSB ; the same 64 bytes?MOV DX, OFFSET BACK1JE SAME1MOV DX, OFFSET LOST1SAME1:MOV AH, 09hINT 21hROOT1 DB "\", 0OLD1 DB "\", 64 DUP(0)NOW1 DB 64 DUP(0)BACK1 DB "back in the old directory", 13, 10, "$"LOST1 DB "somewhere else", 13, 10, "$"PCWD PROC NEAR ; print the current directory: C:\PATHMOV AH, 19h ; the drive letterINT 21hADD AL, "A"MOV DL, ALMOV AH, 02hINT 21hMOV DL, ":"MOV AH, 02hINT 21hMOV DL, "\"MOV AH, 02hINT 21hMOV AH, 47h ; the directory, without "\" in frontMOV DL, 0MOV SI, OFFSET DIRBUFINT 21hCLDPCWD1:LODSBOR AL, ALJZ PCWD2MOV DL, ALMOV AH, 02hINT 21hJMP PCWD1PCWD2:MOV DX, OFFSET CRLFMOV AH, 09hINT 21hRETPCWD ENDPDIRBUF DB 64 DUP(0)CRLF DB 13, 10, "$"