gcc 内嵌汇编的学习笔记 III

UCOS-III 系统移植 UCOSIII系统移植到GD32F303详细过程 工程代码:https://github.com/jslaobing/techIot_ucosiii_porting 阅读详情

           gcc 内嵌汇编的学习笔记 III
                                     --一个loop
  作者:ShellEx. 
  ShellEx.cn && blog.youkuaiyun.com/shellex 版权所有
 我又来了。今天实现的是类似While(...){...}的一个loop。对于不
支持高级语法(.if之流)的GNU gcc汇编器--也就是GAS--来说,写条件判
断和循环要略微麻烦呢。
#include <stdio.h>
int main() {
 int in = 0, out =0, i = 0 ;
 printf("PLZ input a Number: /n");
 scanf("%d", &in);

 asm volatile(
  "nop  #LoopTest/n"  
  "L_BEG:   /n/t" //起始标志位
  "cmp  %2, %1  /n/t" //比较in 和 i (放在寄存器中)的值
  "jge  L_END  /n/t" //i 比in 大就跳出
  "addl  $2, %0  /n/t" //否则out+=2
  "incl  %1   /n/t" //i自增  
  "jmp  L_BEG  /n"  //跳回起始 位置  
  "L_END:   /n/t" //结束标志
  :"+r"(out),"+r"(i)
  :"r"(in)
  :
 );
 printf("out = %d",out);
 return 0;
}
///////////////////////////////////////////////////////////////
没有难度,就仅仅是比较和跳转,相当于下列C++ code :
while (i < in) {
 out += 2;
 ++i;
}
shellex.cn && blog.youkuaiyun.com/shellex 版权所有 

Linux——gcc/g++编译器 Linux ——gcc/g++的编译链接过程,目标文件对动静态链接方式,动静态库的区别 阅读详情

相关推荐

GCC源码分析(二)——前端

从这一篇开始,我们将从源代码的角度来分析GCC如何完成对C语言源文件的处理。GCC的内部构架在GCC Internals(搜“gccint.pdf”,或者见[1])里已经讲述得很详细了,但是如果你只看了gccint就来看代码,还是觉得一头雾水,无法下手,因为你很难把gccint所讲的概念同gcc代码里真实的数据结构联系起来。那么这也是我把我这半年的分析经理写下来的原因,大家可以参照gccint来看

SonicLing的专栏 1万+

gcc将内嵌汇编编译成汇编

extern int input ,result;   2   3 void test_at_t()   4 {   5     result = 0;   6     input = 1;   7     __asm__   8     __volatile__("addl%1, %0":"=r"(result):"r"(input));   9 } ~

遨游太空2014 706

gcc之编译链接原理

文章目录1. 概述2. 1. 概述      Windows环境下的开发同事,对于“目标文件”概念的理解或多或少有些陌生,因为大多数都是基于IDE(Integrated Development Environment)集成开发环境进行项目开发。如常用到的 IntelliJ IDEA、Visual Studio、Eclipse 等等。当某函数功能开发完成之后,直接鼠标点击构建(Build)然后就会生...

Postgres 数据库内核开发工程师 741

__asm__ __volatile__ GCC的内嵌汇编语法 AT&T汇编语言语法

1.内存屏障(memory barrier)   #define set_mb(var, value) do { var = value; mb(); } while (0)   #define mb() __asm__ __volatile__ ("" : : : "memory") 1)set_mb(),mb(),barrier()函数追踪到底,就是__asm__ __volatil

zzhongcy的专栏 1392

gcc内嵌汇编 中文使用说明

gcc内嵌汇编 中文使用说明 脚你如何在c语言中插入汇编代码

FID指标实战:如何用Python快速计算生成图像的质量分数(附完整代码)

本文详细介绍了如何使用Python计算Fréchet Inception Distance(FID)指标,以评估生成图像的质量。通过完整的代码示例和优化技巧,帮助开发者快速实现FID计算,并解读分数背后的实际意义,适用于GAN和扩散模型的性能评估。

