第47部分- Linux x86 64位汇编 C调用汇编

C与汇编语言 目录 一、汇编指令 二、汇编器和链接器 三、 汇编语法 四、C中嵌入汇编代码 五、GDB反汇编 1、x86_64通用寄存器 2、 调用栈 3、导出汇编代码 4、反汇编调试详解 5、结构体反汇编 一、汇编指令 汇编指令是指特定CPU架构的指令码的助记符,比如Intel x86 32位下ADD指令对应的16进制机器码有04/05/80/81等,被操作对象不同同一个... 阅读详情

第47部分- Linux x86 64位汇编 C调用汇编

这个部分我们直接以例子来展示。

示例

定义casm.c文件如下:

#include <string.h>

int main() {
	char* str = "Hello World\n";
	int len = strlen(str);
	printHelloWorld(str, len);
	return 0;
}

调用printHelloWorld函数,我们知道在X86处理中调用函数的前6个参数位于寄存器rdi, rsi, rdx, rcx, r8 and r9中,其他通过栈来实现。这样printHelloWorld函数可以通过rdi,rsi来获取前两个参数。

Nasm汇编器语法

再来看汇编文件,定义汇编文件printHelloWorld.s如下:

global printHelloWorld
section .text
printHelloWorld:
		;; 参数一
		mov r10, rdi
		;; 参数二
		mov r11, rsi
		;; 调用write系统调用
		mov rax, 1
		mov rdi, 1
		mov rsi, r10
		mov rdx, r11
		syscall
		ret

nasm -f elf64 -o printHelloWorld.o printHelloWorld.asm

gcc printHelloWorld.o casm.c -o casm

然后执行我们可以得到如下:

#./casm

Hello World

Gas汇编器语法

修改成gas的AT&T语法

printHelloWorld.s如下:

.global printHelloWorld
.section .text
printHelloWorld:
		mov %rdi, %r10
		mov %rsi, %r11
		mov $1,%rax
		mov $1,%rdi
		mov %r10,%rsi
		mov %r11,%rdx
		syscall
		ret

as -o printHelloWorld.o printHelloWorld.s

gcc printHelloWorld.o casm.c -o casm

得到的结果是一样的。

 

示例二求平方

先定义个求平方的汇编函数在文件square.s中如下:

.type square, @function
.globl square
square:
  movq %rdi,%rax
  imul %rax, %rax
  ret

然后C语言去调用

#include <stdio.h>

int main()
{
        int i = 2;
        int j = square(i);
        printf("The square of %d is %d\n", i, j);

        j = square(10);
        printf("The square of 10 is %d\n", j);
        return 0;
}

编译

gcc -o inttest inttest.c square.s

我们看到第一次使用了C变量i,第二次使用了立即数10。返回值被赋值给C变量j。这里我们要知道的是函数传递的时候前面六个寄存器是:

rdi,rsi,rdx,rcx,r8,r9.

示例三返回字符串

字符串比较长,只能通过返回字符串指针的方式来进行了。

这里需要提醒的事C/C++程序中处理器字符串时候,字符串必须使用空字符结尾。

默认情况下,C程序假设函数返回值是整数值。需要通知编译器这个函数范湖字符串指针,通过创建函数调用的原型来完成这个任务。

原型在使用函数之间定义。

以获取CPUID字符串为例子。

定义cpuidfunc.s汇编文件如下:

.section .bss
   .comm output, 13
.section .text
.type cpuidfunc, @function
.globl cpuidfunc
cpuidfunc:
   movq $0, %rax
   cpuid
   movq $output, %rdi
   movq %rbx, (%rdi)
   movq %rdx, 4(%rdi)
   movq %rcx, 8(%rdi)
   movq $output, %rax
   ret

这里定义了一个缓冲区,将被主C程序访问。

定义C文件stringtest.c如下:

#include <stdio.h>

char *cpuidfunc(void);

int main()
{
        char *spValue;
        spValue = cpuidfunc();
        printf("The CPUID is: '%s'\n", spValue);
        return 0;
}

编译:

gcc -o stringtest stringtest.c cpuidfunc.s -no-pie

 

示例三返回浮点值

浮点返回值是特殊情况。

整数和字符串返回值都是使用EAX寄存器把值从汇编语言函数返回到发出调用的C程序。

C样式使用xmm0寄存器在函数之间交换浮点值。函数把返回值存放到FPU堆栈中,然后调用程序负责把返回值弹出堆栈并且把它赋值给变量。

