当前位置:网站首页>GCC C inline assembly
GCC C inline assembly
2022-06-11 02:30:00 【Eddy_ l】
GCC C Inline assembly
C The basic syntax of language inline assembly is as follows :
asm asm-qualifiers ( AssemblerTemplate
: OutputOperands
[ : InputOperands
[ : Clobbers ] ])
asm asm-qualifiers ( AssemblerTemplate
: OutputOperands
: InputOperands
: Clobbers
: GotoLabels)
among :
asm: Statement C Insert assembly code into the program , Can also write
__asm__.asm-qualifiers: qualifiers , Its optional values are :
volatile、inline、goto, amongvolatileIs to instruct the compiler not to optimize this assembly code ,inlineUsed to instruct the compiler to keep the size of the hypothetical assembly code instructions as small as possible ,gotoThe code used for assembly can jump to one or more C label .AssemblerTemplate: Assembly instruction , In use, you need to enclose it in double quotation marks , If there are multiple instructions , Each instruction needs to be followed by
\n\tSeparate .OutputOperands: Output operands , When inline assembly code is executed , Return to C Program save , When there are multiple output parameters , Use commas to separate . The format is :
[ [asmSymbolicName] ] constraint (cvariablename)- asmSymbolicName: Symbol name , Any permitted C Variables are allowed , Two operands in the same statement cannot use the same symbolic name .
- constraint: Denotes a constraint , See table for optional values 1.
- cvariablename:C Language variable name .
InputOperands: Enter the operands , Where to transfer operation data . The format is :
[ [asmSymbolicName] ] constraint (cexpression).- asmSymbolicName: It's a symbolic name , Any valid C Variable names are acceptable , Two operands in the same statement cannot use the same symbolic name . When not in use , Don't write .
- constraint: Denotes a constraint .
- cexpression:C Language expressions .
Clobbers: In inline assembly , For the registers involved in the output operand 、 Memory , Made changes ,
ClobbersUsed to indicate what is being modified , See table for optional values 3.
Different platforms have different inline assemblies , It is called assembly dialect , The differences between specific platforms can be seen GNU C Extended assembly .
| constraint | describe |
|---|---|
| m | memory operand Indicates that you want to pass in a valid address , as long as CPU Can support this address , Can be passed in . |
| r | register operand Register operand , Use registers to hold these operands . |
| i | immediate integer operand Indicates that an immediate number can be passed in . |
| constraint Modifier Characters | describe |
|---|---|
| = | Write only operands , Indicates that inline assembly will modify this operand . |
| & | This means that this operand is an early change operand , It is modified by using the input operand before the instruction is completed . therefore , This operand cannot be located in a register that is used as an output operand or any memory address part . If the old value is only used as input before it is written , An input operand can be an early change operand . |
| + | Read and write operands , Can only be used to decorate output operands . |
| nothing | The default operation is read-only . |
See for more modifiers http://hehezhou.cn/gccint/Modifiers.html#Modifiers.
| Clobbers | describe |
|---|---|
| cc | Indicates that the assembly code will modify the condition ( sign ) register |
| memory | In assembly code , Will modify the memory . |
For example
#define __ASM_STR(x) #x
#define csr_write(csr,val) \ ({
\ unsigned long __val = (unsigned long)(val); \ __asm__ __volatile__("csrw "__ASM_STR(csr) ", %0" \ : \ : "rK"(__val) \ : "memory"); \ })
#define csr_read_set(csr,val) \ ({
\ register unsigned long __v = val; \ __asm__ __volatile__("csrrs %0,"__ASM_STR(csr) ", %1" \ : "=r"(__v) \ : "rK"(__v) \ : "memory"); \ __v;
})
Reference resources
ARM GCC Embedded (inline) Compilation manual
🧇
边栏推荐
- [3.delphi common components] 4 Select class component
- What do you know about the set class? Soul questions from Volume I
- Introduction for i-Teams
- Koa2 learning notes
- 查看Redis内数据,除了命令行和客户端,你还有第三种选择
- SQL | 外连接
- What is the relationship between precious metal silver and spot Silver
- Dynamically add attributes to objects
- mysql重装时写my.ini配置文件出错
- [3.delphi common components] 6 scroll bar
猜你喜欢

力扣刷题篇——哈希表

The interviewer of Tencent said that who knows the internal module index principle and performance optimization idea of MySQL architecture?

Tencent test development post interview programming questions

Jetpack Compose Scaffold和TopAppBar(顶部导航)

环糊精金属有机骨架(β-CD-MOF)装载二巯丁二酸/大黄素/槲皮素/三氯蔗糖/二氟尼柳/奥美拉唑(OME)

Unity animator rewind

Colab报错:ImportError: cannot import name ‘_check_savefig_extra_args‘ from ‘matplotlib.backend_bases‘
![[3.delphi common components] 4 Select class component](/img/36/e78ee0c082bc36be6dbc49d0e12521.jpg)
[3.delphi common components] 4 Select class component
![[3.delphi common components] 6 scroll bar](/img/55/891e56de4500a9128ac89e3c5b1721.jpg)
[3.delphi common components] 6 scroll bar

Cyclodextrin metal organic framework( β- Cd-mof) loaded with dimercaptosuccinic acid / emodin / quercetin / sucralose / diflunisal / omeprazole (OME)
随机推荐
Colab reported an error: importerror: cannot import name '_ check_ savefig_ extra_ args‘ from ‘matplotlib. backend_ bases‘
ShaderGraphs
Li Kou brushing questions - hash table
Unity HTC and Pico are the same
Record scroll bar position, passive, scrolltop
2022 high altitude installation, maintenance and removal of simulated examination platform of theoretical question bank
【无标题】
Oracle collects statistics
STC8A8K64D4 EEPROM读写失败
Why can some programmers get good offers with average ability?
Is it appropriate for a 27 - year-old girl to change her career from zero to software testing?
Nodejs send mail
项目 - Redis消息队列+工作线程取出用户操作日志并入库(二)
金属有机框架MOF-Al(DIBA),MOF-Zr(DIBA),MOF-Fe(DIBA)包载姜黄素/羧苄西林/MTX甲氨蝶呤/紫杉醇PTX/阿霉素DOX/顺铂CDDP/CPT喜树碱等药物
Secret
[3.delphi common components] 6 scroll bar
The diligent is the laziest
How to guarantee the data quality of data warehouse?
Shader of double sided material
Colab报错:ImportError: cannot import name ‘_check_savefig_extra_args‘ from ‘matplotlib.backend_bases‘