Updated lib label scopes and continued to lesson 18

This commit is contained in:
Lauri Koskenniemi 2025-06-24 00:26:00 +03:00
parent 8d471b77f7
commit 1c0fcde351
10 changed files with 182 additions and 9 deletions

BIN
lesson16/l16 Executable file

Binary file not shown.

26
lesson16/l16.asm Normal file
View File

@ -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

BIN
lesson16/l16.o Normal file

Binary file not shown.

BIN
lesson17/l17 Executable file

Binary file not shown.

44
lesson17/l17.asm Normal file
View File

@ -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

BIN
lesson17/l17.o Normal file

Binary file not shown.

BIN
lesson18/l18 Executable file

Binary file not shown.

60
lesson18/l18.asm Normal file
View File

@ -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

BIN
lesson18/l18.o Normal file

Binary file not shown.

View File

@ -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