commit 9165f49e62d8c5e740ffb9e7a79863af1a2ab578 Author: Lauri Koskenniemi Date: Sat May 24 11:05:24 2025 +0300 Create learn asm repo Repository for learning assembly language diff --git a/info b/info new file mode 100644 index 0000000..900bb73 --- /dev/null +++ b/info @@ -0,0 +1,4 @@ + +https://asmtutor.com/ + +https://www.chromium.org/chromium-os/developer-library/reference/linux-constants/syscalls/#x86-32-bit diff --git a/lesson1/l1 b/lesson1/l1 new file mode 100755 index 0000000..6e7e04c Binary files /dev/null and b/lesson1/l1 differ diff --git a/lesson1/l1.asm b/lesson1/l1.asm new file mode 100644 index 0000000..765f5ee --- /dev/null +++ b/lesson1/l1.asm @@ -0,0 +1,16 @@ +; Lesson 1 +; nasm -f elf l1.asm +; ld -m elf_i386 l1.o -o l1 + +SECTION .data +msg db 'Hello, World!', 0Ah + +SECTION .text +global _start + +_start: +mov edx, 13 +mov ecx, msg +mov ebx, 1 +mov eax, 4 +int 80h diff --git a/lesson1/l1.o b/lesson1/l1.o new file mode 100644 index 0000000..f4e806c Binary files /dev/null and b/lesson1/l1.o differ diff --git a/lesson2/l2 b/lesson2/l2 new file mode 100755 index 0000000..0da28fa Binary files /dev/null and b/lesson2/l2 differ diff --git a/lesson2/l2.asm b/lesson2/l2.asm new file mode 100644 index 0000000..ee1b394 --- /dev/null +++ b/lesson2/l2.asm @@ -0,0 +1,17 @@ + +SECTION .data +msg db 'cat!', 0Ah + +SECTION .text +global _start + +_start: +mov edx, 5 +mov ecx, msg +mov ebx, 1 +mov eax, 4 +int 80h + +mov ebx, 0 +mov eax, 1 +int 80h diff --git a/lesson2/l2.o b/lesson2/l2.o new file mode 100644 index 0000000..3363aea Binary files /dev/null and b/lesson2/l2.o differ diff --git a/lesson3/l3 b/lesson3/l3 new file mode 100755 index 0000000..51795df Binary files /dev/null and b/lesson3/l3 differ diff --git a/lesson3/l3.asm b/lesson3/l3.asm new file mode 100644 index 0000000..982fb18 --- /dev/null +++ b/lesson3/l3.asm @@ -0,0 +1,28 @@ + +SECTION .data +msg db 'Le Chat!', 0Ah + +SECTION .text +global _start + +_start: +mov ebx, msg +mov eax, ebx + +nextchar: +cmp byte [eax], 0 +jz finished +inc eax +jmp nextchar + +finished: +sub eax, ebx +mov edx, eax +mov ecx, msg +mov ebx, 1 +mov eax, 4 +int 80h + +mov ebx, 0 +mov eax, 1 +int 80h diff --git a/lesson3/l3.o b/lesson3/l3.o new file mode 100644 index 0000000..ebfd09e Binary files /dev/null and b/lesson3/l3.o differ diff --git a/lesson3/l3i b/lesson3/l3i new file mode 100755 index 0000000..d715856 Binary files /dev/null and b/lesson3/l3i differ diff --git a/lesson3/l3i.asm b/lesson3/l3i.asm new file mode 100644 index 0000000..1359b64 --- /dev/null +++ b/lesson3/l3i.asm @@ -0,0 +1,26 @@ + +SECTION .data +msg db 'Le Chat!', 0Ah + +SECTION .text +global _start + +_start: +mov ecx, msg +mov edx, ecx + +nextchar: +cmp byte [edx], 0 +jz finished +inc edx +jmp nextchar + +finished: +sub edx, ecx +mov ebx, 1 +mov eax, 4 +int 80h + +mov ebx, 0 +mov eax, 1 +int 80h diff --git a/lesson3/l3i.o b/lesson3/l3i.o new file mode 100644 index 0000000..515b0b1 Binary files /dev/null and b/lesson3/l3i.o differ diff --git a/lesson4/l4 b/lesson4/l4 new file mode 100755 index 0000000..db489fc Binary files /dev/null and b/lesson4/l4 differ diff --git a/lesson4/l4.asm b/lesson4/l4.asm new file mode 100644 index 0000000..7afedfd --- /dev/null +++ b/lesson4/l4.asm @@ -0,0 +1,34 @@ + +SECTION .data +msg db 'A cat!', 0Ah + +SECTION .text +global _start + +_start: +mov edx, msg +call strlen + +mov ecx, msg +mov ebx, 1 +mov eax, 4 +int 80h + +mov ebx, 0 +mov eax, 1 +int 80h + +strlen: +push ebx +mov ebx, edx + +nextchar: +cmp byte [edx], 0 +jz finished +inc edx +jmp nextchar + +finished: +sub edx, ebx +pop ebx +ret diff --git a/lesson4/l4.o b/lesson4/l4.o new file mode 100644 index 0000000..69b865b Binary files /dev/null and b/lesson4/l4.o differ diff --git a/lesson5/l5 b/lesson5/l5 new file mode 100755 index 0000000..7e2f371 Binary files /dev/null and b/lesson5/l5 differ diff --git a/lesson5/l5.asm b/lesson5/l5.asm new file mode 100644 index 0000000..8a419b1 --- /dev/null +++ b/lesson5/l5.asm @@ -0,0 +1,18 @@ + +%include '../lib/fl.asm' + +SECTION .data +msg1 db 'Cats and', 0Ah +msg2 db 'Dogs', 0Ah + +SECTION .text +global _start + +_start: +mov eax, msg1 +call sprint + +mov eax, msg2 +call sprint + +call quit diff --git a/lesson5/l5.o b/lesson5/l5.o new file mode 100644 index 0000000..c2f8c63 Binary files /dev/null and b/lesson5/l5.o differ diff --git a/lib/fl.asm b/lib/fl.asm new file mode 100644 index 0000000..03bcf45 --- /dev/null +++ b/lib/fl.asm @@ -0,0 +1,45 @@ + +slen: +push ebx +mov ebx, eax + +nextchar: +cmp byte [eax], 0 +jz finished +inc eax +jmp nextchar + +finished: +sub eax, ebx +pop ebx +ret + + + +sprint: +push edx +push ecx +push ebx +push eax +call slen + +mov edx, eax +pop eax + +mov ecx, eax +mov ebx, 1 +mov eax, 4 +int 80h + +pop ebx +pop ecx +pop edx +ret + + + +quit: +mov ebx, 0 +mov eax, 1 +int 80h +ret