Reputation: 512
I am doing some exercise with ARM 32, but in a 64 bit RaspberryPi.
Here is the code:
.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
If I try to compile factorial.s, I receive a bunch of errors:
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
I think it's due to the fact I'm compiling ARM32 inside a 64bit Raspberry.
How can I compile ARM32 inside a 64 bit RaspberryPi?
Upvotes: 0
Views: 1880
Reputation: 5925
A simple solution would be to use a 32 bit version of Linux with your RaspberryPI.
This being said, you would need to install a toolchain such as arm-linux-gnueabihf
on your 64 bit system.
If your Linux system is Debian-based, you can list the available packages by executing the following command:
sudo apt-cache search gnueabihf
An alternative would be to build binutils from scratch:
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
After replacing push {lr,ip}
by push {ip, lr}
and pop {lr, ip}
by pop {ip, lr}
:
/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>
Upvotes: 2