3

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

Here is my code.

.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

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

I don't know why?

1
  • 1
    Because only the first 4 arguments are passed in registers. Sounds like you forgot to read the calling convention documentation. Commented Nov 5, 2016 at 19:15

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That explains the problem. Thanks
@DanielRobertWebb: then you should click the checkmark on this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.