0

I tried using _printf to print a message but it doesn't print the message without a \n at the end of the message

.global _main
.p2align 2

.equ SYS_WRITE, 4
.equ SYS_READ, 3
.equ SYS_EXIT, 1

_main:
    adr x0, message
    bl _printf

    // Exit the program
    mov x0, #0               // System call number for exit
    mov x16, SYS_EXIT        // System call for exit
    svc #0

message:
    .string "Hello, World!"

it doesn't print the string

I have found that passing an argument into a string with \n at the end works

.global _main
.p2align 2

.equ SYS_WRITE, 4
.equ SYS_READ, 3
.equ SYS_EXIT, 1

_main:
    adr x0, fmt
    adr x22, message
    str x22, [sp]
    bl _printf

    // Exit the program
    mov x0, #0               // System call number for exit
    mov x16, SYS_EXIT        // System call for exit
    svc #0

message:
    .string "Hello, World!"
fmt:
    .string "%s\n"

the command I use to assemble and link is as file.s -o file.o && ld -o file file.o -lSystem -syslibroot xcrun -sdk macosx --show-sdk-path -e _main -arch arm64 && ./file

073
  • 13
  • 4
  • 1
    `bl _exit` instead of `svc` when you're using stdio functions that might still have buffered output. IDK why you added this to the reopen queue; it's a duplicate of existing questions about printf line-buffering. – Peter Cordes Apr 24 '23 at 04:20

0 Answers0