1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
|