How do you invoke the variables in the assembly in C language? __c language

Source: Internet
Author: User
How to invoke variables in the assembly in C language.


Assembly language: Declaring a global variable


. Globl _end_ofs
_end_ofs:
. Word _end-_start


C language: Declare the variable, and then call the variable
void Board_init_r (gd_t *id, ulong dest_addr)
{
...............


Monitor_flash_len = _end_ofs;//_end_ofs is declared in another header file, so this function does not have to be declared


....................
}


-----------------------------------------------------------------------------------------


Usage:The stack address in C language is passed to the Assembly (when porting uboot, it may be used)


Assembly:


. Globl base_sp//define and declare base_sp and initialize to 0
BASE_SP:
. Long 0



.........
Ldr SP, BASE_SP//Reset Stack
......


C Language:
void Board_init_f (ULONG bootflag)
{
extern ulong base_sp; To declare a global variable that uses a compilation request in C language
.........
#else
ADDR_SP + 128; /* Leave words for abort-stack * *
GD->IRQ_SP = addr_sp;
#endif


Debug ("New stack pointer is:%08lx\n", addr_sp)//addr_sp This is the last stack value of the Board_init_f function


#ifdef Config_post
Post_bootmode_init ();
Post_run (NULL, Post_rom | post_bootmode_get (0));
#endif


Gd->bd->bi_baudrate = gd->baudrate;
/* Ram IST Board specific, so move it to board code ... * *
Dram_init_banksize ();
Display_dram_config (); /* and display it * *


gd->relocaddr = addr;
GD->START_ADDR_SP = addr_sp;
Gd->reloc_off = addr-_text_base;
Debug ("Relocation Offset is:%08lx\n", Gd->reloc_off);
memcpy (ID, (void *) GD, sizeof (gd_t));


base_sp = addr_sp; Pass the last stack value of the Board_init_f function to the Assembly
}

Related Article

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.