From 21f616b5593d87d6381c1f3d67a3df0c442dba44 Mon Sep 17 00:00:00 2001 From: scratko Date: Wed, 27 Mar 2024 22:38:51 +0300 Subject: Initial commit --- string_conversion.asm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 string_conversion.asm (limited to 'string_conversion.asm') 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 -- cgit v1.2.3