What is the proper way to pass arguments to printf with multiple variables using ARM64 Apple Silicon? Example: fOutputStr: .asciz "Element[%d] = %d\n" // formated output string
for an output of: Element[4] = 9 This code (see below) works on Raspberry Pi 5, on my Mac Studio, I am getting this output,
Element[9] = 1871655168
What do I need to do to use printf from an assembly language call with multiple variables?
I am using the following code. ` .align 2 // memory alignment model for 64-bit ARMc
#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