jos*_*ira 13 macos assembly cocoa 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
谢谢你的帮助
小智 0
您可以像这样调用 Carbon API call
:
call _CreateNewWindow
Run Code Online (Sandbox Code Playgroud)
您也可以传递参数,但我不确定该怎么做。可能push
在以下之前以相反的顺序入栈call
:
push arg4
push arg3
push arg2
push arg1
call _CreateNewWindow
Run Code Online (Sandbox Code Playgroud)
您可以查看 C 代码如何编译成汇编,如下所示:
$ clang myCarbonCode.c -S -O -o myCarbonCode.s
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3036 次 |
最近记录: |