w1coding.comAll tutorials

Assembly Introduction

Assembly lessons
  1. Environment Setup
  2. Introduction
  3. Syntax
  4. Datamovement
  5. Operators
  6. Control
  7. Loops
  8. Interupts
  9. Functions
  10. Memory
  11. System
  12. Debugging
  13. Macros
  14. Execution
  15. Floating
  16. Interupts
  17. Optimization
  18. Linking
  19. Inline
  20. Registers
  21. Bootloader
  22. Macros
  23. Stack
  24. Call
  25. Technique
  26. Responsive

Introduction to Assembly Language

Assembly language is a low-level programming language that provides direct control over hardware. It is specific to a computer's architecture and is often used to write performance-critical code.

Why Learn Assembly?

  • Direct hardware control.
  • Optimized performance for critical tasks.
  • Understanding how computers work at a fundamental level.

Basic Structure of Assembly Code

An assembly program consists of three main sections:

  • Data Section: Defines variables.
  • BSS Section: Defines uninitialized variables.
  • Text Section: Contains the code instructions.

Sample Program: Hello, World

section .data
    msg db "Hello, World!", 0xA  ; Message with a newline
    len equ $ - msg             ; Length of the message

section .text
    global _start

_start:
    mov rax, 1          ; System call: write
    mov rdi, 1          ; File descriptor: stdout
    mov rsi, msg        ; Message address
    mov rdx, len        ; Message length
    syscall             ; Make the system call

    mov rax, 60         ; System call: exit
    xor rdi, rdi        ; Exit code: 0
    syscall             ; Make the system call
    

This code, written for Linux x86-64 architecture, outputs "Hello, World!" to the terminal.