定义汇编函数areafunc.s如下:

.section .text
.type areafunc, @function
.globl areafunc
areafunc:
   fldpi
   push %rdi
   fild (%rsp)
   fmul %st(0), %st(0)
   fmul %st(1), %st(0)
   fstps (%rsp)
   movq (%rsp),%xmm0
   popq %rdi
   ret

先加载π到fpu堆栈中。然后加载半径到st0,然后半径自己相乘,最后与π相乘。最后要把结果放到xmm0中才可以。

定义C文件floattest.c如下:

#include <stdio.h>

float areafunc(int);//声明函数

int main()
{
        int radius = 10;
        float result;
        result = areafunc(radius);
        printf("The result is %f\n", result);

        result = areafunc(2);
        printf("The result is %f\n", result);
        return 0;
}

编译:

gcc -o floattest floattest.c areafunc.s

输出结果如下:

# ./floattest

The result is 314.159271

The result is 12.566371

 

示例四混合数据类型输入值

以一个双精度浮点输入值和一个整数输入值的汇编语言函数为例子。

汇编文件testfunc.s如下:

.section .text
.type testfunc, @function
.globl testfunc
testfunc:
   pushq %rdi;//第一个整型参数位于rdi寄存器中
   filds (%rsp)
   movq %xmm0, %rsi;//浮点参数位于xmm0寄存器中
   pushq %rsi
   fldl (%rsp)
   fmul %st(1),%st(0)
   fstpl (%rsp)
   movq (%rsp),%xmm0
   popq %rsi
   popq %rdi

   ret

第一个参数是双精度浮点值,第二个参数是整数。

定义C语言文件prog.c如下:

#include <stdio.h>

double testfunc(double, int);

int main()
{
        double data1 = 3.14159;
        int data2 = 10;
        double result;

        result = testfunc(data1, data2);
        printf("The proper result is %f\n", result);
        return 0;
}

编译文件如下:

gcc -g -o prog prog.c testfunc.s

示例五超6个参数输入

这里共8个参数。计算表达式:((43.65/22+(76.34*3.1))/((12.43*6)-(140.2/94.21))

定义汇编文件fpmathfunc.s

.section .text
.type fpmathfunc, @function
.globl fpmathfunc
fpmathfunc:

   push %rdi;//第一个整数参数value2, 56(%rsp)
   push %rsi;//第二个整数参数value6, 48(%rsp)
   movq %xmm0, %rsi
   push %rsi;// 第一个浮点参数value1, 40(%rsp)
   movq %xmm1, %rsi 
   push %rsi;// 第二个浮点参数value3, 32(%rsp)
   movq %xmm2, %rsi 
   push %rsi;// 第三个浮点参数value4, 24(%rsp)
   movq %xmm3, %rsi 
   push %rsi ;// 第四个浮点参数value5, 16(%rsp)
   movq %xmm4, %rsi 
   push %rsi ;// 第五个浮点参数value7,8(%rsp)
   movq %xmm5, %rsi 
   push %rsi ;// 第六个浮点参数value8,(%rsp)
   flds 40(%rsp)
   fidiv 56(%rsp)
   flds 32(%rsp)
   flds 24(%rsp)
   fmul %st(1), %st(0)
   fadd %st(2), %st(0)
   flds 16(%rsp)
   fimul 48(%rsp)
   flds 8(%rsp)
   flds (%rsp)
   fdivrp
   fsubr %st(1), %st(0)
   fdivr %st(2), %st(0)
   fsts (%rsp)
   movq (%rsp),%xmm0
//恢复栈,压栈几次出栈几次,都可以丢给rdi寄存器,反正用不到了,或者直接操作rsp寄存器。
   addq $64,%rsp
   ret
# fpmathfunc.s - An example of reading multiple input values

定义C文件mathtest.c程序如下:

#include <stdio.h>

float fpmathfunc(float, int, float, float, float, int, float, float);

int main()
{
        float value1 = 43.65;//浮点参数
        int value2 = 22; //第一个整型参数
        float value3 = 76.34; //浮点参数
        float value4 = 3.1; //浮点参数
        float value5 = 12.43; //浮点参数
        int value6 = 6; //整型参数
        float value7 = 140.2; //浮点参数
        float value8 = 94.21; //浮点参数
        float result;
        result = fpmathfunc(value1, value2, value3, value4,
                            value5, value6, value7, value8);
        printf("The final result is %f\n", result);
        return 0;
}

编译gcc -o -g mathtest mathtest.c fpmathfunc.s

# ./mathtest

The final result is 3.264907

64/32位Linux系统的差异(地址空间布局,系统调用)对比分析 映射地址:可以看到,对应的地址0x7fd9b8c00000是PSE页,映射了10M,是PMD级的大页映射,也就是2M页面的映射。连续影射了5个PMD大页。这些大页的分配是在mmap后,执行memset(addr, 0x5a, ...)时通过page fault流程进行分配的,对应执行hugetlb_fault的执行流程。 阅读详情

相关推荐

47、X86-64 汇编语言优化与开发指南

本博客详细介绍了x86-64汇编语言的优化与开发指南,涵盖从指令集扩展测试、基准计时目标设定到汇编代码编写、测试与优化的完整流程。内容包括Windows和Linux系统下的开发工具配置、代码示例及操作步骤,并分析了关键性能优化策略和注意事项,旨在帮助开发者提升代码性能与开发效率。

u0v1w2x3的博客 92

Linux系统64位AT&T系统调用汇编指令syscall

在Linux中syscall是系统调用)的指令。想要深入了解syscall的作用,就需要了解特权级别。现代计算机通常采用名为的机制来保护整个系统的数据和功能,使其免受故障和外部恶意行为的伤害。这种方式通过提供多种不同层次的资源访问级别,即特权级别,来限制不同代码的执行能力。Intel x86 架构中,特权级别被分为 4 个层次,即Ring0Ring3。其中,Ring0层拥有最高特权,它具有对整个系统的最大控制能力,内核代码通常运行于此。相对地,Ring3。

