linux 汇编 `.eabi_attribute',有趣的++i和i++

本文通过具体的C++代码示例,深入探讨了前置递增与后置递增运算符的工作原理及其在复杂表达式中的行为,揭示了CPU处理这两种递增方式的实际流程,并通过汇编代码详细解释了其背后的原因。

作为一个天天和代码“约会”的人来说i++和++i这玩意再熟悉不过了,因为使用频率太高了。

虽然如此,但也未必见得我们真的了解她,不妨猜猜下面的输出结果。

#inlcude

int main(void)

{

int i = , j = ;

printf("i[1] = %d i[2] = %d\n", i++ + ++i, ++i + i++);

printf("j[1] = %d j[2] = %d\n", j++ + j++, ++j + ++j);

return ;

}

最后结果是:

i[1] = 6 i[2] = 2

j[1] = 4 j[2] = 4

想要得出正确答案,仅仅知道前+和后+的区别是不够的,这里面有两个坑。

第一个是cpu处理前+和后+真正的执行过程。

第二个是printf这个“小妾”暗藏一腿。

先把简单的第二个坑填了,以一般的思维和习惯会下意识的认为printf先计算前面那个表达式(即代码中的i[1] 和 j[1]),然后计算后面那个表达式的值(即  代码中的i[2]和j[2]),事实却正好相反,要先算后面再算前面。

要想填平第一个大坑,我们需要研究编译后的汇编代码。

@by tid_think

@arm-linux-gcc -S test.c -o test.s

@tiny4412

.cpu arm1176jzf-s

.eabi_attribute ,

.fpu vfp

.eabi_attribute ,

.eabi_attribute ,

.eabi_attribute ,

.eabi_attribute ,

.eabi_attribute ,

.eabi_attribute ,

.eabi_attribute ,

.eabi_attribute ,

.file "test.c"

.section .rodata

.align

.LC0:

.ascii "i[1] = %d i[2] = %d\012\000"

.align

.LC1:

.ascii "j[1] = %d j[2] = %d\012\000"

.text

.align

.global main

.type main, %function

main:

@ args = , pretend = , frame =

@ frame_needed = , uses_anonymous_args =

@by tid_think

@关键代码

stmfd sp!, {fp, lr} @将fp,lr两个寄存器的值压栈

add fp, sp, # @fp = sp +

sub sp, sp, # @sp = sp +

mov r3, # @r3 =

str r3, [fp, #-] @将r3的值()写入 fp - 的地方 int i = 0

mov r3, # @r3 =

str r3, [fp, #-] @将r3的值()写入 fp - 的地方 int j = 0

ldr r1, .L2 @将.L2的地址加载到r1

ldr r3, [fp, #-] @将fp -8地址上的值(i = ) 给r3

add r3, r3, # @r3 = r3 + ===>i =

str r3, [fp, #-] @将r3的值()写入 fp - 的地方 i

ldr r2, [fp, #-] @将fp -8地址上的值(i = ) 给r2

ldr r3, [fp, #-] @将fp -8地址上的值(i = ) 给r3

add r2, r2, r3 @r2 = r2 + r =

ldr r3, [fp, #-] @将fp -8地址上的值(i = ) 给r3

add r3, r3, # @ r3 = r3 + =

str r3, [fp, #-] @将r3的值()写入 fp - 的地方 i

ldr r3, [fp, #-] @将fp -8地址上的值(i = ) 给r3

add r3, r3, # @ r3 = r3 + =

str r3, [fp, #-] @将r3的值()写入 fp - 的地方 i

ldr r0, [fp, #-] @将fp -8地址上的值(i = ) 给r0

ldr r3, [fp, #-] @将fp -8地址上的值(i = ) 给r3

add r3, r0, r3 @ r3 = r0 + r3 =

ldr r0, [fp, #-] @将fp -8地址上的值(i = ) 给r0

add r0, r0, # @r0 = r0 + =

str r0, [fp, #-] @将r0的值()写入 fp - 的地方

mov r0, r1 @r0 = r1 给printf传参数1

mov r1, r2 @r1 = r2 = 给printf传参数2

mov r2, r3 @r2 = r3 = 给printf传参数3

bl printf @调用printf打印

ldr r1, .L2+4 @开始计算j了............

ldr r2, [fp, #-]

ldr r3, [fp, #-]

add r2, r2, r3

ldr r3, [fp, #-]

add r3, r3, #

str r3, [fp, #-]

ldr r3, [fp, #-]

add r3, r3, #

str r3, [fp, #-]

ldr r3, [fp, #-]

add r3, r3, #

str r3, [fp, #-]

ldr r3, [fp, #-]

add r3, r3, #

str r3, [fp, #-]

ldr r0, [fp, #-]

ldr r3, [fp, #-]

add r3, r0, r3

mov r0, r1

mov r1, r2

mov r2, r3

bl printf

mov r3, #

mov r0, r3

sub sp, fp, #

ldmfd sp!, {fp, pc}

.L3:

.align

.L2:

.word .LC0

.word .LC1

.size main, .-main

.ident "GCC: (ctng-1.8.1-FA) 4.5.1"

.section .note.GNU-stack,"",%progbits

汇编代码解析:

首先刨去没用的信息,直接从 31行开始看

33~35行都是对栈指针的一些偏移和保存。

从以上汇编代码看可以看出简单的两句C编译成汇编就是一大坨,如果用纯汇编写15行左右应该就能搞定 执行效率几乎是C的20倍……………………

谈谈一些有趣的CSS题目(十二)-- 你该知道的字体 font-family

开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

谈谈一些有趣的CSS题目(十一)-- reset.css 知多少?

开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

几个有趣的WEB设备API(二)

浏览器和设备之间还有很多有趣的接口, 1.屏幕朝向接口 浏览器有两种方法来监听屏幕朝向,看是横屏还是竖屏. (1)使用css媒体查询的方法 /* 竖屏 */ @media screen and (or ...

谈谈一些有趣的CSS题目(三)-- 层叠顺序与堆栈上下文知多少

开本系列,讨论一些有趣的 CSS 题目,抛开实用性而言,一些题目为了拓宽一下解决问题的思路,此外,涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题中有你感觉 ...

谈谈一些有趣的CSS题目(一)-- 左边竖条的实现方法

开本系列,讨论一些有趣的 CSS 题目,抛开实用性而言,一些题目为了拓宽一下解决问题的思路,此外,涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题中有你感觉 ...

谈谈一些有趣的CSS题目(二)-- 从条纹边框的实现谈盒子模型

开本系列,讨论一些有趣的 CSS 题目,抛开实用性而言,一些题目为了拓宽一下解决问题的思路,此外,涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题中有你感觉 ...

谈谈一些有趣的CSS题目(四)-- 从倒影说起,谈谈 CSS 继承 inherit

开本系列,讨论一些有趣的 CSS 题目,抛开实用性而言,一些题目为了拓宽一下解决问题的思路,此外,涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题中有你感觉 ...

谈谈一些有趣的CSS题目(五)-- 单行居中,两行居左,超过两行省略

开本系列,讨论一些有趣的 CSS 题目,抛开实用性而言,一些题目为了拓宽一下解决问题的思路,此外,涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题中有你感觉 ...

谈谈一些有趣的CSS题目(六)-- 全兼容的多列均匀布局问题

开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

谈谈一些有趣的CSS题目(七)-- 消失的边界线问题

开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

随机推荐

cursor

BeginWaitCursor(); // display the hourglass cursor // do some lengthy processing Sleep(3000); EndWai ...

mysql视图的创建

视图内容的变化跟它所依赖的表的变化是同步的也是一致的. create or replace view viewname as select a.id.,a.name,a.sex,b.aid,b.sco ...

hdu 4417 Super Mario/树套树

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意很简单,给定一个序列求一个区间 [L, R,]中小于等于H的元素的个数. 好像函数式线段树可 ...

java的CyclicBarrier

CyclicBarrier直译叫循环屏障,作用有点像赛跑时吹哨的角色,它有2个构造方法,一个是int的arg1,另一个多了一个Runable的arg2 arg1:可以看做此次参加赛跑的人数 arg2: ...

adb概览及协议參考

原文:https://github.com/android/platform_system_core/blob/master/adb/OVERVIEW.TXT) Implementation note ...

TCP重传问题解决思路

处理线上问题经常会碰到网络抖动的情况, 网络抖动有可能就是TCP重传导致,下面简单说下TCP重传的排查思路,不一定能完全解决问题 1. 找运维同事确定是否是网线问题, 如果是网线问题请更换网线 2. ...

Python基础(os模块)

os模块用于操作系统级别的操作: os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录:相当 ...

C++程序设计方法3:类中的静态成员

在类型前面加static修饰的数据成员,是隶属于类的,成为类的静态数据成员,也称为“类的变量” 静态数据成员被该类的所有对象共享(即所有对象中的这个数据域实际上处于同一个内存位置) 静态数据要在实现文 ...

C++ code:数值计算之矩形法求解积分问题

积分的通常方法是将区域切割成一个个的小矩形,然后求这些小矩形的和.小矩形切割得越细,计算精度就越高,可以将切割小矩形的数量作为循环迭代变量,将前后两个不同精度下的小矩形和之差,作为逼近是否达到要求的比 ...

uva 11183 Teen Girl Squad

题意: 有一个女孩,需要打电话让所有的人知道一个消息,消息可以被每一个知道消息的人传递. 打电话的关系是单向的,每一次电话需要一定的花费. 求出打电话最少的花费或者判断不可能让所有人知道消息. 思路: ...

PS E:\stm\tim_servo> ninja -C build ninja: Entering directory `build' [1/6] Building C object CMakeFiles/tim_servo.dir/Core/Src/syscalls.c.obj FAILED: [code=1] CMakeFiles/tim_servo.dir/Core/Src/syscalls.c.obj C:\msys64\ucrt64\bin\gcc.exe -DDEBUG -DSTM32F103xB -DUSE_HAL_DRIVER -IE:/stm/tim_servo/cmake/stm32cubemx/../../Core/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Device/ST/STM32F1xx/Include -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Include -std=gnu11 -MD -MT CMakeFiles/tim_servo.dir/Core/Src/syscalls.c.obj -MF CMakeFiles\tim_servo.dir\Core\Src\syscalls.c.obj.d -o CMakeFiles/tim_servo.dir/Core/Src/syscalls.c.obj -c E:/stm/tim_servo/Core/Src/syscalls.c E:/stm/tim_servo/Core/Src/syscalls.c:31:10: fatal error: sys/times.h: No such file or directory 31 | #include <sys/times.h> | ^~~~~~~~~~~~~ compilation terminated. [2/6] Building ASM object CMakeFiles/tim_servo.dir/startup_stm32f103xb.s.obj FAILED: [code=1] CMakeFiles/tim_servo.dir/startup_stm32f103xb.s.obj C:\msys64\ucrt64\bin\gcc.exe -DDEBUG -DSTM32F103xB -DUSE_HAL_DRIVER -IE:/stm/tim_servo/cmake/stm32cubemx/../../Core/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Device/ST/STM32F1xx/Include -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Include -g -MD -MT CMakeFiles/tim_servo.dir/startup_stm32f103xb.s.obj -MF CMakeFiles\tim_servo.dir\startup_stm32f103xb.s.obj.d -o CMakeFiles/tim_servo.dir/startup_stm32f103xb.s.obj -c E:/stm/tim_servo/startup_stm32f103xb.s E:/stm/tim_servo/startup_stm32f103xb.s: Assembler messages: E:/stm/tim_servo/startup_stm32f103xb.s:28: Error: unknown pseudo-op: `.syntax' E:/stm/tim_servo/startup_stm32f103xb.s:29: Error: unknown pseudo-op: `.cpu' E:/stm/tim_servo/startup_stm32f103xb.s:30: Error: unknown pseudo-op: `.fpu' E:/stm/tim_servo/startup_stm32f103xb.s:31: Error: unknown pseudo-op: `.thumb' E:/stm/tim_servo/startup_stm32f103xb.s:59: Warning: .type pseudo-op used outside of .def/.endef: ignored. E:/stm/tim_servo/startup_stm32f103xb.s:59: Error: junk at end of line, first unrecognized character is `R' E:/stm/tim_servo/startup_stm32f103xb.s:63: Error: no such instruction: `bl SystemInit' E:/stm/tim_servo/startup_stm32f103xb.s:66: Error: no such instruction: `ldr r0,=_sdata' E:/stm/tim_servo/startup_stm32f103xb.s:67: Error: no such instruction: `ldr r1,=_edata' E:/stm/tim_servo/startup_stm32f103xb.s:68: Error: no such instruction: `ldr r2,=_sidata' E:/stm/tim_servo/startup_stm32f103xb.s:69: Warning: `r3' is not valid here (expected `(%rsi)') E:/stm/tim_servo/startup_stm32f103xb.s:69: Error: expecting operand after ','; got nothing E:/stm/tim_servo/startup_stm32f103xb.s:70: Error: no such instruction: `b LoopCopyDataInit' E:/stm/tim_servo/startup_stm32f103xb.s:73: Error: no such instruction: `ldr r4,[r2,r3]' E:/stm/tim_servo/startup_stm32f103xb.s:74: Error: missing ']' E:/stm/tim_servo/startup_stm32f103xb.s:74: Error: too many memory references for `str' E:/stm/tim_servo/startup_stm32f103xb.s:75: Error: expecting operand after ','; got nothing E:/stm/tim_servo/startup_stm32f103xb.s:78: Error: too many memory references for `add' E:/stm/tim_servo/startup_stm32f103xb.s:79: Error: operand type mismatch for `cmp' E:/stm/tim_servo/startup_stm32f103xb.s:80: Error: no such instruction: `bcc CopyDataInit' E:/stm/tim_servo/startup_stm32f103xb.s:83: Error: no such instruction: `ldr r2,=_sbss' E:/stm/tim_servo/startup_stm32f103xb.s:84: Error: no such instruction: `ldr r4,=_ebss' E:/stm/tim_servo/startup_stm32f103xb.s:85: Warning: `r3' is not valid here (expected `(%rsi)') E:/stm/tim_servo/startup_stm32f103xb.s:85: Error: expecting operand after ','; got nothing E:/stm/tim_servo/startup_stm32f103xb.s:86: Error: no such instruction: `b LoopFillZerobss' E:/stm/tim_servo/startup_stm32f103xb.s:89: Error: number of operands mismatch for `str' E:/stm/tim_servo/startup_stm32f103xb.s:90: Error: expecting operand after ','; got nothing E:/stm/tim_servo/startup_stm32f103xb.s:93: Error: operand type mismatch for `cmp' E:/stm/tim_servo/startup_stm32f103xb.s:94: Error: no such instruction: `bcc FillZerobss' E:/stm/tim_servo/startup_stm32f103xb.s:97: Error: no such instruction: `bl __libc_init_array' E:/stm/tim_servo/startup_stm32f103xb.s:99: Error: no such instruction: `bl main' E:/stm/tim_servo/startup_stm32f103xb.s:100: Error: no such instruction: `bx lr' E:/stm/tim_servo/startup_stm32f103xb.s:101: Warning: .size pseudo-op used outside of .def/.endef: ignored. E:/stm/tim_servo/startup_stm32f103xb.s:101: Error: junk at end of line, first unrecognized character is `R' E:/stm/tim_servo/startup_stm32f103xb.s:111: Error: junk at end of line, first unrecognized character is `,' E:/stm/tim_servo/startup_stm32f103xb.s:114: Error: no such instruction: `b Infinite_Loop' E:/stm/tim_servo/startup_stm32f103xb.s:115: Warning: .size pseudo-op used outside of .def/.endef: ignored. E:/stm/tim_servo/startup_stm32f103xb.s:115: Error: junk at end of line, first unrecognized character is `D' E:/stm/tim_servo/startup_stm32f103xb.s:123: Error: junk at end of line, first unrecognized character is `,' E:/stm/tim_servo/startup_stm32f103xb.s:124: Warning: .type pseudo-op used outside of .def/.endef: ignored. E:/stm/tim_servo/startup_stm32f103xb.s:124: Error: junk at end of line, first unrecognized character is `g' E:/stm/tim_servo/startup_stm32f103xb.s:125: Warning: .size pseudo-op used outside of .def/.endef: ignored. E:/stm/tim_servo/startup_stm32f103xb.s:125: Error: junk at end of line, first unrecognized character is `g' E:/stm/tim_servo/startup_stm32f103xb.s:196: Warning: value 0xf108f85f truncated to 0xf85f E:/stm/tim_servo/startup_stm32f103xb.s:207: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:209: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:211: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:213: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:215: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:217: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:219: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:221: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:223: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:225: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:227: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:229: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:231: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:233: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:235: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:237: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:239: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:241: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:243: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:245: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:247: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:249: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:251: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:253: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:255: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:257: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:259: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:261: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:263: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:265: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:267: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:269: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:271: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:273: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:275: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:277: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:279: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:281: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:283: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:285: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:287: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:289: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:291: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:293: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:295: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:297: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:299: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:301: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:303: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:305: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:307: Error: unknown pseudo-op: `.thumb_set' E:/stm/tim_servo/startup_stm32f103xb.s:309: Error: unknown pseudo-op: `.thumb_set' [3/6] Building C object CMakeFiles/tim_servo.dir/Core/Src/main.c.obj FAILED: [code=1] CMakeFiles/tim_servo.dir/Core/Src/main.c.obj C:\msys64\ucrt64\bin\gcc.exe -DDEBUG -DSTM32F103xB -DUSE_HAL_DRIVER -IE:/stm/tim_servo/cmake/stm32cubemx/../../Core/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Device/ST/STM32F1xx/Include -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Include -std=gnu11 -MD -MT CMakeFiles/tim_servo.dir/Core/Src/main.c.obj -MF CMakeFiles\tim_servo.dir\Core\Src\main.c.obj.d -o CMakeFiles/tim_servo.dir/Core/Src/main.c.obj -c E:/stm/tim_servo/Core/Src/main.c In file included from E:/stm/tim_servo/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h:131, from E:/stm/tim_servo/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h:130, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h:29, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h:27, from E:/stm/tim_servo/Core/Inc/stm32f1xx_hal_conf.h:238, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h:29, from E:/stm/tim_servo/Core/Inc/main.h:30, from E:/stm/tim_servo/Core/Src/main.c:20: E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h: In function '__NVIC_SetVector': E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h:1738:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 1738 | uint32_t *vectors = (uint32_t *)SCB->VTOR; | ^ E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h: In function '__NVIC_GetVector': E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h:1753:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 1753 | uint32_t *vectors = (uint32_t *)SCB->VTOR; | ^ C:\Users\Yeah\AppData\Local\Temp\ccIGZrQh.s: Assembler messages: C:\Users\Yeah\AppData\Local\Temp\ccIGZrQh.s:139: Error: no such instruction: `cpsid i' [4/6] Building C object cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj FAILED: [code=1] cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj C:\msys64\ucrt64\bin\gcc.exe -DDEBUG -DSTM32F103xB -DUSE_HAL_DRIVER -IE:/stm/tim_servo/cmake/stm32cubemx/../../Core/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Device/ST/STM32F1xx/Include -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Include -std=gnu11 -MD -MT cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj -MF cmake\stm32cubemx\CMakeFiles\STM32_Drivers.dir\__\__\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c.obj.d -o cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj -c E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c In file included from E:/stm/tim_servo/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h:131, from E:/stm/tim_servo/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h:130, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h:29, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h:27, from E:/stm/tim_servo/Core/Inc/stm32f1xx_hal_conf.h:238, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h:29, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c:82: E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h: In function '__NVIC_SetVector': E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h:1738:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 1738 | uint32_t *vectors = (uint32_t *)SCB->VTOR; | ^ E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h: In function '__NVIC_GetVector': E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h:1753:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 1753 | uint32_t *vectors = (uint32_t *)SCB->VTOR; | ^ C:\Users\Yeah\AppData\Local\Temp\ccLF5hmc.s: Assembler messages: C:\Users\Yeah\AppData\Local\Temp\ccLF5hmc.s:105: Error: number of operands mismatch for `ds' C:\Users\Yeah\AppData\Local\Temp\ccLF5hmc.s:111: Error: no such instruction: `isb 0xF' C:\Users\Yeah\AppData\Local\Temp\ccLF5hmc.s:445: Error: number of operands mismatch for `ds' C:\Users\Yeah\AppData\Local\Temp\ccLF5hmc.s:458: Error: number of operands mismatch for `ds' [5/6] Building C object cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj FAILED: [code=1] cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj C:\msys64\ucrt64\bin\gcc.exe -DDEBUG -DSTM32F103xB -DUSE_HAL_DRIVER -IE:/stm/tim_servo/cmake/stm32cubemx/../../Core/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Device/ST/STM32F1xx/Include -IE:/stm/tim_servo/cmake/stm32cubemx/../../Drivers/CMSIS/Include -std=gnu11 -MD -MT cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj -MF cmake\stm32cubemx\CMakeFiles\STM32_Drivers.dir\__\__\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c.obj.d -o cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj -c E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c In file included from E:/stm/tim_servo/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h:131, from E:/stm/tim_servo/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h:130, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h:29, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h:27, from E:/stm/tim_servo/Core/Inc/stm32f1xx_hal_conf.h:238, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h:29, from E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c:26: E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h: In function '__NVIC_SetVector': E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h:1738:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 1738 | uint32_t *vectors = (uint32_t *)SCB->VTOR; | ^ E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h: In function '__NVIC_GetVector': E:/stm/tim_servo/Drivers/CMSIS/Include/core_cm3.h:1753:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 1753 | uint32_t *vectors = (uint32_t *)SCB->VTOR; | ^ E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c: In function 'HAL_PWR_EnableWakeUpPin': E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c:386:4: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 386 | *(__IO uint32_t *) CSR_EWUP_BB(WakeUpPinx) = (uint32_t)ENABLE; | ^ E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c: In function 'HAL_PWR_DisableWakeUpPin': E:/stm/tim_servo/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c:401:4: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 401 | *(__IO uint32_t *) CSR_EWUP_BB(WakeUpPinx) = (uint32_t)DISABLE; | ^ C:\Users\Yeah\AppData\Local\Temp\ccnxrD4a.s: Assembler messages: C:\Users\Yeah\AppData\Local\Temp\ccnxrD4a.s:13: Error: no such instruction: `wfe' C:\Users\Yeah\AppData\Local\Temp\ccnxrD4a.s:304: Error: no such instruction: `wfi' C:\Users\Yeah\AppData\Local\Temp\ccnxrD4a.s:311: Error: no such instruction: `sev' C:\Users\Yeah\AppData\Local\Temp\ccnxrD4a.s:314: Error: no such instruction: `wfe' C:\Users\Yeah\AppData\Local\Temp\ccnxrD4a.s:317: Error: no such instruction: `wfe' C:\Users\Yeah\AppData\Local\Temp\ccnxrD4a.s:359: Error: no such instruction: `wfi' C:\Users\Yeah\AppData\Local\Temp\ccnxrD4a.s:366: Error: no such instruction: `sev' C:\Users\Yeah\AppData\Local\Temp\ccnxrD4a.s:403: Error: no such instruction: `wfi' ninja: build stopped: subcommand failed.如何解决
11-15
(Kriging_NSGA2)克里金模型结合多目标遗传算法求最优因变量及对应的最佳自变量组合研究(Matlab代码实现)内容概要:本文介绍了克里金模型(Kriging)与多目标遗传算法NSGA-II相结合的方法,用于求解最优因变量及其对应的最佳自变量组合,并提供了完整的Matlab代码实现。该方法首先利用克里金模型构建高精度的代理模型,逼近复杂的非线性系统响应,减少计算成本;随后结合NSGA-II算法进行多目标优化,搜索帕累托前沿解集,从而获得多个最优折衷方案。文中详细阐述了代理模型构建、算法集成流程及参数设置,适用于工程设计、参数反演等复杂优化问题。此外,文档还展示了该方法在SCI一区论文中的复现应用,体现了其科学性与实用性。; 适合人群:具备一定Matlab编程基础,熟悉优化算法数值建模的研究生、科研人员及工程技术人员,尤其适合从事仿真优化、实验设计、代理模型研究的相关领域工作者。; 使用场景及目标:①解决高计算成本的多目标优化问题,通过代理模型降低仿真次数;②在无法解析求导或函数高度非线性的情况下寻找最优变量组合;③复现SCI高水平论文中的优化方法,提升科研可信度与效率;④应用于工程设计、能源系统调度、智能制造等需参数优化的实际场景。; 阅读建议:建议读者结合提供的Matlab代码逐段理解算法实现过程,重点关注克里金模型的构建步骤与NSGA-II的集成方式,建议自行调整测试函数或实际案例验证算法性能,并配合YALMIP等工具包扩展优化求解能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值