Arm instance One

Source: Internet
Author: User
Arm Instance One

On the basis of U-boot, a program is programmed to invoke the custom function in assembly language.

Inline assembly formats with C/W + + expressions are:

__asm__ __volatile__ ("instruction List": output:input:clobber/modify);

The concepts and functional usage of each of these are described below:
1, __asm__
ASM is a macro definition of the GCC keyword ASM:

#define __ASM__ ASM

__asm__ or ASM is used to declare an inline assembly expression, so any inline assembly expression begins with it and is essential.
2. Instruction List
The instruction List is a sequence of assembly instructions. It can be empty, for example: __asm__ __volatile__ (""); or __asm__ (""); all are fully legal inline assembly expressions, but these two statements have little meaning. However, not all inline assembly expressions that are empty by instruction List are meaningless, such as: __asm__ (""::: "Memory");
3. __volatile__
__VOLATILE__ is a macro definition for the GCC keyword volatile

#define __VOLATILE__ Volatile

__volatile__ or volatile is optional. If it is used, it is declared to GCC not allowed to optimize the inline assembly, otherwise when compiling with the optimization option (-O), GCC will decide whether to optimize the instructions in this inline assembly expression.
4. Output
Output used to specify the outputs of the current inline assembly statement BL is the instruction used in the ARM assembly to invoke the subroutine, to return the address, which puts the address of the next instruction in the BL to the R14 register, and the R15 register (the current pointer address of the PC) is set to the address to jump to. This way, when the subroutine returns, the Mov pc,r14 can return to the address behind the BL.

B is not the same, B is a direct MOV PC, the destination address; For jumps that do not return, do not save the subsequent address to R14.

Query U-boot.map Get the address of the function that needs to be called

sudo vim U-boot.map


-Instance Code:

void (*my_print) (const char *fmt,...);
    /function pointer int _start (void) {int a,b,c,d;
    my_print= (void *) 0x33f963a8;//u-boot the address of the printf function in My_print ("1.in%s:before bl\n", __func__); __VOLATILE__: Prevent compiler optimizations __asm__ __volatile__ (//ASSEMBLY statement block "BL target\n" "BL my_func\n" "
    Target:\n ");
    My_print ("3,in%s:after bl\n", __func__);
return 0; } void My_func (void) {My_print ("2,in%s\n", __func__);//__func__: Printing the current function name} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.