Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:55:15+00:00 2026-05-27T09:55:15+00:00

I’m writing code targeting ARM Cortex-A on Android devices (using GNU assembler and compiler),

  • 0

I’m writing code targeting ARM Cortex-A on Android devices (using GNU assembler and compiler), and I’m trying to interface between Assembly and C. In particular, I’m interested in calling functions written in C from Assembly. I tried many things, including the .extern directive, declaring C functions with asm and __asm__ and so on, but none of them worked, so I’m looking for a minimal example of doing so. A reference to such example would be just as welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:55:15+00:00Added an answer on May 27, 2026 at 9:55 am

    You need to read the ARM ARM and/or know the instruction set is all, normally you would want to do something like this

    asm:
    
    bl cfun
    
    c:
    void cfun ( void )
    {
    
    }
    

    You can try this yourself. for gnu as and gcc this works just fine it should also work just fine if you use clang to get the c code to an object and gnu as for assembler. Not sure what you are using.

    The problem with the above is bl has a limited reach,

    if ConditionPassed(cond) then
      if L == 1 then
        LR = address of the instruction after the branch instruction
        PC = PC + (SignExtend_30(signed_immed_24) << 2)
    

    knowing that the bl instruction sets the link register to the instruction after the bl instruction, then if you read about the program counter register:

    For an ARM instruction, the value read is the address of the instruction
    plus 8 bytes. Bits [1:0] of this
    value are always zero, because ARM instructions are always word-aligned.
    

    so if you make your asm look like this:

    mov lr,pc
    ldr pc,=cfun
    

    you get

    d6008034:   e1a0e00f    mov lr, pc
    d6008038:   e51ff000    ldr pc, [pc, #-0]   ; d6008040 
    ...
    d6008040:   d60084c4    strle   r8, [r0], -r4, asr #9
    

    The assembler will reserve a memory location, within reach of the ldr pc, instruction (if possible, otherwise generate an error) where it will place the full 32 bit address for the instruction. the linker will later fill in this address with the external address. that way you can reach any address in the address space.

    if you dont want to play assembler games like that and want to be in control then you create the location to keep the address of the function and load it into the pc yourself:

        mov lr,pc
        ldr pc,cfun_addr
    
    ...
    
    cfun_addr:
        .word cfun
    

    compiled:

    d6008034:   e1a0e00f    mov lr, pc
    d6008038:   e51ff000    ldr pc, [pc, #-0]   ; d6008040 <cfun_addr>
    ...
    
    d6008040 <cfun_addr>:
    d6008040:   d60084c4    strle   r8, [r0], -r4, asr #9
    

    Lastly if you want to move into the modern ARM world where ARM and thumb is mixed or can be (for example use bx lr instead of mov pc,lr) then you will want to use bx

        add lr,pc,#4
        ldr r1,cfun_addr
        bx r1
    ...
    
    cfun_addr:
        .word cfun
    

    of course you need another register to do that and remember to push and pop your link register and the other register before and after your call to C if you want to preserve them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.