<p>Does anyone know of any good tools (I'm looking for IDEs) to write assembly on the Mac. Xcode is a little cumbersome to me.</p>

<p>Also, on the Intel Macs, can I use generic x86 asm?  Or is there a modified instruction set? Any information about post Intel.</p>

<p>Also: I know that on windows, asm can run in an emulated environment created by the OS to let the code think it's running on its own dedicated machine. Does OS X provide the same thing?</p>

[{'answer_id': 5661, 'author': 'Josh', 'author_id': 257, 'author_profile': 'https://Stackoverflow.com/users/257', 'pm_score': 3, 'selected': False, 'text': "<blockquote>\n  <p>Also, on the Intel Macs, can I use generic x86 asm? or is there a modified instruction set? Any information about post Intel Mac assembly helps.</p>\n</blockquote>\n\n<p>It's the same instruction set; it's the same chips.</p>\n"}, {'answer_id': 5665, 'author': 'Bernard', 'author_id': 61, 'author_profile': 'https://Stackoverflow.com/users/61', 'pm_score': 1, 'selected': False, 'text': "<p>The features available to use are dependent on your processor. Apple uses the same Intel stuff as everybody else. So yes, generic x86 should be fine (assuming you're not  on a PPC :D).</p>\n\n<p>As far as tools go, I think your best bet is a good text editor that 'understands' assembly.</p>\n"}, {'answer_id': 5698, 'author': 'Stephen Cox', 'author_id': 534, 'author_profile': 'https://Stackoverflow.com/users/534', 'pm_score': 0, 'selected': False, 'text': '<p>Forget about finding a IDE to write/run/compile assembler on Mac. But, remember mac is UNIX. See <a href="http://asm.sourceforge.net/articles/linasm.html" rel="nofollow noreferrer">http://asm.sourceforge.net/articles/linasm.html</a>. A decent guide (though short) to running assembler via GCC on Linux. You can mimic this. Macs use Intel chips so you want to look at Intel syntax.</p>\n'}, {'answer_id': 5756, 'author': 'Chris Hanson', 'author_id': 714, 'author_profile': 'https://Stackoverflow.com/users/714', 'pm_score': 7, 'selected': True, 'text': '<p>After installing any version of Xcode targeting Intel-based Macs, you should be able to write assembly code.  Xcode is a suite of tools, only one of which is the IDE, so you don\'t have to use it if you don\'t want to.  (That said, if there are specific things you find clunky, please file a bug at <a href="http://bugreport.apple.com/" rel="noreferrer" title="Apple&#39;s bug reporter">Apple\'s bug reporter</a> - every bug goes to engineering.)  Furthermore, installing Xcode will install both the Netwide Assembler (NASM) and the GNU Assembler (GAS); that will let you use whatever assembly syntax you\'re most comfortable with.</p>\n\n<p>You\'ll also want to take a look at the <a href="https://developer.apple.com/library/mac/documentation/CompilerTools/Conceptual/LLVMCompilerOverview/index.html#//apple_ref/doc/uid/TP40010019" rel="noreferrer" title="Compiler &amp; Debugging Guides">Compiler &amp; Debugging Guides</a>, because those document the calling conventions used for the various architectures that Mac OS X runs on, as well as how the binary format and the loader work.  The IA-32 (x86-32) calling conventions in particular may be slightly different from what you\'re used to.</p>\n\n<p>Another thing to keep in mind is that the system call interface on Mac OS X is different from what you might be used to on DOS/Windows, Linux, or the other BSD flavors.  System calls aren\'t considered a stable API on Mac OS X; instead, you always go through libSystem.  That will ensure you\'re writing code that\'s portable from one release of the OS to the next.</p>\n\n<p>Finally, keep in mind that Mac OS X runs across a pretty wide array of hardware - everything from the 32-bit Core Single through the high-end quad-core Xeon.  By coding in assembly you might not be optimizing as much as you think; what\'s optimal on one machine may be pessimal on another.  Apple regularly measures its compilers and tunes their output with the "-Os" optimization flag to be decent across its line, and there are extensive vector/matrix-processing libraries that you can use to get high performance with hand-tuned CPU-specific implementations.</p>\n\n<p>Going to assembly for fun is great.  Going to assembly for speed is not for the faint of heart these days.</p>\n'}, {'answer_id': 357113, 'author': 'David DeHaven', 'author_id': 45095, 'author_profile': 'https://Stackoverflow.com/users/45095', 'pm_score': 5, 'selected': False, 'text': '<p>As stated before, don\'t use syscall. You can use standard C library calls though, but be aware that the stack MUST be 16 byte aligned per Apple\'s <a href="https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html" rel="noreferrer">IA32 function call ABI</a>.</p>\n\n<p>If you don\'t align the stack, your program will crash in <code>__dyld_misaligned_stack_error</code> when you make a call into any of the libraries or frameworks.</p>\n\n<p>The following snippet assembles and runs on my system:</p>\n\n<pre><code>; File: hello.asm\n; Build: nasm -f macho hello.asm &amp;&amp; gcc -o hello hello.o\n\nSECTION .rodata\nhello.msg db \'Hello, World!\',0x0a,0x00\n\nSECTION .text\n\nextern _printf ; could also use _puts...\nGLOBAL _main\n\n; aligns esp to 16 bytes in preparation for calling a C library function\n; arg is number of bytes to pad for function arguments, this should be a multiple of 16\n; unless you are using push/pop to load args\n%macro clib_prolog 1\n    mov ebx, esp        ; remember current esp\n    and esp, 0xFFFFFFF0 ; align to next 16 byte boundary (could be zero offset!)\n    sub esp, 12         ; skip ahead 12 so we can store original esp\n    push ebx            ; store esp (16 bytes aligned again)\n    sub esp, %1         ; pad for arguments (make conditional?)\n%endmacro\n\n; arg must match most recent call to clib_prolog\n%macro clib_epilog 1\n    add esp, %1         ; remove arg padding\n    pop ebx             ; get original esp\n    mov esp, ebx        ; restore\n%endmacro\n\n_main:\n    ; set up stack frame\n    push ebp\n    mov ebp, esp\n    push ebx\n\n    clib_prolog 16\n    mov dword [esp], hello.msg\n    call _printf\n    ; can make more clib calls here...\n    clib_epilog 16\n\n    ; tear down stack frame\n    pop ebx\n    mov esp, ebp\n    pop ebp\n    mov eax, 0          ; set return code\n    ret\n</code></pre>\n'}, {'answer_id': 17800896, 'author': 'Jared Burrows', 'author_id': 950427, 'author_profile': 'https://Stackoverflow.com/users/950427', 'pm_score': 3, 'selected': False, 'text': '<p>Recently I wanted to learn how to compile Intel x86 on Mac OS X:</p>\n<h3>For nasm:</h3>\n<pre><code>-o hello.tmp - outfile\n-f macho - specify format\nLinux - elf or elf64\nMac OSX - macho\n</code></pre>\n<h3>For ld:</h3>\n<pre><code>-arch i386 - specify architecture (32 bit assembly)\n-macosx_version_min 10.6 (Mac OSX - complains about default specification)\n-no_pie (Mac OSX - removes ld warning)\n-e main - specify main symbol name (Mac OSX - default is start)\n-o hello.o - outfile\n</code></pre>\n<h3>For Shell:</h3>\n<pre><code>./hello.o - execution\n</code></pre>\n<h3>One-liner:</h3>\n<pre><code>nasm -o hello.tmp -f macho hello.s &amp;&amp; ld -arch i386 -macosx_version_min 10.6 -no_pie -e _main -o hello.o hello.tmp &amp;&amp; ./hello.o\n</code></pre>\n<p>Let me know if this helps!</p>\n<p>I wrote how to do it on my blog here:</p>\n<p><a href="http://blog.burrowsapps.com/2013/07/how-to-compile-helloworld-in-intel-x86.html" rel="noreferrer">http://blog.burrowsapps.com/2013/07/how-to-compile-helloworld-in-intel-x86.html</a></p>\n<p>For a more verbose explanation, I explained on my Github here:</p>\n<p><a href="https://github.com/jaredsburrows/Assembly" rel="noreferrer">https://github.com/jaredsburrows/Assembly</a></p>\n'}, {'answer_id': 48446402, 'author': 'Akhzar Nazir', 'author_id': 8080276, 'author_profile': 'https://Stackoverflow.com/users/8080276', 'pm_score': 3, 'selected': False, 'text': '<p>Running assembly Code on Mac is just 3 steps away from you. It could be done using XCODE but better is to use NASM Command Line Tool.\nFor My Ease I have already installed Xcode, if you have Xcode installed its good.</p>\n\n<p>But You can do it without XCode as well.</p>\n\n<p>Just Follow:</p>\n\n<ol>\n<li>First Install NASM using Homebrew <code>brew install nasm</code></li>\n<li>convert .asm file into Obj File using this command <code>nasm -f macho64 myFile.asm</code></li>\n<li>Run Obj File to see OutPut using command <code>ld -macosx_version_min 10.7.0 -lSystem -o OutPutFile myFile.o &amp;&amp; ./64</code></li>\n</ol>\n\n<p>Simple Text File named myFile.asm is written below for your convenience.</p>\n\n<pre><code>global start\nsection .text\n\nstart:\n    mov     rax, 0x2000004 ; write\n    mov     rdi, 1 ; stdout\n    mov     rsi, msg\n    mov     rdx, msg.len\n    syscall\n\n    mov     rax, 0x2000001 ; exit\n    mov     rdi, 0\n    syscall\n\nsection .data\n\nmsg:    db      "Assalam O Alaikum Dear", 10\n.len:   equ     $ - msg\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/5649', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/703/']