Skip to content

cyaninfinite/pi_asm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

pi_asm

Exploring assembly with RPi 3B+

System

  • Hardware: Raspberry Pi 3B+
  • OS: Ubuntu 22.04.4 LTS

Prerequisite

Install the following packages.

sudo apt install gcc-arm-linux-gnueabi gdb

Compilation

Default

Compile 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 -nostdlib

Run the executable.

./hello

Debug

Compile 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 -nostdlib

Run with gdb.

gdb ./hello

Display gdb in asm layout.

(gdb) layout asm
(gdb) break 1    # Breakpoint at line 1

References

Notes

Mnemonics

  • Could be upper or lower: add or ADD is okay.
  • Use 'S' in the mnemonic to set the flags in the CPSR (Current Program Status Register) register.

Overview

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

Basics

  • MOV: Move value from source to destination.
  • ADD: Add values.
  • SUB: Subtract values.
  • MUL: Multiply values.

Memory

Only load & store instructions can access memory. (ARM uses load-store architecture)

  • LDR: Load register.
  • STR: Store value from memory to register.

Logical Operators

  • AND: AND operator.
  • ORR: OR operator.
  • EOR: XOR operator.
  • MVN: NOT operator.

Registers

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)

Links

About

Exploring ARMv7 Assembly with RPi 3B+

Topics

Resources

License

Stars

Watchers

Forks