【发布时间】:2011-07-23 16:25:24
【问题描述】:
我想知道如何为 Mac OS X 编写一个简单的汇编程序,在屏幕上显示一个窗口并在该窗口上放置一些彩色文本。代码可能会调用一些 Carbon 或 Cocoa API。我需要一些 nasm sintaxe 的代码。
我在http://snipplr.com/view/29150/assembly-code-nasm-for-mac--hello-world 看到了下一个可以正常工作的代码,但它不是图形。
;用于 mac 的程序集中的 Hello World ; ; nasm -f macho hello.asm ; ld -e _start -o 你好你好.o 部分 .text global _start ;必须为链接器(ld)声明 _系统调用: int 0x80 ;系统调用 ret _start: ;告诉链接器入口点 push dword len ;消息长度 push dword msg ;要写入的消息 push dword 1 ;文件描述符(标准输出) mov eax,0x4 ;系统调用号(sys_write) call _syscall ;调用内核 add esp,12 ;clean stack (3 arguments * 4) push dword 0 ;退出代码 mov eax,0x1 ;系统调用号(sys_exit) call _syscall ;调用内核 ;我们不从 sys_exit 返回, ;无需清理堆栈 节 .data msg db "Hello, world!",0xa ;我们亲爱的字符串 len equ $ - msg ; 我们亲爱的字符串的长度感谢您的帮助
【问题讨论】:
-
+1 用于 Mac OS X 中的核心汇编 GUI 编程。祝你好运。
-
另外,如果你想使用 Cocoa,你可能想看看 Objective-C 运行时参考。
-
我强烈建议反对尝试直接从程序集中使用objective-c。如果不尝试创建自己的类,只是获取类和创建实例是很困难的。
标签: cocoa macos assembly macos-carbon