• 2.5OpenEuler 中C与汇编的混合编程


    1.任务详情

    1.在X86_64架构下实践2.5中的内容,提交代码和实践截图
    2把2.5的内容在OpenEuler中重新实践一遍,提交相关代码和截图
    3.实验内容要经过答辩才能得到相应分数

    2.1

    代码:

    /**********a.c file********/
    #include <stdio.h>
    
    extern int B();
    
    int A(int x,int y)
    {
        int d,e,f;
        d = 4;e = 5;f = 6;
        f = B(d,e);
    }
    

    汇编代码:

    	.file	"a.c"
    	.text
    	.globl	A
    	.type	A, @function
    A:
    .LFB0:
    	.cfi_startproc
    	endbr32
    	pushl	%ebp
    	.cfi_def_cfa_offset 8
    	.cfi_offset 5, -8
    	movl	%esp, %ebp
    	.cfi_def_cfa_register 5
    	pushl	%ebx
    	subl	$20, %esp
    	.cfi_offset 3, -12
    	call	__x86.get_pc_thunk.ax
    	addl	$_GLOBAL_OFFSET_TABLE_, %eax
    	movl	$4, -20(%ebp)
    	movl	$5, -16(%ebp)
    	movl	$6, -12(%ebp)
    	subl	$8, %esp
    	pushl	-16(%ebp)
    	pushl	-20(%ebp)
    	movl	%eax, %ebx
    	call	B@PLT
    	addl	$16, %esp
    	movl	%eax, -12(%ebp)
    	nop
    	movl	-4(%ebp), %ebx
    	leave
    	.cfi_restore 5
    	.cfi_restore 3
    	.cfi_def_cfa 4, 4
    	ret
    	.cfi_endproc
    .LFE0:
    	.size	A, .-A
    	.section	.text.__x86.get_pc_thunk.ax,"axG",@progbits,__x86.get_pc_thunk.ax,comdat
    	.globl	__x86.get_pc_thunk.ax
    	.hidden	__x86.get_pc_thunk.ax
    	.type	__x86.get_pc_thunk.ax, @function
    __x86.get_pc_thunk.ax:
    .LFB1:
    	.cfi_startproc
    	movl	(%esp), %eax
    	ret
    	.cfi_endproc
    .LFE1:
    	.ident	"GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0"
    	.section	.note.GNU-stack,"",@progbits
    	.section	.note.gnu.property,"a"
    

    截图:

    2.2

    代码:

    #include <stdio.h>
    extern int get_ebp();
    extern int get_esp();
    int main()
    {
        int ebp, esp;
        ebp = get_ebp();
        esp = get_esp();
        printf("ebp=%8x     esp=%8x\n",ebp,esp);
    }
    

    汇编代码:

        .section .text
        .global get_esp, get_ebp
    get_esp:
        movl    %esp, %eax
        ret
    get_ebp:
        movl    %ebp, %eax
        ret
    

    截图:

    2.3

    代码:

    #include <stdio.h>
    extern int mysum(int a, int b);
    int main()
    {
        int a,b,c;
        a = 123; b = 456;
        c = mysum(a,b);
        printf("c = %d\n",c);
    }
    

    汇编代码:

        .text
        .global mysum,printf
    mysum:
        pushl %ebp
        movl %esp, %ebp
    
        movl 8(%ebp), %eax
        addl 12(%ebp), %eax
    
        movl %ebp, %esp
        pop  %ebp
        ret
    

    截图:

    2.4

    代码:

    int a,b;
    int main()
    {
    	a = 100;b = 200;
    	sub();
    }
    

    汇编代码:

    	.text
    	.global sub,a,b,printf
    sub:
    	pushl %ebp
    	movl %esp,%ebp
    	
    	pushl b
    	pushl a
    	pushl $fmt
    	call printf
    	addl $12,%esp
    	
    	movl %ebp,%esp
    	popl %ebp
    	ret
    	
    	
    	    .data
    fmt:	.asciz "a=%d b=%d\n"
    

    截图:

  • 相关阅读:
    【原创】VNC-view配置
    【LVM】LVM自动扩容脚本
    【linux磁盘分区--格式化】fdisk,parted,mkfs.ext3
    【原】Centos 7 下创建LVM流程
    【Spring-AOP-学习笔记-7】@Around增强处理简单示例
    【转】libvirt kvm 虚拟机上网 – Bridge桥接
    【phantomjs】使用phantomjs生成highChart的图片(待完善)
    【Redis】使用Redis Sentinel实现Redis HA
    【Redis】配置redis主从复制
    【转载】优秀博文转载
  • 原文地址:https://www.cnblogs.com/tzy20191327/p/15646236.html
Copyright © 2020-2023  润新知