Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shikha-code36/assembly-arm-tutorial
A Beginner’s Guide to Assembly ARM language
https://github.com/shikha-code36/assembly-arm-tutorial
arm armv7 asm assembler assembly assembly-language assembly-language-programming assemblyscript gdp linux-debian raspberry raspberry-pi
Last synced: about 1 month ago
JSON representation
A Beginner’s Guide to Assembly ARM language
- Host: GitHub
- URL: https://github.com/shikha-code36/assembly-arm-tutorial
- Owner: Shikha-code36
- License: mit
- Created: 2024-06-14T11:47:26.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-18T12:18:46.000Z (5 months ago)
- Last Synced: 2024-09-30T05:45:28.205Z (about 2 months ago)
- Topics: arm, armv7, asm, assembler, assembly, assembly-language, assembly-language-programming, assemblyscript, gdp, linux-debian, raspberry, raspberry-pi
- Language: Assembly
- Homepage:
- Size: 286 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Guide to ARM Assembly Language
## Introduction
ARM assembly language is a low-level programming language designed for ARM (Advanced RISC Machine) processors, which are prevalent in embedded systems like smartphones and laptops. It enables direct interaction with the hardware, offering precise control over the device's operations.It is estimated that over 200 billion devices contain an ARM chip, making the arm language valuable to understand. By understanding the arm assembly language, programmers can work at a lower level, allowing them to write code that interacts with hardware in an efficient manner. Arm is a programming language that's used in a variety of different applications. You see it in a lot of different embedded devices. And really popular devices such as different phones, a lot of Android devices and some iPhone devices are running ARM based chips.
## Registers
Registers are fast-access storage locations within the CPU that hold data temporarily during execution. They play a crucial role in assembly language programming due to their speed compared to memory access.### General-Purpose Registers (R0-R6)
- **R0-R6**: Used for general computations and temporary storage.
- **Example**: Storing and adding numbers.
```assembly
MOV R0, #5 ; Move 5 into R0
MOV R1, #10 ; Move 10 into R1
ADD R2, R0, R1; Add R0 and R1, result in R2 (R2 = 15)
```### Special-Purpose Registers
- **R7**: System Call Register for OS services.
```assembly
MOV R7, #1 ; System call number for program exit
SWI 0 ; Invoke system call
```
- **SP (Stack Pointer)**: Points to the stack's top for managing function calls and local variables.
```assembly
PUSH {R0} ; Push R0 onto the stack
POP {R0} ; Pop from stack into R0
```
- **LR (Link Register)**: Holds the return address for functions.
```assembly
BL function ; Call 'function', store return address in LR
```
- **PC (Program Counter)**: Points to the next instruction.
```assembly
LDR PC, [R0] ; Load address into PC from R0
```### CPSR (Current Program Status Register)
Stores flags indicating conditions after operations, like negative or zero results. It guides conditional execution based on these flags.**Example**: Using flags for conditional branching.
```assembly
CMP R0, R1 ; Compare R0 and R1
BEQ label ; If equal (Zero flag set), branch to 'label'
```## Memory Sizes
- **Word**: Maximum data size for a register (32 bits on a 32-bit processor).
- **Half-word**: Half of a word (16 bits).
- **Byte**: Always 8 bits.## Stack Memory
A slower but larger capacity memory used for complex data like arrays. Managed using the stack pointer (SP).## Detailed Register Usage Examples
### Using General-Purpose Registers
```assembly
MOV R3, #15 ; Store 15 in R3
MOV R4, #20 ; Store 20 in R4
MUL R5, R3, R4; Multiply R3 by R4, result in R5 (R5 = 300)
```### Managing Function Calls with LR and SP
```assembly
PUSH {LR} ; Save LR before function call
BL some_func ; Call 'some_func', LR updated with return address
POP {LR} ; Restore LR after function return
```### Conditional Execution with CPSR Flags
```assembly
SUBS R6, R4, R3; Subtract R3 from R4, update flags based on result
BMI negative ; Branch to 'negative' if result is negative (Negative flag set)
```This guide provides an organized overview of ARM assembly language programming concepts.Beginners can use this as a foundation for further learning and practice in ARM assembly programming.
### File Extensions for ARM Assembly
- **.s**: Use this extension for ARM assembly code files intended for the GNU Assembler (GAS), which is part of the GNU toolchain commonly used on Linux systems, including the Raspberry Pi.
- **.asm**: This extension can also be used for assembly code files but is more commonly associated with Intel syntax and assemblers like NASM or MASM. For ARM assembly on Raspberry Pi, `.s` is the preferred extension when using GAS.
## Comprehensive ARM Assembly Programming Guide
This section outlines the complete journey of learning ARM Assembly Language, from writing your first program to advanced hardware interactions and debugging techniques.
- [x] [First Program](first_program)
- [x] [Addressing Modes](addressing_modes)
- [x] [Arithmetic and CPSR Flags](arithmetic_and_cpsr_flags)
- [x] [Logical Operations](logical_operations)
- [x] [Logical Shifts and Rotations](logical_shifts_and_rotations)
- [x] [Conditions and Branches](conditions_and_branches)
- [x] [Loops with Branches](loops_with_branches)
- [x] [Conditional Instruction Execution](conditional_instruction_execution)
- [x] [Branch with Link Register and Returns](branch_with_link_register_and_returns)
- [x] [Preserving and Retrieving Data From Stack Memory](preserving_and_retrieving_data_from_stack_memory)
- [x] [Hardware Interactions](hardware_interactions)
- [x] [Setting Up QEMU for ARM](setting_up_qemu_for_arm)
- [x] [Printing Strings to Terminal](printing_strings_to_terminal)
- [x] [Debugging Arm Programs with Gdb](debugging_arm_programs_with_gdb)## Acknowledgements
This guide is based on the video tutorial by Scott Cosentino. You can watch the full tutorial [here](https://youtu.be/gfmRrPjnEw4?si=WZeq4fv6NHZRJnpT) and visit his channel [Olive Stem Learning](https://www.youtube.com/@olivestemlearning) for more educational content.
A special thanks to Scott Cosentino for the comprehensive tutorial on ARM assembly language.
## Show Your Support
If you found this guide helpful, please consider starring the repository to show your support. Your star helps increase visibility and encourages more learners to discover and benefit from these educational resources.
## License
This project is released under the [MIT License](LICENSE).