Hello everybody. I'm trying to get the current directory, save it, changing the current dir, then coming back to the previous one.

My code so far

TITLE ep1_7
	.MODEL    SMALL
        .STACK    10h
        .DATA
        	msg	DB 'Current directory:',0h
		msg_l	equ	$-msg
        	buff		db  64 dup('$')
		;f_handle	dw  1 dup(?)
	.CODE
        	begin:   mov	ax,@DATA
                mov	ds,ax
		;Getting current directory
		mov	ah,47h
		mov	dl,0
		mov	ds,buff
		;showing the returned pathname
		mov  dx,OFFSET buff
		mov  ah,09h
		int  21h
		;bail out
		mov	ax,4c00h	
	        int	21h	
                END	begin

My problem is that i have an error at line 15. I don't know how to put the buffer's adress into ds. Can some one help me?

Btw , please tell me what is the function that waits for a key to be pressed and/or the one that waits a certain given time to pass.

Dani AI

Generated

— The assembler error happens because DS can’t be loaded directly from a label/memory operand. Segment registers must be loaded from a general-purpose register or set once at program startup for a .EXE; assembler helpers (the SEG/OFFSET operators or the assembler’s expansion) hide that two-step move. As indicated, the right approach is to ensure DS points at the data segment and then pass the buffer’s offset in the register expected by the DOS call (do not try to place a full far address directly into DS).

Practical checklist to make the sequence robust:

  • Initialize the program’s data segment at startup and leave DS pointing there; use an offset/LEA into SI or DX when a DOS service requires a pointer.
  • To save/restore directory: call DOS “get current directory” into a buffer, store that buffer (or copy it), change directory with the DOS chdir service, and later call the chdir service again using the saved path to restore. Check the carry-flag / error codes after each DOS call.
  • Printing: many DOS display calls expect a specific terminator. The string returned by the get-current-directory call is not guaranteed to be $-terminated, so relying on the $-print routine is fragile. Either convert the returned NUL to a $ before calling the $-printer, or (better) use the DOS “write” routine that takes an explicit length so output is safe and exact.

Notes on input and delays:

  • For a blocking key wait, use BIOS keyboard (INT 16h AH=0) or the DOS functions that block and return a character (different DOS services echo vs. non-echo). For non-blocking polls there are small DOS/BIOS checks that indicate whether a key is waiting.
  • For timed waits, read the BIOS tick counter (0x0040:0x006C, ~18.2 ticks/sec) or use the BIOS/DOS time services and loop until the desired tick delta has passed. Avoid long CPU-burning busy loops without sleeping/polling.

Summary: fix the DS load by initializing DS properly and passing offsets, preserve the returned string format before printing, and use the appropriate DOS/BIOS calls for keyboard and timing.

mov ds, seg buff ; works in MASM
mov si, offset buff

All you need is the segment address on which the buff string
lies, this is because your generating an .EXE.

Here's one way to wait for a key press:

waitkey:
  mov ah, 0x6
  mov dx, 0xff
  int 0x21
  jz waitkey ; if no char recieved ZF=1
commented: This solved the thread +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.