Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly GUI programming for Mac OS X

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

like image 287
jose.pereira Avatar asked Mar 26 '11 22:03

jose.pereira


People also ask

Can you write assembly on Mac?

To get started on writing OSX assembly, you need to understand OSX executable file format – the Mach-O file format. It's similar to ELF, but instead of sections of data, bss, and text, it has segments that contains sections. Mach-O is pretty flexible.

Can you write a GUI in assembly?

You can create GUI applications in assembly for Windows, for Linux or for any other OS with graphical user interface.

Does Apple use assembly language?

Summary. The new Apple M1 Macintoshes are running ARM processors as part of all that Apple Silicon and you can run standard ARM 64-bit Assembly Language. LLVM is a standard open source development tool which contains an Assembler that is similar to the GNU Assembler.


1 Answers

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

like image 160
Monolo Avatar answered Oct 04 '22 03:10

Monolo