我想知道如何在Mac OS X上编写一个简单的汇编程序,显示一个窗口并在窗口上放一些彩色文本。代码可能会调用一些Carbon或Cocoa API。我需要一些nasm语法的代码。
我在http://snipplr.com/view/29150/assembly-code-nasm-for-mac--hello-world中看到了下面的代码,它可以正常工作,但不是图形化的。
我在http://snipplr.com/view/29150/assembly-code-nasm-for-mac--hello-world中看到了下面的代码,它可以正常工作,但不是图形化的。
; Mac上汇编实现Hello World ; ; nasm -f macho hello.asm ; ld -e _start -o hello hello.o感谢任何帮助。
section .text global _start ;必须为链接器(ld)声明
_syscall: int 0x80 ;系统调用 ret
_start: ;告诉链接器入口点
push dword len ;消息长度 push dword msg ;要写入的消息 push dword 1 ;文件描述符(stdout) mov eax,0x4 ;系统调用号(sys_write) call _syscall ;调用内核
add esp,12 ;清除堆栈(3个参数*4)
push dword 0 ;退出码 mov eax,0x1 ;系统调用号(sys_exit) call _syscall ;调用内核
;我们不从sys_exit返回, ;没有必要清理堆栈 section .data
msg db "Hello, world!",0xa ;我们亲爱的字符串 len equ $ - msg ;我们亲爱的字符串的长度