Mac OS X 的汇编 GUI 编程
我想知道如何为 Mac OS X 编写一个简单的汇编程序,在屏幕上显示一个窗口并在该窗口上放置一些彩色文本。该代码可能会调用一些 Carbon 或 Cocoa API。我需要一些 nasm sintaxe 的代码。
我在 http://snipplr.com/view 中看到/29150/assemble-code-nasm-for-mac--hello-world 下一个代码可以正常工作,但它不是图形。
; Hello World in assembly for mac ; ; nasm -f macho hello.asm ; ld -e _start -o hello hello.o section .text global _start ;must be declared for linker (ld) _syscall: int 0x80 ;system call ret _start: ;tell linker entry point push dword len ;message length push dword msg ;message to write push dword 1 ;file descriptor (stdout) mov eax,0x4 ;system call number (sys_write) call _syscall ;call kernel add esp,12 ;clean stack (3 arguments * 4) push dword 0 ;exit code mov eax,0x1 ;system call number (sys_exit) call _syscall ;call kernel ;we do not return from sys_exit, ;there's no need to clean stack section .data msg db "Hello, world!",0xa ;our dear string len equ $ - msg ;length of our dear string
感谢您的帮助
I’d like to know how can I do a simple assembly program for Mac OS X that shows a window on the screen and put some coloured text on that window. The code may call some Carbon or Cocoa APIs. I need some code for the nasm sintaxe.
I saw in http://snipplr.com/view/29150/assembly-code-nasm-for-mac--hello-world the next code that works fine, but it´s not graphic.
; Hello World in assembly for mac ; ; nasm -f macho hello.asm ; ld -e _start -o hello hello.o section .text global _start ;must be declared for linker (ld) _syscall: int 0x80 ;system call ret _start: ;tell linker entry point push dword len ;message length push dword msg ;message to write push dword 1 ;file descriptor (stdout) mov eax,0x4 ;system call number (sys_write) call _syscall ;call kernel add esp,12 ;clean stack (3 arguments * 4) push dword 0 ;exit code mov eax,0x1 ;system call number (sys_exit) call _syscall ;call kernel ;we do not return from sys_exit, ;there's no need to clean stack section .data msg db "Hello, world!",0xa ;our dear string len equ $ - msg ;length of our dear string
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是前面答案中评论中所要求的 Carbon,但它可能会帮助您在崇高的追求中更进一步:
http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
This is not Carbon as requested in the comments in the previous answers, but it may help you get a step further ahead in your noble pursuit:
http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
您可以使用
call
调用 Carbon API,如下所示:您也可以传递参数,但我不确定如何执行此操作。可能在
调用
之前以相反的顺序推入
堆栈:您可以查看 C 代码如何编译成程序集,如下所示:
You can call Carbon APIs with
call
like this:You can pass arguments also, but I'm unsure how to do that. Probably
push
ed onto the stack in reversed order just before thecall
:You can look in how you C code compiles into assembly, like this: