ASSEMBLER

A "C-ish" introduction.

The Outline

C

#include <stdio.h> // Just a comment!

void main (int argc, char* argv[])
{
    // Variables
    ...

    // "Code"
    ...
}
// EOF

The Outline

Assembler

global _start ; Just a comment!

section .data
    ; Variables
    ...

section .text
    _start:
        ; "Code"
        ...
; EOF

Hello World

C

#include <stdio.h> // Just a random comment!
void main (int argc, char* argv[])
{
    // Variables
    int i = 1;
    char hello[] = "Hello World!";

    // "Code"
    do {
        printf("%s", hello);
        i++;
    } while (i < 5);
}
// EOF
5x "C says Hello World!"

Hello World

Assembler

 global _start ; Just a random comment!

section .data
    ; Variables
    str_ptr: db 'Hello World!', 10  ; char hello[] = "Hello World!";

section .text
    _start:
        ; "Code"
        mov r12, 1        ;    int i = 1;

        say_hello:        ;    do {
        mov rax, 1        ; \
        mov rdi, 1        ;  |
        mov rsi, str_ptr  ;  > printf("%s", hello);
        mov rdx, 13       ;  |
        syscall           ; /

        inc r12           ;    i++;
        cmp r12, 5        ; \
        jl say_hello      ;  > } while (i < 5);
; EOF

5x "Assembler says Hello World!"

Registers

(on 64-bit systems)

; # Command registers
;  1.   2.   3.   4.  ...
; rax, rdi, rsi, rdx, ...
; syscall

; # General purpose registers
; r12, r13, r14 or r15

; # Stack counter
; rsp

ASSEMBLER

By Per

ASSEMBLER

A "C-ish" introduction.

  • 1,642
Loading comments...

More from Per