As now I'm getting into calculator programming, I wish I could have a cross assembler on desktop computer so I can write programs for them.
I though once that macro assemblers on modern computers are all dead. It is proved that I was wrong, by presenting Flat Assembler G. This is a macro assembler down to the level of available instructions and output formats.
fasmg itself is
implemented in x86 assembly, that doesn't mean it will expire soon
as Apple has moved a step forward to ARM, as there is still x86
emulation with macOS, and since
only used a small subset of x86 writing a emulator is not a
difficult task, besides the community of
fasmg is also thriving.
There are not as much x86 assembly programming tutorial for OS X
compared to Linux or even Windows. Most of the existing tutorials
are dated, using the
nasm instead of
the default available
gas, and they
didn't even bother to explain the differences in system call and
So, this is an example of the standard "Hail the world" for 64bit macOS.
format MachO64 executable|
entry start5 |
import exit,'_exit'10 |
segment '__TEXT' readable executable|
section '__text' align 16|
mov rax,02000004h15 |
mov rax,02000001h20 |
segment '__DATA' readable writable|
section '__data' align 4|
db "Hello, World!", 10
The standard distribution has the
selfhost.inc file that can be almost directly
used for x86_64 macOS assembly programming. It is just the file
path needs to be modified to work properly. The line that has
import is not used but it is important to have it sit
there to generated the
segment otherwise it won't be treated as valid Mach-O executable.
You do can build the
segment by self.
System calls has offset
4 is write. They are available from
<sys/syscall.h> if you have installed macOS
fasmg on the file
will produce the Mach-O binary. Just remember to
chmod it and you are done.