qq_42108074的博客 2026

攀藤PMS系列传感器STM32驱动开发与数据解析实战

本文详细介绍了攀藤PMS系列传感器与STM32微控制器的驱动开发与数据解析实战,涵盖硬件连接、数据协议解析、驱动源码编写及数据处理优化。重点解析了传感器数据帧结构,提供了完整的STM32驱动实现代码,并分享了实际应用中的问题排查与性能优化经验,帮助开发者快速实现高精度颗粒物浓度检测。

milk8的博客 358

Linux x86_64 汇编语言的编写

Linux x86_64 汇编语言输出 helloworld 的编写

小立仔 2750

【Docker】Docker安装Hadoop分布式集群

hadoop目录安装在:/usr/local/hadoop-2.7.0/etc/hadoop。访问Hadoop102:9870,查看是否能够看到hdfs界面。访问hadoop103:8088,查看能够看到yarn界面。在yarn上可以看到执行情况。

weixin_46429290的博客 3468

信号与系统——卷积、相关运算与FFT关系以及工程应用(三)

卷积运算、相关运算

qq_35028634的博客 6623

x86-64汇编入门

前言 去年在看协程相关内容的时候,通读了腾讯的libco。其中切换协程的一小段代码是用汇编实现的,当时没有去搞明白这一块。最近趁着项目空闲查阅了x64汇编的相关资料,这篇博客打算总结一下,方便以后查阅。 本篇主要翻译自Introduction to X86-64 Assembly for Compiler Writers由于是入门教程,原文中函数调用部分的描述和实际所出入, 我补上了相关...

麦峰强的博客 1万+

论文阅读《Eigen-GNN: A Graph Structure Preserving Plug-in for GNNs》

好久没看论文了,感觉好生疏 关于这篇文章的大致脉络,这篇文章已经介绍过了。

且视他人之疑目如盏盏鬼火,大胆地去走你的夜路 465

X86_64函数调用汇编程序分析

将函数参数rdi的值存储到当前栈帧的-0x28位置。将函数参数rdx的值存储到当前栈帧的-0x38位置。将当前栈帧的-0x40位置的值加载到寄存器rax中。将当前栈帧的-0x28位置的值加载到寄存器rax中。将当前栈帧的-0x10位置的值加载到寄存器rax中。将当前栈帧的-0x10位置的值加载到寄存器rdx中。将当前栈帧的-0x28位置的值加载到寄存器rax中。将当前栈帧的-0x20位置的值加载到寄存器rax中。将寄存器rax的值存储到当前栈帧的-0x20位置。

天使之翼 2377

链接文件及功能安全:英飞凌官方文档摘录 - 基于Tasking与AURIX TC3xx MCAL中Link文件解析以及代码变量定位方法详解

