Per
This work is licensed under a "by-nc-sa" Creative Commons License.
#include <stdio.h> // Just a comment!
... void main (int argc, char* argv[]) { // Variables // "Code"
... } // EOF
global _start ; Just a comment!
section .data
; Variables
...
section .text
_start:
; "Code"
...
; EOF
#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!"
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!"
; # Command registers
; 1. 2. 3. 4. ...
; rax, rdi, rsi, rdx, ...
; syscall
; # General purpose registers
; r12, r13, r14 or r15
; # Stack counter
; rsp
By Per
A "C-ish" introduction.