This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Calling Printf or other C functions

Note: This was originally posted on 24th June 2009 at http://forums.arm.com

Hello all,

Processor : ARM Cortex A8
Toolchain: Codesourcery ARM GCC
Version: gcc version 4.2.3 (Sourcery G++ Lite 2008q1-126)

Query: We wanted to know how to call standard C library functions from ASM. For instance Printf or other custom C functions.

Or is there a printing utility in asm, which could be used.
thanks and regards
pachu
Parents
  • Note: This was originally posted on 25th June 2009 at http://forums.arm.com

    Pachu,

    The following should work:
      .cpu cortex-a8
      .text
      .align  2
      .global myfunc
      .type   myfunc, %function
    myfunc:
      stmfd   sp!, {r4, lr} @ preserve LR, keep SP aligned
      adr  r0, mystring  @ point first param to string
      mov  r1, #123   @ set second param to 123
      bl   printf  @ call printf
      ldmfd   sp!, {r4, lr} @ restore LR and R4
      bx   lr   @ return from this function
      .data
    mystring:
      .ascii  "Test %d\n\0" @ nul terminated string
      .size   myfunc,. -myfunc


    hth
    s.


    Hello Sim,
                   thanks for the reply. I shall try it out.
    i shall reply back once i have tested the code.

    thanks and regards
Reply
  • Note: This was originally posted on 25th June 2009 at http://forums.arm.com

    Pachu,

    The following should work:
      .cpu cortex-a8
      .text
      .align  2
      .global myfunc
      .type   myfunc, %function
    myfunc:
      stmfd   sp!, {r4, lr} @ preserve LR, keep SP aligned
      adr  r0, mystring  @ point first param to string
      mov  r1, #123   @ set second param to 123
      bl   printf  @ call printf
      ldmfd   sp!, {r4, lr} @ restore LR and R4
      bx   lr   @ return from this function
      .data
    mystring:
      .ascii  "Test %d\n\0" @ nul terminated string
      .size   myfunc,. -myfunc


    hth
    s.


    Hello Sim,
                   thanks for the reply. I shall try it out.
    i shall reply back once i have tested the code.

    thanks and regards
Children
No data