如何使用“printf"树莓派汇编语言 [英] How to use "printf" in raspberry pi assembly language

查看:30
本文介绍了如何使用“printf"树莓派汇编语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

printf 对可以打印的值的数量有限制吗?

Does printf has a limit to the number of values you can print?

这是我的代码.

.data
.balign 4       
   string: .asciz "\n%d %d %d %d\n"        
.text
.global main
.extern printf

main:
    push    {ip, lr}        @ push return address + dummy register
                            @ for alignment
    ldr     r0, =string     @ get address of string into r0
    mov     r1, #11
    mov     r2, #22
    mov     r3, #33
    mov     r4, #444
    bl      printf          @ print string and pass params
                            @ into r1, r2, and r3
    pop     {ip, pc}        @ pop return address into pc

当我编译并执行这段代码时,它会打印:

When I compile and execute this code it prints this:

11 22 33 1995276288

11 22 33 1995276288

如您所见,R4 中的值没有打印正确的值.

As you can see, the value in R4 does not print the right value.

我不知道为什么?

推荐答案

只有前 4 个参数在 ARM 上的寄存器 (r0-r3) 中传递——任何额外的参数都在堆栈上传递.查看过程调用ABI 了解详情.

Only the first 4 arguments are passed in registers (r0-r3) on the ARM -- any additional args are passed on the stack. Check out the procedure call ABI for details.

这篇关于如何使用“printf"树莓派汇编语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