• 2.4 OpenEuler中C语言中的函数调用测试


    2.4 OpenEuler中C语言中的函数调用测试

    任务详情

    1. 在X86_64架构下实践2.4中的内容
    2. 通过GDB查看寄存器的内容,把教材中的图填入具体的值
    3. 把2.4的C代码在OpenEuler中重新实践一遍,绘制出ARM64的逻辑框图

    任务一X86_64架构下实践2.4

    操作环境: Ubuntu Kylin

    2.4.1

    code

    #include <stdio.h>
    
    int sub(int x,int y)
    {
        int u,v;
        u = 4;v = 5;
        return x+y+u+v;
    }
    
    int main()
    {
        int a,b,c;
        a = 1;b = 2;c = 3;
        c = sub(a,b);
        printf("c = %d\n",c);
    }
    

    code.s

    sub:
    .LFB0:
            .cfi_startproc
            endbr64
            pushq   %rbp
            .cfi_def_cfa_offset 16
            .cfi_offset 6, -16
            movq    %rsp, %rbp
            .cfi_def_cfa_register 6
            movl    %edi, -20(%rbp)
            movl    %esi, -24(%rbp)
            movl    $4, -8(%rbp)
            movl    $5, -4(%rbp)
            movl    -20(%rbp), %edx
            movl    -24(%rbp), %eax
            addl    %eax, %edx
            movl    -8(%rbp), %eax
            addl    %eax, %edx
            movl    -4(%rbp), %eax
            addl    %edx, %eax
            popq    %rbp
            .cfi_def_cfa 7, 8
            ret
            .cfi_endproc
    .LFE0:
            .size   sub, .-sub
            .section        .rodata
    .LC0:
            .string "c = %d\n"
            .text
            .globl  main
            .type   main, @function
    main:
    .LFB1:
            .cfi_startproc
            endbr64
            pushq   %rbp
            .cfi_def_cfa_offset 16
            .cfi_offset 6, -16
            movq    %rsp, %rbp
            .cfi_def_cfa_register 6
            subq    $16, %rsp
            movl    $1, -12(%rbp)
            movl    $2, -8(%rbp)
            movl    $3, -4(%rbp)
            movl    -8(%rbp), %edx
            movl    -12(%rbp), %eax
            movl    %edx, %esi
            movl    %eax, %edi
            call    sub
            movl    %eax, -4(%rbp)
            movl    -4(%rbp), %eax
            movl    %eax, %esi
            movl    $.LC0, %edi
            movl    $0, %eax
            call    printf
            movl    $0, %eax
            leave
            .cfi_def_cfa 7, 8
            ret
            .cfi_endproc
    

    GDB查看寄存器内容

    1

    填写教材中内容

    HIGH PC rbp c b a tmp pc rbp v u tmp x y LOW
    .... unknown 0x0 0x3 0x2 0x1 4bytes 0x401191 0x7fffffffe240 0x5 0x4 0x1 0x2 ....

    任务二arm64下实践2.4

    操作环境: openeuler with arm

  • 相关阅读:
    ThreadLocal用法
    Spring Cloud Alibaba 使用RestTemplate进行服务消费
    Spring Cloud Alibaba 使用Nacos作为配置管理中心
    Spring Cloud Alibaba 使用Nacos作为服务注册中心
    Spring Cloud Alibaba 介绍及工程准备
    Redission 支持GsonCodec
    Maven Archetype快速构建项目
    拜占庭将军问题
    Paxos算法详解
    Paxos、Raft分布式一致性算法应用场景(转载)
  • 原文地址:https://www.cnblogs.com/WANGYUHAN/p/15647440.html
Copyright © 2020-2023  润新知