适用于Mac OS X的汇编GUI编程

时间:2011-03-26 22:48:33

标签: cocoa macos assembly macos-carbon

我想知道如何为Mac OS X做一个简单的汇编程序,它在屏幕上显示一个窗口并在该窗口上放置一些彩色文本。代码可能会调用一些Carbon或Cocoa API。我需要一些针对nasm sintaxe的代码。

我在http://snipplr.com/view/29150/assembly-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 

感谢您的帮助

2 个答案:

答案 0 :(得分:2)

这不是前面答案评论中要求的碳,但它可以帮助你在你的崇高追求中更进一步:

http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html

答案 1 :(得分:0)

您可以使用call调用Carbon API,如下所示:

call _CreateNewWindow

你也可以传递参数,但我不确定如何做到这一点。在push

之前,可能会以相反的顺序call进入堆栈
push arg4
push arg3
push arg2
push arg1
call _CreateNewWindow

您可以查看C代码如何编译成程序集,如下所示:

$ clang myCarbonCode.c -S -O -o myCarbonCode.s
相关问题