如果我有一个格式字符串是这样的:臂组件传递一个字符串作为参数
fmtPrintSphere:.string "Sphere %s\n"
.global main
.balign 4
和其他格式的字符串这样
fmtName1:.string "First"
.global main
.balign 4
当我打电话的拳头之一,我该怎么办添加第二个字符串作为参数?即
adrp x0, fmtPrintSphere
add x0, x0, :lo12:fmtPrintSphere
mov x1, fmtName1 <-- this causes a segmentation fault
bl 'printf'
UPDATE: 这是我如何调用该函数
add x0, x29, fmtName1
add x1, x29, origin_offset
bl printSphere
这是我迄今为止在功能
printSphere:
stp x29, x30, [sp, alloc]!
mov x29, sp
mov x1, x0
adrp x0, fmtPrintSphere
add x0, x0, :lo12:fmtPrintSphere
bl printf
mov w0, 0
ldp x29, x30, [sp], -alloc
ret
这不会引发任何错误但输出正好:Sphere 应该是:Sphere First
UPDATE X2: 这是我想要做的一个例子 -
void printSphere(char *name, struct sphere *s){
printf("Sphere %s origin = (%d, %d, %d) radius = %d\n", name, s->origin.x, s->origin.x, s->origin.y, s->rad)
}
输入: printSphere( “someName”,$ sphereStruct)
输出: 球someName =(2,3,4)半径= 10
什么'fmtName'(不是 “不'fmtName1'” 等)? – Notlikethat
对不起,这是一个错字它应该是fmtName1,我会改变这种情况,该函数可以将fmtName1或fmtName2作为第一个参数 – Sentinel