0

asm file

section .data
    message db 'Hello, World!',0

section .text
    global _start

_start:
    mov eax, 4        ; write syscall number
    mov ebx, 1        ; stdout file descriptor
    mov ecx, qword [message]  ; address of message
    mov edx, 13       ; length of message
    int 0x80          ; invoke syscall

    mov eax, 1        ; exit syscall number
    xor ebx, ebx      ; exit status
    int 0x80          ; invoke syscall

command

  1. yasm -f macho64 hello.asm -o hello
  2. chomd +x
  3. result -bash: ./hello: cannot execute binary file

I am using macOS m1 Ventura 13.1(22C65)

is there any solution

meBe
  • 154
  • 9
  • 1
    First of all, that source code is for 32-bit x86 Linux; no matter how you build it, it won't run on recent MacOS, which dropped support for 32-bit executables. Second, YASM only assembles, to make a `.o`. You forgot to link (with `gcc -nostdlib -static hello.o -o hello` if you were on Linux). – Peter Cordes Jan 01 '23 at 10:33
  • 1
    Also, that isn't the code you assembled; if you tried, it would reject `mov ecx, qword [message]` as an operand-size mismatch; you can't load 64 bits into a 32-bit register. Maybe you meant `mov rcx, strict qword message` to use a 64-bit absolute address (instead of an efficient RIP-relative LEA), but `int 0x80` will ignore the high 32 bits even in 64-bit code. [What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?](https://stackoverflow.com/q/46087730) – Peter Cordes Jan 01 '23 at 10:34
  • 1
    See [Hello World using x86 assembler on Mac 0SX](https://stackoverflow.com/q/4288921) for x86-64 MacOS hello world. – Peter Cordes Jan 01 '23 at 10:35

0 Answers0