Assembly x64 getcwd() Not Outputting

meep :

I've just started learning/using Assembly x64 on Linux, and am trying to call getcwd() with call. After attempting to call the getcwd() function, I am also trying to output the result which is not working and I do not understand why. Any pointers/help would be really appreciated. Sorry if its a stupid question. I've looked online for examples but haven't found any that help me specifically. Many thanks. Here is the code:

section .text
        global _start

extern getcwd

_start:
        mov     rdi,rbx
        mov     rsi,128

        call getcwd wrt ..plt

        mov     rax,1
        mov     rdi,1
        mov     rsi,rbx
        mov     rdx,128

        syscall

        mov     rax,60
        mov     rdi,0

        syscall

I compile with:

nasm -f elf64 -o file.o file.asm
gcc -nostdlib -v -o file file.o -lc
./file

And nothing is shown

Jester :

Here is a possible implementation that allocates space on the stack. I also switched to main and puts:

global main
extern getcwd
extern puts

main:
        sub rsp, 128+8  ; buffer + alignment
        mov rdi, rsp
        mov rsi, 128

        call getcwd wrt ..plt
        call puts wrt ..plt

        add rsp, 128+8
        ret

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=6471&siteId=1