Data区域是用来存放带初始化值的全局变量,在link文件中,这个区域有两种类型,预先定义的区域和默认区域。预先定义的Data区域,例如.data.Ifx_Ssw_Tc1和.data.Cpu1_Main.*,在cpu1_main.c中如果定义了一个带初始化值的变量,则它会放在DSRAM1中的.data.Cpu1_Main.*段中。

梦想技术家 542

一步步教你使用 NVIDIA 推出的全新GPU加速求解器 cuOpt:解锁超高效率的求解体验

未完成

Linshaodan520的博客 878

Linux 页表机制详解(x86_64 架构)

本文系统介绍了x86_64架构下Linux系统的四级页表机制。详细解析了PGD、PUD、PMD和PT四级页表结构及其8字节页表项(PTE)的存储格式,包含52位物理地址和12位标志位。分析了页表空间占用情况,每级默认4KB,并讨论了2MB/1GB大页等特殊情况。同时阐述了内核与用户页表的隔离机制,以及CR3寄存器、TLB等硬件支持。最后概述了内核管理页表的关键数据结构和分配函数,为AI计算相关的内核驱动开发提供了内存管理方面的理论基础。

图形/计算GPU的驱动与虚拟化技术分享园地 2935

《SOC架构-ARM架构-文档导读》-目录

小白请看“Armv8/Armv9架构从入门到精通”专栏。以翻译为主的,深度深度深度深度/深入深入深入 学习ARM架构的文章。

baron-周贺贺-代码改变世界ctw 2091

Linux 内核揭秘:深入解析 x86_64 分页机制(Paging Theory)

