diff --git a/lesson16/l16 b/lesson16/l16 new file mode 100755 index 0000000..22225d6 Binary files /dev/null and b/lesson16/l16 differ diff --git a/lesson16/l16.asm b/lesson16/l16.asm new file mode 100644 index 0000000..a0e81ee --- /dev/null +++ b/lesson16/l16.asm @@ -0,0 +1,26 @@ + +; %include '../lib/fl.asm' ; local +%include 'lib/fl.asm' ; build.sh + +SECTION .text +global _start + +_start: +pop ecx +pop edx +sub ecx, 1 +mov edx, 0 + +nextArg: +cmp ecx, 0h +jz noMoreArgs +pop eax +call atoi +add edx, eax +dec ecx +jmp nextArg + +noMoreArgs: +mov eax, edx +call iprintLF +call quit diff --git a/lesson16/l16.o b/lesson16/l16.o new file mode 100644 index 0000000..37dcbd1 Binary files /dev/null and b/lesson16/l16.o differ diff --git a/lesson17/l17 b/lesson17/l17 new file mode 100755 index 0000000..dd18660 Binary files /dev/null and b/lesson17/l17 differ diff --git a/lesson17/l17.asm b/lesson17/l17.asm new file mode 100644 index 0000000..8ed90e7 --- /dev/null +++ b/lesson17/l17.asm @@ -0,0 +1,44 @@ + +; %include '../lib/fl.asm' ; local +%include 'lib/fl.asm' ; build.sh + +SECTION .data +msg1 db 'Jumping to finished label.', 0h +msg2 db 'Inside subroutine number: ', 0h +msg3 db 'Inside subroutine "finished".', 0h + +SECTION .text +global _start + +_start: +subroutineOne: +mov eax, msg1 +call sprintLF +jmp .finished + +.finished: +mov eax, msg2 +call sprint +mov eax, 1 +call iprintLF + +subroutineTwo: +mov eax, msg1 +call sprintLF +jmp .finished + +.finished: +mov eax, msg2 +call sprint +mov eax, 2 +call iprintLF + +mov eax, msg1 +call sprintLF +jmp finished + +finished: +mov eax, msg3 +call sprintLF +call quit + diff --git a/lesson17/l17.o b/lesson17/l17.o new file mode 100644 index 0000000..43b7582 Binary files /dev/null and b/lesson17/l17.o differ diff --git a/lesson18/l18 b/lesson18/l18 new file mode 100755 index 0000000..9844b0a Binary files /dev/null and b/lesson18/l18 differ diff --git a/lesson18/l18.asm b/lesson18/l18.asm new file mode 100644 index 0000000..cd189f7 --- /dev/null +++ b/lesson18/l18.asm @@ -0,0 +1,60 @@ + +; %include '../lib/fl.asm' ; local +%include 'lib/fl.asm' ; build.sh + +SECTION .data +fizz db 'Fizz', 0h +buzz db 'Buzz', 0h + +SECTION .text +global _start + +_start: +mov esi, 0 +mov edi, 0 +mov ecx, 0 + +nextNumber: +inc ecx + +.checkFizz: +mov edx, 0 +mov eax, ecx +mov ebx, 3 +div ebx +mov edi, edx +cmp edi, 0 +jne .checkBuzz +mov eax, fizz +call sprint + +.checkBuzz: +mov edx, 0 +mov eax, ecx +mov ebx, 5 +div ebx +mov esi, edx +cmp esi, 0 +jne .checkInt +mov eax, buzz +call sprint + +.checkInt: +cmp edi, 0 +je .continue +cmp esi, 0 +je .continue +mov eax, ecx +call iprint + +.continue: +mov eax, 0Ah +push eax +mov eax, esp +call sprint +pop eax +cmp ecx, 100 +jne nextNumber + +call quit + diff --git a/lesson18/l18.o b/lesson18/l18.o new file mode 100644 index 0000000..7c23e2e Binary files /dev/null and b/lesson18/l18.o differ diff --git a/lib/fl.asm b/lib/fl.asm index a25a640..9d606f1 100644 --- a/lib/fl.asm +++ b/lib/fl.asm @@ -1,3 +1,46 @@ + +;------------------------------------------ +; int atoi(Integer number) +; Ascii to integer function (atoi) +atoi: +push ebx +push ecx +push edx +push esi +mov esi, eax +mov eax, 0 +mov ecx, 0 + +.multiplyLoop: +xor ebx, ebx +mov bl, [esi+ecx] +cmp bl, 48 +jl .finished +cmp bl, 57 +jg .finished + +sub bl, 48 +add eax, ebx +mov ebx, 10 +mul ebx +inc ecx +jmp .multiplyLoop + +.finished: +cmp ecx, 0 +je .restore +mov ebx, 10 +div ebx + +.restore: +pop esi +pop edx +pop ecx +pop ebx +ret + + + ;------------------------------------------ ; void iprint(Integer number) ; Integer printing function (itoa) @@ -8,7 +51,7 @@ push edx push esi mov ecx, 0 -divideLoop: +.divideLoop: inc ecx mov edx, 0 mov esi, 10 @@ -16,15 +59,15 @@ idiv esi add edx, 48 push edx cmp eax, 0 -jnz divideLoop +jnz .divideLoop -printLoop: +.printLoop: dec ecx mov eax, esp call sprint pop eax cmp ecx, 0 -jnz printLoop +jnz .printLoop pop esi pop edx @@ -58,13 +101,13 @@ slen: push ebx mov ebx, eax -nextchar: +.nextchar: cmp byte [eax], 0 -jz finished +jz .finished inc eax -jmp nextchar +jmp .nextchar -finished: +.finished: sub eax, ebx pop ebx ret @@ -109,7 +152,7 @@ push eax mov eax, esp call sprint pop eax -pop eax +pop eax ret