back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/string_conversion.asm
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-03-27 22:38:51 +0300
committerscratko <m@scratko.xyz>2024-03-27 22:38:51 +0300
commit21f616b5593d87d6381c1f3d67a3df0c442dba44 (patch)
tree28eba727b41d4d6b6b273ba3f7e81a4793d56e84 /string_conversion.asm
downloadtrigonometric-table-21f616b5593d87d6381c1f3d67a3df0c442dba44.tar.gz
trigonometric-table-21f616b5593d87d6381c1f3d67a3df0c442dba44.tar.bz2
trigonometric-table-21f616b5593d87d6381c1f3d67a3df0c442dba44.zip
Initial commit
Diffstat (limited to 'string_conversion.asm')
-rw-r--r--string_conversion.asm40
1 files changed, 40 insertions, 0 deletions
diff --git a/string_conversion.asm b/string_conversion.asm
new file mode 100644
index 0000000..1cef531
--- /dev/null
+++ b/string_conversion.asm
@@ -0,0 +1,40 @@
+global to_int
+
+section .text
+
+;
+; angle translation from string to integer
+; [ebp+8] is pointer to string
+; eax=-1 if digit is not 0-9
+; else eax=number
+;
+to_int: push ebp
+ mov ebp, esp
+ sub esp, 8 ; local variables
+ push esi ; save esi
+ mov dword [ebp-4], 0 ; init number
+ mov dword [ebp-8], 10 ; init const
+ mov esi, [ebp+8] ; buffer
+ cld
+.lp: lodsb
+ cmp al, 0
+ je .store
+ cmp al, '0'
+ jl .error
+ cmp al, '9'
+ jg .error
+ sub al, '0'
+ xor ecx, ecx
+ xchg al, cl
+ mov eax, [ebp-4]
+ mul dword [ebp-8]
+ add eax, ecx
+ mov [ebp-4], eax
+ jmp .lp
+.error: mov eax, -1
+ jmp .quit
+.store: mov eax, [ebp-4]
+.quit: pop esi
+ mov esp, ebp
+ pop ebp
+ ret