Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to use inline asm to change directory

Status
Not open for further replies.

christheprogrammer

Programmer
Jul 10, 2000
258
CA
Hi all,
I am trying to write a C function using inline asm to change the directory in the dos shell. I am using mingw (dev C) to compile and I think the trouble lies in the
"int 21h" function call. Here is the asm code I want to execute:

mov ah,3Bh
mov dx,"DIRNAME"
int 21h

Simple, but trying to find examples on this stuff is hard.
Thanks & good weekend Chris
 
The 3Bh service of interrupt 21h uses an offset to point to the ASCII directory name, it is DS:DX; also your dirname should be ASCIIZ (0-terminated string)... thus try this:

first define DIRNAME like so inside your data segment:
;
DATA SEGMENT
;
DIRNAME DB "D:\Dirname\NewDir",0 ; or whatever path you want
;
DATA ENDS

then in the code segment:

CODE SEGMENT
;
mov ax, DATA ; base address of data segment
mov ds, ax ; moved here
lea dx, DIRNAME ; DS:DX pointer set here
mov ah, 3Bh ; place function 3Bh in ah for
int 21h ; interrupt call to dos
;
CODE ENDS

also if there is an error it will set the carry flag so you may want to check it after returning from dos... the error code is returned in ax; if ax is 03h it means the path was not found.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top