-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.asm
77 lines (77 loc) · 3.25 KB
/
lib.asm
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
section _text
StrToInt:
push edi
mov bh, '9'
mov bl, '0'
push esi ; ��������� ����� �������� ������
cmp byte[esi], '-'
jne .prod
inc esi ; ���������� ����
.prod cld
xor di, di ; �������� ������� �����
.cycle: lodsb ; ��������� ������ (�����)
cmp al, 10 ; ���� 10, �� �� �����
je .Return
cmp al, bl ; ���������� � ����� ����
jb .Error ; "����" � ������
cmp al, bh ; ���������� � ����� ������
ja .Error ; "����" � ������
sub al, 30h ; �������� ����� �� �������
cbw ; ��������� �� �����
push ax ; ��������� � �����
mov ax, 10 ; ������� 10 � AX
mul di ; ��������, ��������� � DX:AX
pop di ; � DI � ��������� �����
add ax, di
mov di, ax ; � DI � ����������� �����
jmp .cycle
.Return: pop esi
mov ebx, 0
cmp byte[esi], '-'
jne .J
neg di
.J mov ax, di
cwde
jmp .R
.Error: pop esi
mov eax, 0
mov ebx, 1
.R pop edi
ret
IntToStr:
push edi
push ebx
push edx
push ecx
push esi
mov byte[esi],0 ; �� ����� �����
cmp eax,0
jge .l1
neg eax
mov byte[esi],'-'
.l1 mov byte[esi+6],10
mov edi,5
mov bx,10
.again: cwd ; ��������� ����� �� ��������
div bx ; ����� ��������� �� 10
add dl,30h ; �������� �� ������� ��� �����
mov [esi+edi],dl ; ����� ������ � ������
dec edi ; ��������� ��������� ��
; ���������� �������
cmp ax, 0 ; ������������� ��� �����?
jne .again
mov ecx, 6
sub ecx, edi ; ����� ����������+����
mov eax,ecx
inc eax ; ����� ����������+0�
inc esi ; ���������� ����
push esi
lea esi,[esi+edi] ; ������ ����������
pop edi
rep movsb
pop esi
pop ecx
pop edx
pop ebx
pop edi
ret