http://www.cotyrmiller.com > rants > MacOS_64bit_nasm_woes

 

MacOS 64bit nasm woes.


Over the past weekend I got back into coding assembly, I was bit out of touch and hadn’t written assembly code since my switch to using a Mac. So naturally I fired up nano and started writing some 32bit assembly code. With much success I decided that I would then move on to 64bit code, why not? 32bit is basically legacy at this point and probably wont be fully supported in macOS in the future.


So I looked up a tutorial on writing 64bit assembly in nasm got it together and when to assemble it with the recommended nasm -f macho64 adventure64.asm and lo and behold macho64 was not supported… 


Checking the nasm version I saw it was version:


NASM version 0.98.40 (Apple Computer, Inc. build 11) compiled on May  2 2018


What? Nasm is at version 2! Why is this so old? No wonder it wont assemble… So naturally I I ran brew upgrade nasm for those of you unaware of brew here is a link to it’s home page:


https://brew.sh


After running brew, brew reported NASM as “up-to-date” well… That’s not right? NASM IS AT VERSION 2! So after allot of hair pulling a googling it turns out that macOS actually has 2 versions of nasm installed.


“nasm” — version 0.98.40 for legacy application support.

“NASM” — ALL CAPS is the fully up-to-date “ NASM version 2.13.03 compiled on Feb  8 2018” 


And of course the legacy version of nasm does not support 64bit assembly! This actually makes allot of sense now that I know this. It’s just something if you don’t know then it’s going to be a pain. I hope to continue writing in assembly for at least a while, but now here is whatever I wrote, hopefully with more to come.


global start

section .text


start:

mov rsi, msg

mov rdx, msg.len

call print

exit:

mov rax, ints.exit

mov rdi, 0

syscall


print:

push rax

push rdi

mov rax, ints.write

mov rdi, 1 ; stdout

syscall

pop rdi

pop rax

ret



section .data

ints:

.exit equ 0x2000001

.write equ 0x2000004


msg: db "Hello, World!", 10

.len: equ $ - msg



Compiles with “make64”.


NASM -f macho64 adventure64.asm && ld -macosx_version_min 10.7.0 -lSystem -o adventure64 adventure64.o && ./adventure64


Until next time, Coty out!