weixin_28718487的博客 374

gcc内嵌汇编简介

在内嵌汇编中,可以将C语言表达式指定为汇编指令的操作数,而且不用去管如何将C语言表达式的值读入哪个寄存器,以及如何将计算结果写回C 变量,你只要告诉程序中C语言表达式与汇编指令操作数之间的对应关系即可, GCC会自动插入代码完成必要的操作。 1、简单的内嵌汇编 例:       __asm__ __volatile__("hlt"); "__asm__"表示后面的代码为内嵌汇编,"asm"是"__

zdfonline的专栏 2550

小白学电路之cadance搭建buffer电路

Buffer(缓冲器)是一种放大器或驱动电路,主要用于隔离输入和输出,以防止负载对前级电路造成干扰或影响。本文作者在电路方面是小白水平,目前正在学习,有不足之处欢迎指正。3.创建新的cellview,对此buffer进行仿真验证。2.创建buffer的symbol。电路中的V2的详细参数。

weixin_58051657的博客 1983

中英文对照—masm编译时错误性息提示

<br />ml.exe错误性息<br /><br />FATAL  严重错误<br />cannot open file不能打开文件 <br />I/O error closing fileI/O错误 正在关闭文件<br />I/O error writing fileI/O错误 正在写文件<br />I/O error reading file           I/O错误 正在读取文件<br />out of memory             缺少内存<br />assembler limit 

fengbonianshao的专栏 5462

华为铁三角(AR、SR、FR)的考核指标设计

以和为核心,通过和实现协同。考核维度分为和,并随市场阶段动态调整权重。

从技术实践立足,从项目管理方法论延伸思考 2768

T2T基因组组装实战指南:从数据到完整染色体

本文详细介绍了T2T基因组组装技术的实战指南,从测序数据选择到完整染色体组装的全流程。重点解析了ONT ultra-long和PacBio HiFi测序技术的优势,以及如何攻克端粒和着丝粒等重复区域的组装难题。通过具体案例和实用技巧,帮助研究人员实现从数据到完整染色体的高质量组装。

weixin_29292535的博客 843

gcc 内嵌汇编的学习笔记 IV

gcc 内嵌汇编的学习笔记 IV --函数调用 作者:ShellEx. ShellEx.cn &amp;&amp; shellex.cublog.cn 版权所有 没有经验,还是通过反汇编出来的代码来学习。先写……...

钢窟. 231

如何快速获取SAMM、SMIC等主流微表情数据集?完整申请指南(附避坑技巧)

本文提供了获取SAMM、SMIC等主流微表情数据集的完整申请指南,包括申请前的准备工作、分步申请流程、协议谈判技巧以及数据使用与维护策略。特别针对高分辨率动态捕捉和多模态同步数据等热词,帮助研究者高效获取高质量数据集,避免常见陷阱。

weixin_29057163的博客 419

MIPS内嵌汇编:从语法到实战,掌握底层优化核心技术

内嵌汇编是连接高级语言与底层硬件指令的关键技术,它允许开发者在C/C++代码中直接插入特定架构的机器指令,从而实现对性能瓶颈的精准优化或对硬件行为的精确控制。其核心原理在于通过编译器提供的特殊语法,将汇编指令模板与高级语言变量进行绑定和寄存器分配,在保持代码可读性的同时突破高级语言的限制。这项技术的核心价值在于能够直接操作硬件寄存器、实现原子操作、管理缓存以及执行系统级调用,尤其在对性能有极致要求的嵌入式系统、操作系统内核和高性能计算等场景中不可或缺。以MIPS架构为例,其精简规整的指令集使得内嵌汇编的学习

weixin_33895695的博客 416

数学建模--十大经典常用算法

数学建模十大算法:灰色预测,蒙特卡洛,遗传算法,模拟退火法,组合算法,神经网络,动态规划,聚类算法,类比法,概率算法,Floyd算法

qq_51533426的博客 5646

BES平台集成第三方音频算法避坑指南:以声加ENC为例,聊聊文件放置、内存分配与授权那些事

