37.C and assembly mixed programming
New light.c:
Modify start. S
Modify Makefile: Add LIGHT.O
Finally make successful, burn write success.
Again, we can call the functions in our assembly in the C function:
Modify start. S: Declare light_led as global:
is called in light.c:
Make compile-and-write to the Development board: The lights can be lit. The call assembler function succeeds in C.
The next step is to embed the assembly code in C instead of calling:
Embed assembler code in C:
Format:
C Inline assembly begins with the keyword "__asm__" or "ASM", containing four parts of the content, for example, separate parts with ":", the first part must be written, the following three parts can be ignored, but the semicolon: cannot be omitted.
- Assembly statements
- Output section: C variables modified in the language
- input section: from C arguments coming in
- Destruction Description: The value of the register is modified and the register is listed here.
Simple example:
read out the value of the C1 register in the CPSR in the C language:
In the assembly statement above, notice that the position of the Universal register is a parameter%0, and that all the parts to be read are placed in the input section, and all the parts to be written are placed in the output section.
The "R" in the input section above is a general-purpose register, assigned by the system, followed by parentheses value, which is present in the register.
The value of the C1 register written in the CPSR is implemented in the C language:
The parameter register is the value of the register in the output CPSR.
The equals sign is write-only, which is the write-only operation of register r, and the value in the register is written in value.
The destruction section has memory, which tells the system to modify the value of the variable in memory in the Assembly statement.
Volatile is telling the CPU not to optimize the code:
To achieve illumination:
The above with%0 and% means that this is a two parameter, the value of the parameter is two general register value. "R" in "R" (Gpkcon) represents a universal register with a value of Gpkcon. "R0" is the destruction department because the entire operation affects the value of R0.
Make Burn and the light is on.
37.C and assembly mixed programming