News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Intel Assember for the Macintosh ?

Started by James Ladd, December 21, 2007, 02:33:17 AM

Previous topic - Next topic

James Ladd

Has anyone written assember for the intel chip and then run the program on a Macintosh, maybe
calling some of that OS libraries?

u

Please use a smaller graphic in your signature.

Rockoon

I'm sure GAS is ported.. tho it uses AT&T syntax if I am not mistaken
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

Synfire

NASM supports Mac, has for a while. Do you mean something like this:

; Build with:
;  nasm -f macho hello.asm
;  ld -e _start -o hello hello.o

; Some stuff from BKMACROS.INC to make things pretty. (optional)
%define T tword
%define Q qword
%define D dword
%define W word
%define B byte

%idefine TWORD_size 10
%idefine QWORD_size 8
%idefine DWORD_size 4
%idefine WORD_size  2
%idefine BYTE_size  1

%idefine SIZEOF(x) x %+ _size

; A simple macro for calling system calls on one line. (optional)
%imacro FREEBSD 1+
%define _proc %1
%rep %0-1
%rotate -1
PUSH %1
%endrep
MOV EAX, _proc
CALL FREEBSD_SYSCALL
%endmacro

; a few FreeBSD system call definitions
%define SYS_WRITE 0x4
%define SYS_EXIT 0x1
%define STDOUT 1

SECTION .DATA
Msg DB "Hello, World!", 10
Len EQU $ - Msg

SECTION .TEXT
GLOBAL _START

; FreeBSD likes us to call our kernel through a procedure.
FREEBSD_SYSCALL:
INT 0x80
RET

; Program entrypoint
_START:
; Display a message
FREEBSD SYS_WRITE, D STDOUT, D Msg, D Len
ADD ESP, 3*SIZEOF(DWORD) ; clean up stack

; Exit to FreeBSD/Mac OS
FREEBSD SYS_EXIT, D 0
; No need to clean up stack because the program has already stopped.


You could also import routines from LibC and call them through NASM like _printf, _exit, and the rest. The lastest NASM 2.0 now also suports 64-bit support on the OSX.