本文详细解析了在BES平台上集成声加ENC降噪算法的全流程,包括技术选型、系统架构设计、内存管理及量产授权等关键环节。特别针对BES平台的双核架构和内存限制,提供了文件放置、内存分配与授权验证的实用解决方案,帮助开发者高效实现音频算法集成。

weixin_33720956的博客 513

STM32 uCOS-III GCC移植说明

1. 修改ST的内核文件 参考https://blog.youkuaiyun.com/chuancey_cc/article/details/78474001 第四节 2. 替换启动文件 参考https://blog.youkuaiyun.com/chuancey_cc/article/details/78474001 第五节 3. 添加链接脚本 参考https://blog.youkuaiyun.com/chuancey_cc/...

Chuancey_CC的博客 2217

QT使用高精度定时器

精度相对第二种方法高许多。

ljjjjjjjjjjj的博客 4097

操作系统—GCC与编译全流程

GCC与编译全流程

Voltline的博客 2252

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Ucos-iii 移植到STM32F407 (vscode+cmake版)

本文详细介绍了uC/OS-III实时操作系统在STM32F429平台上的移植过程。主要内容包括:1)准备uC/OS源码并验证关键汇编文件;2)建立工程目录结构,复制必要源文件和配置文件;3)编写CMake脚本将uC/OS编译为静态库;4)修改启动文件、中断处理和配置宏定义;5)实现BSP层时钟和GPIO初始化;6)创建LED闪烁示例任务。移植过程中重点处理了系统时钟配置、任务调度初始化、临界区保护等关键环节,最终成功实现了基于uC/OS-III的LED定时闪烁功能。该移植方案采用CMake构建系统,便于工程

weixin_52980131的博客 679

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

c与汇编的关系

c与汇编的关系 _start是汇编程序的入口,main是c程序的入口? gcc 只是一个  外壳而不是真正的编译器,这真的c编译器是/usr/lib/gcc/i486-gun/4.3.2/cc1,gcc调用c编译器、汇编器和链接器完成c 代码的编译链接工作。/usr/lib/gcc/i486-linux-gun/4.3.2/collect2是链接器ld的外壳,它调用ld完成链接。 i

u013673367的专栏 859

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Linux 高并发学习笔记 - GCC/G++基本使用

GCC/G++ 基本使用,GCC编译原理,GCC常用命令,GCC与G++的区别。

凉皮大大的博客 244

从前后台系统到UCOS-III实践指南

基础阶段(1-2周):完成LED多任务闪烁实验进阶阶段(1个月):实现多外设协同控制项目实战(3个月):完成工业控制器原型开发源码研究(6个月):深入理解内核调度算法ImageCodefill:#333;color:#333;color:#333;fill:none;裸机开发基础RTOS任务管理系统资源优化网络协议集成安全机制设计裸机开发基础RTOS任务管理系统资源优化网络协议集成安全机制设计。

波风水门的博客 917

黑妹的游戏III

题目链接:黑妹的游戏III 不难发现,每次除以因子,可以等价于除以质因子。 然后我们对每个质因子单独看也是不影响的。 然后就变成质因子最多可以抵消多少次了。 假设某个质因子总数为sum,最大值为mx,那么如果mx*2<=sum,则会剩下1或者0个(奇偶)。 不然就是mx*2-sum个。 AC代码: #pragma GCC optimize("-Ofast","-funroll-all-loops") #include<bits/stdc++.h> //#define int long

青烟绕指柔的博客 584

GCC源码分析(摘)

摘自https://blog.youkuaiyun.com/sonicling/article/details/6702031,https://blog.youkuaiyun.com/sonicling/article/details/670615,https://blog.youkuaiyun.com/sonicling/article/details/7915301,https://blog.youkuaiyun.com/sonicling...

数字人生 5886
上一篇: gcc 内嵌汇编的学习笔记 II
下一篇: gcc 内嵌汇编的学习笔记 IV
ShellEx
博客等级 码龄21年 4粉丝 43原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值