Skip to contentSkip to conversation

chdir command

DISCUSSION Allan Wooley 3 participants 3 messages May 3, 2002 – May 6, 2002

lore
Share & tools
lore
#0 lore raw

I can not get system call #12 to work as advertised. In Read Hat Linux 7.2 under bash using nasm with elf I write:

section .text
global _start

path db '/root',0

_start:

    mov ebx, path
    mov eax,12
    int 80h

    mov eax, 1
    int 80h        ;; int 0x80

Although I have gotten system calls 1, 3-6 & 11 to work fine in assembly programs, I can not get the change-working-directory call to work.

#1 lore raw
Quoted 17 lines

I can not get system call #12 to work as advertised. In Read Hat Linux 7.2 under bash using nasm with elf I write:

section .text
global _start

path db '/root',0

_start:

    mov ebx, path
    mov eax,12
    int 80h

    mov eax, 1
    int 80h        ;; int 0x80
Quoted 2 lines

Although I have gotten system calls 1, 3-6 & 11 to work fine in assembly programs, I can not get the change-working-directory call to work.

The chdir call is working just fine. What you're forgetting is that every process has its own current directory. That's why the cd command has to be a shell builtin -- a process can't change its parent's current directory, only its own.
________________

section .bss
cwdbuf:

    resb 1024

%macro printcwd 0 ;; call getcwd, then write

		pusha
		mov	ebx, cwdbuf
		mov	ecx, 1024
		mov	eax, 183
		int	0x80
		mov	byte [ebx + eax], 10
		inc	eax
		mov	edx, eax
		mov	ecx, ebx
		mov	ebx, 1
		mov	eax, 4
		int	0x80
		popa

%endmacro

section .text
global _start

path db '/root',0

_start:

	printcwd

    mov ebx, path
    mov eax, 12
    int 80h

	printcwd

    xor ebx, ebx
    mov eax, 1
    int 80h        ;; int 0x80

________________

b

#2 lore raw
In reply to Allan Wooley
Quoted 14 lines · Allan Wooley

section .text
global _start

path db '/root',0

_start:

    mov ebx, path
    mov eax,12
    int 80h

    mov eax, 1
    int 80h        ;; int 0x80
Quoted 3 lines

Although I have gotten system calls 1, 3-6 & 11 to work fine in assembly
programs, I can not get the change-working-directory call to work.

Make sure you have needed permissions. Which error do you get?

Signature · 2 lines
Regards,
Konstantin