Background and Goals:
I am fairly new to assembly, and even newer to macOS. I am currently hitting an error I don't know how to solve or even how to debug. The goal is to change directory in the parent application. I have found ways to do this in Shell, but it is a bit hacky, and I am hoping to be able to achieve this using Assembly.
I am currently running the assembly code below on Mac Monterey v12.2.
I ran into problems with linker errors before, and ended up following everything on the following link before up where I am now: nasm - Can't link object file with ld on macOS Mojave
Present:
I am getting the error .zsh bus error ./chdirfn.
I am ..
.. compiling using nasm -f macho64 chdirfn.asm ..
.. linking the object file using ld -e start -static chdirfn.o -o chdirfn..
.. running the executable via ./chdirfn
I am curious how I might fix the code AND how I could have figure out what the bus error was on my own?
Code:
; code modified from from querist post on https://stackoverflow.com/questions/35905847/chdir-syscall-in-os-x-assembler
global start
section .text
section .data
path db "/Users/sister/",0x00,0x00
start:
mov rax, 0x0200000c
lea rdi, [rel path]
sub rsp, 16
syscall
mov rdi, rax
mov rax, 0x02000001
syscall
Expected Behavior: "cd" into `/Users/sister/