{"id":15060088,"url":"https://github.com/kavicastelo/assembly_basics","last_synced_at":"2025-03-15T05:14:37.336Z","repository":{"id":250224138,"uuid":"833778587","full_name":"kavicastelo/assembly_basics","owner":"kavicastelo","description":"This guide is designed to help you learn assembly language from the ground up, focusing on the 64-bit Windows architecture. We'll cover everything from setting up your environment to understanding registers and writing basic programs.","archived":false,"fork":false,"pushed_at":"2024-07-30T19:05:26.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T20:27:48.681Z","etag":null,"topics":["asmx86","assembly","basics","gcc-complier","low-level","mingw-w64","nasm"],"latest_commit_sha":null,"homepage":"https://kavicastelo.github.io/assembly_basics/","language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kavicastelo.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-25T18:18:36.000Z","updated_at":"2024-08-06T20:19:48.000Z","dependencies_parsed_at":"2024-07-30T01:08:26.973Z","dependency_job_id":"07a65bd6-a191-4f8e-8bfe-babc010c8a8b","html_url":"https://github.com/kavicastelo/assembly_basics","commit_stats":null,"previous_names":["kavicastelo/assembly_basics"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kavicastelo%2Fassembly_basics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kavicastelo%2Fassembly_basics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kavicastelo%2Fassembly_basics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kavicastelo%2Fassembly_basics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kavicastelo","download_url":"https://codeload.github.com/kavicastelo/assembly_basics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243685584,"owners_count":20330982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asmx86","assembly","basics","gcc-complier","low-level","mingw-w64","nasm"],"created_at":"2024-09-24T22:52:29.171Z","updated_at":"2025-03-15T05:14:37.305Z","avatar_url":"https://github.com/kavicastelo.png","language":"Assembly","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Assembly Language Guide for Windows 64-bit\n\n## Introduction\n\nThis guide is designed to help you learn assembly language from the ground up, focusing on the 64-bit Windows\narchitecture. We'll cover everything from setting up your environment to understanding registers and writing basic\nprograms. High-level programming language comparisons are included to make concepts more understandable.\n\n## Table of Contents\n1. [Setting Up the Environment](#setting-up-the-environment)\n2. [Basic Syntax and Structure](#basic-syntax-and-structure)\n3. [Registers](#registers)\n4. [Simple Input and Output](#simple-input-and-output)\n5. [Arithmetic Operations](#arithmetic-operations)\n6. [Control Flow](#control-flow)\n7. [Functions and Calling Conventions](#functions-and-calling-conventions)\n8. [Learning Strategies](#learning-strategies)\n\n## Setting Up the Environment\n1. **Install NASM:** Download and install NASM from the [official site](https://www.nasm.us).\n2. **Install MinGW or GCC:** Download and install MinGW or GCC for Windows.\n3. **Set up IntelliJ IDEA:** Use IntelliJ IDEA with the necessary plugins to support assembly language.\n\n## Basic Syntax and Structure\nAn assembly program is divided into sections:\n- **.data:** Contains initialized data\n- **.text:** Contains executable code\n- **.bss:** Contains uninitialized data\n\n### Example\n\n```asm\nsection .data\n    hello db 'Hello, world!', 0\n\nsection .text\n    global _start\n\n_start:\n    ; Your code here\n```\n\n## Registers\nRegisters are limited storage locations in the CPU, each with specific purposes.\n\n### General-Purpose Registers\n- **RAX, RBX, RCX, RDX:** Arithmetic operations, loop counters, function returns.\n- **RSP, RBP, RSI, RDI:** Stack pointer, base pointer, source index, destination index.\n- **R8, R9, R10, R11, R12, R13, R14, R15:** Reserved for future use.\n- **RIP:** Points to the next instruction to execute.\n- **RFLAGS:** CPU flags.\n\n### Segment Registers\n- **CS, SS, DS, ES, FS, GS:** Segment selectors.\n\n### Example\nC Code:\n```c\nint main() {\n    int a = 5;\n    int b = 10;\n    int sum = a + b;\n    return sum;\n}\n```\n\nAssembly Code:\n```asm\nsection .text\nglobal _start\n\n_start:\n    mov rax, 5       ; a = 5\n    mov rbx, 10      ; b = 10\n    add rax, rbx     ; sum = a + b\n    mov rdi, rax     ; return sum\n    call ExitProcess\n```\n\n## Simple Input and Output\n### Printing a String\nC Code:\n```c\n#include \u003cstdio.h\u003e\nint main() {\n    printf(\"Hello, World!\");\n    return 0;\n}\n```\n\nAssembly Code:\n```asm\nsection .data\n    hello db 'Hello, World!', 0\n\nsection .text\nglobal _start\nextern GetStdHandle\nextern WriteConsoleA\nextern ExitProcess\n\n_start:\n    mov rcx, -11           ; STD_OUTPUT_HANDLE\n    call GetStdHandle\n\n    mov rcx, rax           ; handle to stdout\n    mov rdx, hello         ; pointer to string\n    mov r8, 13             ; string length\n    lea r9, [rsp+8]        ; dummy variable\n    call WriteConsoleA\n\n    xor rcx, rcx           ; exit code 0\n    call ExitProcess\n```\n\n## Arithmetic Operations\n### Addition Example\nC Code:\n```c\nint add(int a, int b) {\n    return a + b;\n}\n```\n\nAssembly Code:\n```asm\nsection .text\nglobal _start\n\n_start:\n    mov rax, 5       ; a = 5\n    mov rbx, 10      ; b = 10\n    add rax, rbx     ; result = a + b\n    call ExitProcess\n```\n\n## Control Flow\n### Loop Example\nC Code:\n```c\nint sum_n(int n) {\n    int sum = 0;\n    for (int i = 1; i \u003c= n; i++) {\n        sum += i;\n    }\n    return sum;\n}\n```\n\nAssembly Code:\n```asm\nsection .text\nglobal _start\n\n_start:\n    mov rcx, 10      ; n = 10\n    mov rax, 0       ; sum = 0\n    mov rbx, 1       ; i = 1\n\nloop_start:\n    add rax, rbx     ; sum += i\n    inc rbx          ; i++\n    cmp rbx, rcx\n    jle loop_start   ; if i \u003c= n, repeat\n\n    call ExitProcess\n```\n\n## Functions and Calling Conventions\n### Function Example\nC Code:\n```c\nint multiply(int a, int b) {\n    return a * b;\n}\nint main() {\n    int result = multiply(5, 10);\n    return result;\n}\n```\n\nAssembly Code:\n```asm\nsection .text\nglobal _start\nextern multiply\n\n_start:\n    mov rcx, 5       ; a = 5\n    mov rdx, 10      ; b = 10\n    call multiply\n    ; result is in rax\n    call ExitProcess\n\nmultiply:\n    imul rax, rcx, rdx\n    ret\n```\n\n## Learning Strategies\n- **Start Small:** Begin with simple programs and gradually increase complexity.\n- **Use Debuggers:** Tools like `gdb` can help you step through your code and understand what's happening.\n- **Read Documentation:** Manuals and tutorials specific to x86-64 assembly can be very helpful.\n- **Practice Regularly:** Writing and experimenting with code is the best way to learn.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkavicastelo%2Fassembly_basics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkavicastelo%2Fassembly_basics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkavicastelo%2Fassembly_basics/lists"}