Post

Replies

Boosts

Views

Activity

Reply to Apple Silicon calling printf
Thank you! Just figured this out. Much appreciated!!!!! This was my solution, mov w2, w20 // Prepare printf arguments // x0 = format string. x0 // w1 = i w20 // w2 = element i w1 #if defined(__APPLE__) // Apple Silicon store decimals stp X2, X1 , [SP, #-16]! bl _printf ldp X2, X1, [SP], #16 #else bl printf #endif Here is the desired output. ❯ ./a.out Through all my reading, Linux and Pi pass through registers and Apple Silicon pass on the stack (reverse order). Are there Apple Docs on this somewhere?
Topic: Programming Languages SubTopic: General Tags:
1d
Reply to Apple Silicon calling printf
#if defined(__APPLE__) .global _main // Provide program starting address to linker Mac OS _main: #else .global main // Raspian and Linux main: #endif // stack frame work setup START stp x29, x30, [sp, -16]! str x20, [sp, -16]! mov x29, sp // stack frame work setup END // setup printf call #if defined(__APPLE__) adrp x0, fOutputStr@PAGE add x0, x0, fOutputStr@PAGEOFF #else ldr x0, =fOutputStr #endif mov w1, #4 mov w2, #9 print_brk: #if defined(__APPLE__) stp X0, X1, [SP, #-16]! stp X2, X3, [SP, #-16]! bl _printf ldp X2, X3, [SP], #16 ldp X0, X1, [SP], #16 #else bl printf #endif done: // closing stack frame work ldr x20, [sp],16 ldp x29, x30, [sp],16 // exit mov w0, wzr ret .data .align 4 // intArrayPtr: .word 3,7,5,2,4,8 // word, each value is offset by 4 fOutputStr: .asciz "Element[%d] = %d\n" // formated output string
Topic: Programming Languages SubTopic: General Tags:
1d