在深入学习 Linux 内核初始化流程之前,必须先理解一个最核心的底层机制——**分页(Paging)**:它是将线性地址转换为物理地址的机制,也是 x86_64 架构下虚拟内存系统、按需分页与内存保护得以实现的基础。本文以《linux-insides-zh》的 [Theory/linux-theory-1.md](https://link.gitcode.com/i/8f09bfa8914085

gitblog_00868的博客 812

嵌入式Zephyr RTOS面试题及参考答案

在Zephyr中,为自定义外设编写Devicetree绑定(Bindings)有助于内核理解设备树中自定义外设节点的含义和属性。首先,需要创建一个.yaml格式的绑定文件,通常存放在目录下对应的子目录中,文件名应能反映外设的类型和功能。绑定文件的开头要定义基本信息,包括字段,用于简要描述外设的功能和用途;compatible字段,它是一个字符串列表,用于匹配设备树中自定义外设节点的compatible属性,设备树节点和绑定文件通过这个字段关联起来。接下来,要定义外设节点的属性。使用properties。

大模型大数据攻城狮的专栏 994

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

多语言团队看不懂英文提示?commitlint 国际化中文提示配置完整指南

跨国团队里,新同事对着 commitlint 交互式提交的英文提示无从下手,提交信息写得五花八门,审查起来费劲。commitlint 的 prompt 配置天然支持国际化,把提示和提交类型换成中文即可,这篇从装好到长期维护一次讲清。 [![commitlint 中文提示与提交类型自定义的交互界面](https://raw.gitcode.com/gh_mirrors/co/commitlint/

gitblog_00554的博客 951

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

堆的地址怎么比栈还高啊?+栈和堆的地址哪个高+64位系统,调试时显示的地址为48位+linux每种变量的存储地址

文章目录堆的地址怎么比栈还高啊?栈和堆的地址哪个高64位系统,调试时显示的地址为48位 堆的地址怎么比栈还高啊? #include <stdio.h> #include <stdlib.h> static int a = 0; const char* p = "wefrfg"; void main() { int temp; printf("%p\n", &temp); int* pointer = (int*)malloc(sizeof(int)*99999);

fgh123的博客 1283

深度学习工具包 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")

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Linux 内核初始化(一):x86_64 内核入口点、GDT 与早期页表构建全解析

本篇是 Linux 内核初始化章节的第一部分,承接 [Linux 内核启动过程](https://link.gitcode.com/i/ce0a359a97a8bb5ac2f38f6255d3eabc) 的结尾,从 `startup_64` 这一 x86_64 内核真正的入口点出发,逐条指令剖析内核在进入 C 语言世界之前必须完成的三个核心动作:搭建执行环境(栈、`gs` 寄存器)、装载属于内核自

gitblog_00067的博客 365

【X86】实现x86-linux内核项目

把解压包x86安装在C盘地下,把bin目录加入到系统配置当中,加载GCC工具链。c02.02 Windows开发环境配置_哔哩哔哩_bilibili。安装cmake 软件自带加载path目录。把qemu也下载安装,作为模拟器。按照vscode并且增加扩展。暂时还没做完 做完后会上传。安装git并且按照环境变量。

qq_58358642的博客 166

Linux 内核系统调用深度解析:概念、处理流程与实现(linux-insides-zh SysCall 章节)

本篇文章以 linux-insides-zh 仓库 [SysCall 章节](https://link.gitcode.com/i/04e71131c2af74d26658d07b8681e6bc) 为核心,系统梳理 Linux 内核中"系统调用"这一机制从用户空间发起到内核处理的完整链路:包括系统调用概念与汇编示例、内核侧的系统调用表与入口初始化、`vsyscall`/`vDSO` 加速机制、`

gitblog_00838的博客 955

Linux 内核揭秘:中断描述符表(IDT)——门描述符、错误代码与 x86_64 中断处理机制全解

中断描述符表(Interrupt Descriptor Table,简称 IDT)是 x86/x86_64 体系结构上连接 CPU 中断信号与内核处理程序的核心数据结构。本文以 [linux-kernelstructure-1.md](https://link.gitcode.com/i/3c2d8c4a554c167cfe483ad729bf9337) 为主体,结合本仓库 [中断与中断处理](h

gitblog_00025的博客 461

Linux 下用汇编语言处理文件

Linux 下用汇编语言处理文件1.1 UNIX文件的概念1.2 打开和关闭文件1.3 访问类型1.4 UNIX 权限1.5 打开错误返回代码1.6 缓冲区和 .bss1.7 标准文件和特殊文件1.8 在程序中使用文件GDB toupper 程序调试部分内容表参考 作者:高玉涵 时间:2012.10.12 15:56 博客:blog.csdn.net/cg_i 环境:Linux 7e142849497c 5.10.47-linuxkit #1 SMP Sat Jul 3 21:51:47 UTC 2021

1304

Linux x86_64 中断描述符表(IDT)完全解析:向量、门描述符、错误码与 IST 机制

中断描述符表(Interrupt Descriptor Table,IDT)是 x86_64 架构中连接中断/异常向量号与处理器入口的关键数据结构,也是 Linux 内核中断子系统一切工作的起点。本文以 linux-insides 仓库 [X86/linux-x86-2.md](https://link.gitcode.com/i/701222aaaae7d5acd480388a4eb3e038)

gitblog_00970的博客 208

【珍藏整理】Cameralink 协议 Verilog FPGA 实现:从零集成到上板实战

这个项目把 Cameralink 相机接口协议完整做成了 FPGA 上的 Verilog RTL,拿来即用。想找 Cameralink 协议 FPGA 源码、或想走一遍 Verilog 仿真上板流程的同学可以直接入手,适合相机接口新手和普通 FPGA 开发者。 ## 一、它到底帮你省了什么 Cameralink 是机器视觉里常见的高速数字相机接口,按传统做法需要在板子上配专用接口芯片,还得去啃

gitblog_00964的博客 1044

Linux 内核揭秘(linux-insides-zh):从 `syscall` 指令到系统调用处理程序的完整旅程

本篇文章是《Linux 内核揭秘》中文版(linux-insides-zh)[SysCall 章节](https://link.gitcode.com/i/12ce3732a26d7d6d1ddf090ef9c28cb6) 的第二部分,聚焦 **x86_64 架构下 Linux 内核如何响应并处理来自用户空间的系统调用**。通过阅读本文,你将掌握三件事:系统调用表 `sys_call_table`

gitblog_00386的博客 446

在ARM设备上运行x86-64 Windows程序:Wine、FEX-Emu与DXMT三层翻译栈实战解析

跨平台兼容层通过API翻译和指令集翻译技术,实现在非原生架构上运行异构程序。Wine作为API翻译器,将Windows系统调用转换为POSIX调用;FEX-Emu通过动态二进制翻译,把x86-64指令转为ARM64指令;DXMT则在Metal之上实现Direct3D翻译。三层栈串联协作,使Windows程序能在ARM设备上执行,但性能损耗呈乘法关系。该方案适用于ARM Linux、macOS及越狱iOS设备,可运行轻量级Windows应用,但重度3D游戏和日常使用仍面临挑战。

weixin_34088583的博客 412
上一篇: 第46部分-Linux x86 64位汇编 斐波那契和汇编性能增益
下一篇: 第48部分- Linux x86 64位汇编 C++调用汇编
badman250
博客等级 码龄17年 2391粉丝 1479原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值