首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在64位RaspberryPi中编译32位ARM?

如何在64位RaspberryPi中编译32位ARM?
EN

Stack Overflow用户
提问于 2020-09-08 19:38:03
回答 1查看 539关注 0票数 0

我正在使用ARM32做一些练习,但使用的是64位RaspberryPi。

代码如下:

代码语言:javascript
运行
复制
.global main

main:
        mov r0,#0
        mov r1,#5
        push {lr,ip}
        bl factorial
        pop {lr,ip} 
        bx lr

factorial:
        cmp r1,#1
        moveq pc,lr
        sub r1,r1,#1
        mul r0,r1,r0
        b factorial

如果我试图编译factorial.s,我会收到一堆错误:

代码语言:javascript
运行
复制
cc    factorial.s   -o factorial
factorial.s: Assembler messages:
factorial.s:4: Error: operand 1 must be an integer register -- `mov r0,#0'
factorial.s:5: Error: operand 1 must be an integer register -- `mov r1,#5'
factorial.s:6: Error: unknown mnemonic `push' -- `push {lr,ip}'
factorial.s:8: Error: unknown mnemonic `pop' -- `pop {lr,ip}'
factorial.s:9: Error: unknown mnemonic `bx' -- `bx lr'
factorial.s:12: Error: operand 1 must be an integer or stack pointer register -- `cmp r1,#1'
factorial.s:13: Error: unknown mnemonic `moveq' -- `moveq pc,lr'
factorial.s:14: Error: operand 1 must be an integer or stack pointer register -- `sub r1,r1,#1'
factorial.s:15: Error: operand 1 must be a SIMD vector register -- `mul r0,r1,r0'
make: *** [<builtin>: factorial] Error 1

我想这是因为我是在64位的树莓中编译ARM32的。

如何在64位RaspberryPi中编译ARM32?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-08 21:16:33

一个简单的解决方案是在你的RaspberryPI中使用32位版本的Linux。

也就是说,您需要在您的64位系统上安装诸如arm-linux-gnueabihf之类的工具链。如果您的Linux系统是基于Debian的,您可以通过执行以下命令列出可用的软件包:

sudo apt-cache search gnueabihf

另一种方法是从头开始构建binutils:

代码语言:javascript
运行
复制
wget https://mirror.csclub.uwaterloo.ca/gnu/binutils/binutils-2.35.tar.xz
tar Jxf binutils-2.35.tar.xz
mkdir binutils
cd binutils
../binutils-2.35/configure --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- --prefix=/usr/local
make all
sudo make install

/usr/local/bin/arm-linux-gnueabihf-as -o factorial.o factorial.s
factorial.s: Assembler messages:
factorial.s:6: Warning: register range not in ascending order
factorial.s:8: Warning: register range not in ascending order

push {ip, lr}替换push {lr,ip},用pop {ip, lr}替换pop {lr, ip}之后

代码语言:javascript
运行
复制
/usr/local/bin/arm-linux-gnueabihf-as -o factorial.o factorial.s
/usr/local/bin/arm-linux-gnueabihf-objdump -d factorial.o

factorial.o:     file format elf32-littlearm


Disassembly of section .text:

00000000 <main>:
   0:   e3a00000        mov     r0, #0
   4:   e3a01005        mov     r1, #5
   8:   e92d5000        push    {ip, lr}
   c:   eb000001        bl      18 <factorial>
  10:   e8bd5000        pop     {ip, lr}
  14:   e12fff1e        bx      lr

00000018 <factorial>:
  18:   e3510001        cmp     r1, #1
  1c:   01a0f00e        moveq   pc, lr
  20:   e2411001        sub     r1, r1, #1
  24:   e0000091        mul     r0, r1, r0
  28:   eafffffa        b       18 <factorial>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63793099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档