Apple Silicon assembly fizz buzz example
To run this code, you need to:
- Compile the
main.s
file
as -o main.o main.s
- Link the object file with
libc
:
gcc -o main -lc main.o
- Run the executable:
./main
Usually, to debug an assembly code, you use gdb, but right now doesn't work on MacOS's arm64 assembly. Fortunately, a similar tool called LLDB can already be used on MacOS's arm64 assembly.
To use a debugger on the assembly code, you need to compile and link it with -gdwarf-4
flag, like so:
$ as main.s -o main.o -gdwarf-4
$ gcc main.o -o main -lc -gdwarf-4
This tells the compiler to add debugging information inside the executable file for the debugger. To debug your code, run this command:
lldb ./main
This command will display a REPL that allows you to set breakpoints, step over and into lines, and view the current values of all registers among other things. You can learn more about what you can do with LLDB in Apple's GDB and LLDB Command Examples archived documentation or LLDB's GDB to LLDB command map documentation page.
You may be able to run this example on arm64-based Linux and Windows with the same processes, but I haven't tried it out yet.