13.2.2 / - 2


. 32- 10 + + , .. 12 . 12 , .

. -32- . -

:

Ideal

p586

model flat

extrn ExitProcess:proc

include "win.inc"

dataseg

my db ' 25', 0

val dd ?

codeseg

proc atoi

public atoi

arg value:dword, mystr:dword = p

push ebp

mov ebp, esp

push ebx ecx edx esi

mov esi, [mystr]

skip esi

mov ebx, 1

cmp [byte ptr esi], '-'

je short minus

cmp [byte ptr esi], '+'

je short plus

jmp prod

minus:

inc esi

neg ebx

jmp prod

plus:

inc esi

prod:

skip esi

xor eax, eax; r=0

mov ecx, 10

for:

cmp [byte ptr esi], 0

je exit

mul ecx

test edx, edx

jne error

mov dl, [esi]

sub dl, '0'

add eax, edx

inc esi

jmp for

exit:

mul ebx

mov esi, [value]

mov [esi], eax

xor eax, eax

jmp lend

error:

mov eax, 1

lend:

pop esi edx ecx ebx

pop ebp

ret p

endp atoi

begin:

push offset my offset val

call atoi

call ExitProcess

end begin

. .