Exploring assembly with RPi 3B+
- Hardware: Raspberry Pi 3B+
- OS: Ubuntu 22.04.4 LTS
Install the following packages.
sudo apt install gcc-arm-linux-gnueabi gdbCompile the file.
# Create obj file via assembler
arm-linux-gnueabi-as hello.s -o hello.o
# Create executable file
arm-linux-gnueabi-gcc hello.o -o hello -nostdlibRun the executable.
./helloCompile the file.
# Create obj file via assembler
arm-linux-gnueabi-as hello.s -g -o hello.o
# Create executable file
arm-linux-gnueabi-gcc hello.o -o hello -nostdlibRun with gdb.
gdb ./helloDisplay gdb in asm layout.
(gdb) layout asm
(gdb) break 1 # Breakpoint at line 1- Could be upper or lower:
addorADDis okay. - Use 'S' in the mnemonic to set the flags in the CPSR (Current Program Status Register) register.
| Instructions \ Options | Immediate | Register |
|---|---|---|
| MOV | Yes | Yes |
| ADD | Yes | Yes |
| SUB | Yes | Yes |
| MUL | No | Yes |
| AND | Yes | Yes |
| ORR | Yes | Yes |
| EOR | Yes | Yes |
| MVN | No | Yes |
- MOV: Move value from source to destination.
- ADD: Add values.
- SUB: Subtract values.
- MUL: Multiply values.
Only load & store instructions can access memory. (ARM uses load-store architecture)
- LDR: Load register.
- STR: Store value from memory to register.
- AND:
ANDoperator. - ORR:
ORoperator. - EOR:
XORoperator. - MVN:
NOToperator.
ARMv7 register length: 32 Bits
r0-r6: General purpose registers, could be used as required.r7: Special register, holds system call number.sp: Stack pointer, point to the next available location in the stack. Use to store variables like strings, arrays, etc. (Extra places to store values)
- Tutorial: https://www.youtube.com/watch?v=kKtWsuuJEDs&list=PLn_It163He32Ujm-l_czgEBhbJjOUgFhg
- ARMv7 emulator: https://cpulator.01xz.net/
- Linux system call table: https://www.chromium.org/chromium-os/developer-library/reference/linux-constants/syscalls/