Updated lib label scopes and continued to lesson 18
This commit is contained in:
+52
-9
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user