尝试使用QEMU终端命令编译ARM64时的核心转储问题

发布于 2025-01-22 05:14:44 字数 3390 浏览 1 评论 0原文

我正在研究ARM64 GCC 11.2组件中的程序,并且正在遇到一个我不知道如何修复的错误。该程序的目的是递归地调用双重数字数量的函数,然后打印出最高的双重函数。在C中,此函数是:

#include <stdio.h>

#define SIZE 10 
         
double arr[SIZE] = {6.221, 1.0,  14.1, 46.5, 62.1, 7.7, 4.4, 1.5, 500.023, 2.1}; // get the array

double max_value(double array[], int size) {
  
    if (size == 1) {
        return array[size - 1];
    } else {
        double max = max_value(array, size - 1);
        if (array[size - 1] > max)
            max = array[size - 1]; // iterate to the next index of the array
        return max;
    }
}

int main() {
    printf("%g\n", max_value(arr, SIZE)); // print`
    return 0;
}


考虑到这一点,我已经在ARM64 GCC 11.2中写下了以下内容:




.global _start // https://stackoverflow.com/questions/17898989/what-is-global-start-in-assembly-language
       // global_start adds _start to the object code, global is NASM specific
       // and it will start the file

.text 

.extern printf // start the file 
maxvalue:
        stp     x29, x30, [sp, -48]!
        mov     x29, sp
        str     x0, [sp, 24]
        str     w1, [sp, 20]
        ldr     w0, [sp, 20]
        cmp     w0, 1
        bne     .L2
        ldr   x0, [sp, 20]
        lsl     x0, x0, 3
        sub     x0, x0, #8
        ldr     x1, [sp, 24]
        add     x0, x1, x0
        ldr     d0, [x0]
        b       .L3
.L2:
        ldr     w0, [sp, 20]
        sub     w0, w0, #1
        mov     w1, w0
        ldr     x0, [sp, 24]
        bl      maxvalue
        str     d0, [sp, 40]
        ldr   x0, [sp, 20]
        lsl     x0, x0, 3
        sub     x0, x0, #8
        ldr     x1, [sp, 24]
        add     x0, x1, x0
        ldr     d0, [x0]
        ldr     d1, [sp, 40]
        fcmpe   d1, d0
        bmi     .L6
        b       .L4
.L6:
        ldr   x0, [sp, 20]
        lsl     x0, x0, 3
        sub     x0, x0, #8
        ldr     x1, [sp, 24]
        add     x0, x1, x0
        ldr     d0, [x0]
        str     d0, [sp, 40]
.L4:
        ldr     d0, [sp, 40]
.L3:
        ldp     x29, x30, [sp], 48
        
.LC0:
        .string "%g\n"
_start:
        stp     x29, x30, [sp, -16]!
        mov     x29, sp
        mov     w1, 10
        adrp    x0, arr
        add     x0, x0, :lo12:arr
        bl      maxvalue
        adrp    x0, .LC0
        add     x0, x0, :lo12:.LC0
        bl      printf
        // print a new line
        mov     w0, 10
        bl      putchar


        mov     w0, 0
        ldp     x29, x30, [sp], 16
         

.data
// declare an array - the one I'm using is below
//double arr[SIZE] = {6.221, 1.0,  14.1, 46.5, 62.1, 7.7, 4.4, 1.5, 500.023, 2.1}; // get the array
 
arr:
        .word   -755914244
        .word   1075372621
        .word   0
        .word   1072693248
        .word   858993459
        .word   1076638515
        .word   0
        .word   1078411264
        .word   -858993459
        .word   1078922444
        .word   -858993459
        .word   1075760332
        .word   -1717986918
        .word   1074895257
        .word   0
        .word   1073217536
        .word   893353198
        .word   1082081374
        .word   -858993459
        .word   1073794252



我会遇到这些错误(使用我正在使用的terminal命令的屏幕截图)。

“在此处输入图像说明”

I'm working on a program in ARM64 gcc 11.2 Assembly and am experiencing a bug that I do not know how to fix. The goal of this program is to recursively call a function on a double array of numbers, then print out the highest double. In C, this function is:

#include <stdio.h>

#define SIZE 10 
         
double arr[SIZE] = {6.221, 1.0,  14.1, 46.5, 62.1, 7.7, 4.4, 1.5, 500.023, 2.1}; // get the array

double max_value(double array[], int size) {
  
    if (size == 1) {
        return array[size - 1];
    } else {
        double max = max_value(array, size - 1);
        if (array[size - 1] > max)
            max = array[size - 1]; // iterate to the next index of the array
        return max;
    }
}

int main() {
    printf("%g\n", max_value(arr, SIZE)); // print`
    return 0;
}


With that in mind, I've written the following in ARM64 gcc 11.2:




.global _start // https://stackoverflow.com/questions/17898989/what-is-global-start-in-assembly-language
       // global_start adds _start to the object code, global is NASM specific
       // and it will start the file

.text 

.extern printf // start the file 
maxvalue:
        stp     x29, x30, [sp, -48]!
        mov     x29, sp
        str     x0, [sp, 24]
        str     w1, [sp, 20]
        ldr     w0, [sp, 20]
        cmp     w0, 1
        bne     .L2
        ldr   x0, [sp, 20]
        lsl     x0, x0, 3
        sub     x0, x0, #8
        ldr     x1, [sp, 24]
        add     x0, x1, x0
        ldr     d0, [x0]
        b       .L3
.L2:
        ldr     w0, [sp, 20]
        sub     w0, w0, #1
        mov     w1, w0
        ldr     x0, [sp, 24]
        bl      maxvalue
        str     d0, [sp, 40]
        ldr   x0, [sp, 20]
        lsl     x0, x0, 3
        sub     x0, x0, #8
        ldr     x1, [sp, 24]
        add     x0, x1, x0
        ldr     d0, [x0]
        ldr     d1, [sp, 40]
        fcmpe   d1, d0
        bmi     .L6
        b       .L4
.L6:
        ldr   x0, [sp, 20]
        lsl     x0, x0, 3
        sub     x0, x0, #8
        ldr     x1, [sp, 24]
        add     x0, x1, x0
        ldr     d0, [x0]
        str     d0, [sp, 40]
.L4:
        ldr     d0, [sp, 40]
.L3:
        ldp     x29, x30, [sp], 48
        
.LC0:
        .string "%g\n"
_start:
        stp     x29, x30, [sp, -16]!
        mov     x29, sp
        mov     w1, 10
        adrp    x0, arr
        add     x0, x0, :lo12:arr
        bl      maxvalue
        adrp    x0, .LC0
        add     x0, x0, :lo12:.LC0
        bl      printf
        // print a new line
        mov     w0, 10
        bl      putchar


        mov     w0, 0
        ldp     x29, x30, [sp], 16
         

.data
// declare an array - the one I'm using is below
//double arr[SIZE] = {6.221, 1.0,  14.1, 46.5, 62.1, 7.7, 4.4, 1.5, 500.023, 2.1}; // get the array
 
arr:
        .word   -755914244
        .word   1075372621
        .word   0
        .word   1072693248
        .word   858993459
        .word   1076638515
        .word   0
        .word   1078411264
        .word   -858993459
        .word   1078922444
        .word   -858993459
        .word   1075760332
        .word   -1717986918
        .word   1074895257
        .word   0
        .word   1073217536
        .word   893353198
        .word   1082081374
        .word   -858993459
        .word   1073794252



I'm getting these errors (screenshots with the terminal commands that I'm using & errors generated).

enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文