back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
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
downloadtrigonometric-table-21f616b5593d87d6381c1f3d67a3df0c442dba44.tar.gz
trigonometric-table-21f616b5593d87d6381c1f3d67a3df0c442dba44.tar.bz2
trigonometric-table-21f616b5593d87d6381c1f3d67a3df0c442dba44.zip
Initial commit
-rw-r--r--Makefile13
-rw-r--r--compute_functions.asm44
-rw-r--r--macro.inc72
-rw-r--r--number_conversion.asm132
-rw-r--r--result.txt149
-rw-r--r--string_conversion.asm40
-rw-r--r--trigonometric_table.asm249
-rw-r--r--validations.asm74
8 files changed, 773 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ddcbcba
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+ASM = nasm
+ASMFLAGS = -f elf
+
+BUILDFLAGS = -m elf_i386
+
+%.o: %.asm
+ $(ASM) $(ASMFLAGS) $<
+
+OBJMODULES = string_conversion.o validations.o compute_functions.o number_conversion.o \
+ trigonometric_table.o
+
+trigonometric_table: $(OBJMODULES)
+ $(LD) $(BUILDFLAGS) $^ -o $@
diff --git a/compute_functions.asm b/compute_functions.asm
new file mode 100644
index 0000000..339742a
--- /dev/null
+++ b/compute_functions.asm
@@ -0,0 +1,44 @@
+global compute
+
+section .text
+
+;
+; calculating functions (sine, cosine, tangent, catangent)
+; [ebp+8] is integer angle
+; [ebp+12] is pointer to sine buffer
+; [ebp+16] is pointer to cosine buffer
+; [ebp+20] is pointer to tangent buffer
+; [ebp+24] is pointer to catangent buffer
+;
+compute: push ebp
+ mov ebp, esp
+ sub esp, 4
+ mov dword [ebp-4], 180
+ finit
+ fild dword [ebp+8]
+ fldpi
+ fmulp
+ fild dword [ebp-4]
+ fdivp
+ fld st0 ; copy radian angle
+ fsin
+ mov eax, [ebp+12]
+ fstp dword [eax] ; extract sin
+ fld st0
+ fcos
+ mov eax, [ebp+16]
+ fstp dword [eax] ; extract cos
+ mov eax, [ebp+20] ; check tang
+ cmp dword [eax], 0ffffffffh ; undefined value
+ je .skip
+ fptan
+ fxch
+ fst dword [eax] ; extract tang
+.skip: mov eax, [ebp+24]
+ cmp dword [eax], 0ffffffffh
+ je .quit
+ fdivp ; ctng
+ fstp dword [eax] ; extract ctng
+.quit: mov esp, ebp
+ pop ebp
+ ret
diff --git a/macro.inc b/macro.inc
new file mode 100644
index 0000000..4253947
--- /dev/null
+++ b/macro.inc
@@ -0,0 +1,72 @@
+%macro get_arg 0
+ add esi, 4
+ mov edi, [esi]
+%endmacro
+%macro write_value 0
+ mov edx, eax ; count
+ mov eax, 4 ; syscall write
+ mov ebx, [f_discr]
+ mov ecx, buffer
+ int 80h
+%endmacro
+%macro new_line 0
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, nlstr
+ mov edx, 1
+ int 80h
+%endmacro
+%macro vertical 0
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, vert_sep
+ mov edx, 3
+ int 80h
+%endmacro
+%macro border 0
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, some_spaces
+ mov edx, 2
+ int 80h
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, border_sep
+ mov edx, 53
+ int 80h
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, some_spaces
+ mov edx, 2
+ int 80h
+%endmacro
+%macro horizontal 0
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, beg_sep
+ mov edx, 2
+ int 80h
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, hor_sep
+ mov edx, hor_length
+ int 80h
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, end_sep
+ mov edx, 2
+ int 80h
+%endmacro
+%macro placeholder 0
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, some_spaces
+ int 80h
+%endmacro
+%macro undefined 0
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, undef_value
+ mov edx, 1
+ int 80h
+%endmacro
diff --git a/number_conversion.asm b/number_conversion.asm
new file mode 100644
index 0000000..af6452f
--- /dev/null
+++ b/number_conversion.asm
@@ -0,0 +1,132 @@
+global result_to_string
+global input_to_string
+
+;
+;local variables of result_to_string
+;
+%define ten ebp-4
+%define count ebp-8
+%define digit ebp-12
+
+section .text
+
+;
+; converts float number to string
+; [ebp+8] is value of sine/cosine/tangent/cotangent
+; [ebp+12] is pointer to buffer
+; returns eax is string size
+;
+result_to_string:
+ push ebp
+ mov ebp, esp
+ sub esp, 12 ; memory allocation
+ mov dword [ten], 10
+ mov dword [count], 0
+ mov edi, [ebp+12] ; string address
+ cld
+ finit
+ fld dword [ebp+8] ; load number
+ ftst ; compare with 0.0
+ fstsw ax ; save flags
+ sahf ; load flags
+ jnc .positiv
+ mov al, '-'
+ stosb
+ inc dword [count]
+ fchs ; modulus
+.positiv: fld1 ; load 1
+ fld st1 ; copy number to top
+ fprem ; fraction part
+ fsub st2, st0 ; integer
+ fxch st2
+ xor ecx, ecx ; count for integer part
+.lp1: fidiv dword [ten] ; number /10
+ fxch st1 ; st0 = 1, st1 = number
+ fld st1 ; st0 = number, st1 = 1, st2 = number
+ fprem
+ fsub st2, st0 ; number - fract
+ fimul dword [ten] ; 0,fraction * 10
+ fistp dword [digit]
+ push dword [digit] ; save integer part
+ inc ecx ; increment integer count
+ inc dword [count] ; incement total count
+ fxch st1 ; st0 = number, st1 = 1
+ ftst ; integer part = 0.0
+ fstsw ax
+ sahf
+ jne .lp1
+.extract: pop eax
+ add al, '0'
+ stosb
+ loop .extract
+ fstp st0 ; remove integer part
+ fxch st1 ; st0 = fraction part, st1 = 1
+ ftst ; compare with 0.0
+ fstsw ax
+ sahf
+ je .quit
+ mov al, '.'
+ stosb
+ inc dword [count]
+ mov ecx, 5 ; length fract part
+.lp2: fimul dword [ten]
+ fxch st1 ; st0 = 1, st1 = number
+ fld st1 ; st0 = number, st1 = 1, st2 = number
+ fprem
+ fsub st2, st0 ; st2 = integer part
+ fxch st2 ; st0 = int part, st1 = 1, st2 = frac
+ fistp dword [digit] ; st0 = 1, st1 = frac
+ mov al, [digit]
+ add al, '0'
+ stosb
+ inc dword [count]
+ fxch st1 ; st0 = number, st1 = 1
+ ftst
+ fstsw ax
+ sahf
+ je .quit ; number = 0.0
+ loop .lp2 ; else reduce ecx
+.quit: ffree st0 ; clear stack
+ fincstp
+ ffree st0
+ fincstp
+ mov eax, [count] ; return count
+ mov esp, ebp
+ pop ebp
+ ret
+
+
+;
+; angle translation from integer to string
+; [ebp+8] is number
+; [ebp+12] is pointer to buffer
+; return eax is pointer to the beggining of string
+; and ecx is character count
+;
+input_to_string:
+ push ebp
+ mov ebp, esp
+ sub esp, 4
+ push edi
+ mov dword [ebp-4], 10
+ xor ecx, ecx ; count
+ mov edi, [ebp+12] ; buffer
+ add edi, 7 ; by the end of buffer
+ std ; from right to left
+ mov eax, [ebp+8] ; number
+.lp: xor edx, edx
+ div dword [ebp-4]
+ xchg al, dl
+ add al, '0'
+ stosb
+ inc ecx
+ xchg al, dl
+ cmp eax, 0
+ jne .lp
+ mov eax, edi ; address of string
+ inc eax
+ pop edi
+ mov esp, ebp
+ pop ebp
+ ret
+
diff --git a/result.txt b/result.txt
new file mode 100644
index 0000000..cfbf364
--- /dev/null
+++ b/result.txt
@@ -0,0 +1,149 @@
+ -----------------------------------------------------
+ | deg | sin | cos | tan | ctg |
+ |-----------------------------------------------------|
+ | 0 | 0 | 1 | 0 | - |
+ |-----------------------------------------------------|
+ | 5 | 0.08715 | 0.99619 | 0.08748 | 11.43005 |
+ |-----------------------------------------------------|
+ | 10 | 0.17364 | 0.98480 | 0.17632 | 5.67128 |
+ |-----------------------------------------------------|
+ | 15 | 0.25881 | 0.96592 | 0.26794 | 3.73205 |
+ |-----------------------------------------------------|
+ | 20 | 0.34202 | 0.93969 | 0.36397 | 2.74747 |
+ |-----------------------------------------------------|
+ | 25 | 0.42261 | 0.90630 | 0.46630 | 2.14450 |
+ |-----------------------------------------------------|
+ | 30 | 0.5 | 0.86602 | 0.57735 | 1.73205 |
+ |-----------------------------------------------------|
+ | 35 | 0.57357 | 0.81915 | 0.70020 | 1.42814 |
+ |-----------------------------------------------------|
+ | 40 | 0.64278 | 0.76604 | 0.83909 | 1.19175 |
+ |-----------------------------------------------------|
+ | 45 | 0.70710 | 0.70710 | 1 | 1 |
+ |-----------------------------------------------------|
+ | 50 | 0.76604 | 0.64278 | 1.19175 | 0.83909 |
+ |-----------------------------------------------------|
+ | 55 | 0.81915 | 0.57357 | 1.42814 | 0.70020 |
+ |-----------------------------------------------------|
+ | 60 | 0.86602 | 0.5 | 1.73205 | 0.57735 |
+ |-----------------------------------------------------|
+ | 65 | 0.90630 | 0.42261 | 2.14450 | 0.46630 |
+ |-----------------------------------------------------|
+ | 70 | 0.93969 | 0.34202 | 2.74747 | 0.36397 |
+ |-----------------------------------------------------|
+ | 75 | 0.96592 | 0.25881 | 3.73205 | 0.26794 |
+ |-----------------------------------------------------|
+ | 80 | 0.98480 | 0.17364 | 5.67128 | 0.17632 |
+ |-----------------------------------------------------|
+ | 85 | 0.99619 | 0.08715 | 11.43005 | 0.08748 |
+ |-----------------------------------------------------|
+ | 90 | 1 | -0.00000 | - | -0 |
+ |-----------------------------------------------------|
+ | 95 | 0.99619 | -0.08715 | -11.43005 | -0.08748 |
+ |-----------------------------------------------------|
+ | 100 | 0.98480 | -0.17364 | -5.67128 | -0.17632 |
+ |-----------------------------------------------------|
+ | 105 | 0.96592 | -0.25881 | -3.73205 | -0.26794 |
+ |-----------------------------------------------------|
+ | 110 | 0.93969 | -0.34202 | -2.74747 | -0.36397 |
+ |-----------------------------------------------------|
+ | 115 | 0.90630 | -0.42261 | -2.14450 | -0.46630 |
+ |-----------------------------------------------------|
+ | 120 | 0.86602 | -0.5 | -1.73205 | -0.57735 |
+ |-----------------------------------------------------|
+ | 125 | 0.81915 | -0.57357 | -1.42814 | -0.70020 |
+ |-----------------------------------------------------|
+ | 130 | 0.76604 | -0.64278 | -1.19175 | -0.83909 |
+ |-----------------------------------------------------|
+ | 135 | 0.70710 | -0.70710 | -1 | -1 |
+ |-----------------------------------------------------|
+ | 140 | 0.64278 | -0.76604 | -0.83909 | -1.19175 |
+ |-----------------------------------------------------|
+ | 145 | 0.57357 | -0.81915 | -0.70020 | -1.42814 |
+ |-----------------------------------------------------|
+ | 150 | 0.5 | -0.86602 | -0.57735 | -1.73205 |
+ |-----------------------------------------------------|
+ | 155 | 0.42261 | -0.90630 | -0.46630 | -2.14450 |
+ |-----------------------------------------------------|
+ | 160 | 0.34202 | -0.93969 | -0.36397 | -2.74747 |
+ |-----------------------------------------------------|
+ | 165 | 0.25881 | -0.96592 | -0.26794 | -3.73205 |
+ |-----------------------------------------------------|
+ | 170 | 0.17364 | -0.98480 | -0.17632 | -5.67128 |
+ |-----------------------------------------------------|
+ | 175 | 0.08715 | -0.99619 | -0.08748 | -11.43005 |
+ |-----------------------------------------------------|
+ | 180 | -0.00000 | -1 | 0.00000 | - |
+ |-----------------------------------------------------|
+ | 185 | -0.08715 | -0.99619 | 0.08748 | 11.43005 |
+ |-----------------------------------------------------|
+ | 190 | -0.17364 | -0.98480 | 0.17632 | 5.67128 |
+ |-----------------------------------------------------|
+ | 195 | -0.25881 | -0.96592 | 0.26794 | 3.73205 |
+ |-----------------------------------------------------|
+ | 200 | -0.34202 | -0.93969 | 0.36397 | 2.74747 |
+ |-----------------------------------------------------|
+ | 205 | -0.42261 | -0.90630 | 0.46630 | 2.14450 |
+ |-----------------------------------------------------|
+ | 210 | -0.5 | -0.86602 | 0.57735 | 1.73205 |
+ |-----------------------------------------------------|
+ | 215 | -0.57357 | -0.81915 | 0.70020 | 1.42814 |
+ |-----------------------------------------------------|
+ | 220 | -0.64278 | -0.76604 | 0.83909 | 1.19175 |
+ |-----------------------------------------------------|
+ | 225 | -0.70710 | -0.70710 | 1 | 1 |
+ |-----------------------------------------------------|
+ | 230 | -0.76604 | -0.64278 | 1.19175 | 0.83909 |
+ |-----------------------------------------------------|
+ | 235 | -0.81915 | -0.57357 | 1.42814 | 0.70020 |
+ |-----------------------------------------------------|
+ | 240 | -0.86602 | -0.5 | 1.73205 | 0.57735 |
+ |-----------------------------------------------------|
+ | 245 | -0.90630 | -0.42261 | 2.14450 | 0.46630 |
+ |-----------------------------------------------------|
+ | 250 | -0.93969 | -0.34202 | 2.74747 | 0.36397 |
+ |-----------------------------------------------------|
+ | 255 | -0.96592 | -0.25881 | 3.73205 | 0.26794 |
+ |-----------------------------------------------------|
+ | 260 | -0.98480 | -0.17364 | 5.67128 | 0.17632 |
+ |-----------------------------------------------------|
+ | 265 | -0.99619 | -0.08715 | 11.43005 | 0.08748 |
+ |-----------------------------------------------------|
+ | 270 | -1 | 0.00000 | - | -0 |
+ |-----------------------------------------------------|
+ | 275 | -0.99619 | 0.08715 | -11.43005 | -0.08748 |
+ |-----------------------------------------------------|
+ | 280 | -0.98480 | 0.17364 | -5.67128 | -0.17632 |
+ |-----------------------------------------------------|
+ | 285 | -0.96592 | 0.25881 | -3.73205 | -0.26794 |
+ |-----------------------------------------------------|
+ | 290 | -0.93969 | 0.34202 | -2.74747 | -0.36397 |
+ |-----------------------------------------------------|
+ | 295 | -0.90630 | 0.42261 | -2.14450 | -0.46630 |
+ |-----------------------------------------------------|
+ | 300 | -0.86602 | 0.5 | -1.73205 | -0.57735 |
+ |-----------------------------------------------------|
+ | 305 | -0.81915 | 0.57357 | -1.42814 | -0.70020 |
+ |-----------------------------------------------------|
+ | 310 | -0.76604 | 0.64278 | -1.19175 | -0.83909 |
+ |-----------------------------------------------------|
+ | 315 | -0.70710 | 0.70710 | -1 | -1 |
+ |-----------------------------------------------------|
+ | 320 | -0.64278 | 0.76604 | -0.83909 | -1.19175 |
+ |-----------------------------------------------------|
+ | 325 | -0.57357 | 0.81915 | -0.70020 | -1.42814 |
+ |-----------------------------------------------------|
+ | 330 | -0.5 | 0.86602 | -0.57735 | -1.73205 |
+ |-----------------------------------------------------|
+ | 335 | -0.42261 | 0.90630 | -0.46630 | -2.14450 |
+ |-----------------------------------------------------|
+ | 340 | -0.34202 | 0.93969 | -0.36397 | -2.74747 |
+ |-----------------------------------------------------|
+ | 345 | -0.25881 | 0.96592 | -0.26794 | -3.73205 |
+ |-----------------------------------------------------|
+ | 350 | -0.17364 | 0.98480 | -0.17632 | -5.67128 |
+ |-----------------------------------------------------|
+ | 355 | -0.08715 | 0.99619 | -0.08748 | -11.43005 |
+ |-----------------------------------------------------|
+ | 360 | 0.00000 | 1 | 0.00000 | - |
+ -----------------------------------------------------
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
diff --git a/trigonometric_table.asm b/trigonometric_table.asm
new file mode 100644
index 0000000..d596204
--- /dev/null
+++ b/trigonometric_table.asm
@@ -0,0 +1,249 @@
+%include "macro.inc"
+
+global _start
+extern result_to_string
+extern compute
+extern input_to_string
+extern check_angle
+extern check_tangent
+extern check_cotanget
+extern to_int
+
+section .text
+
+;
+; MAIN PROGRAM
+;
+_start: pop ebx ; length of args
+ cmp ebx, 5
+ jne .arg_error
+ mov esi, esp
+ get_arg ; file name
+ mov [f_name], edi
+ get_arg ; start angle
+ push edi
+ call to_int
+ add esp, 4
+ cmp eax, -1
+ je .arg_error
+ mov [beg_angle], eax
+ get_arg ; finish angle
+ push edi
+ call to_int
+ add esp, 4
+ cmp eax, -1
+ je .arg_error
+ mov [end_angle], eax
+ get_arg ; step
+ push edi
+ call to_int
+ add esp, 4
+ cmp eax, -1
+ je .arg_error
+ mov [step], eax
+ push dword [beg_angle]
+ push dword [end_angle]
+ call check_angle
+ add esp, 8
+ cmp eax, 0
+ je .angle_error
+ cmp eax, -1
+ je .greater_error
+ mov eax, 5
+ mov ebx, [f_name]
+ mov ecx, 241h ; open file
+ mov edx, 0666q ; rights
+ int 80h
+ mov ecx, eax
+ and ecx, 0fffff000h
+ cmp ecx, 0fffff000h
+ je .open_error
+ mov [f_discr], eax
+ border
+ new_line
+ mov eax, 4
+ mov ebx, [f_discr]
+ mov ecx, title
+ mov edx, title_len
+ int 80h
+ new_line
+ mov esi, [beg_angle]
+.lp: cmp esi, [end_angle]
+ jg .quit
+ horizontal
+ vertical
+ push buffer
+ push esi
+ call input_to_string ; for print input angle
+ add esp, 8
+ push ecx ; save ecx
+ push eax ; save eax
+ mov eax, 3
+ sub eax, ecx
+ cmp ecx, 0
+ je .skip
+ mov edx, eax ; indent
+ placeholder
+.skip: pop eax
+ pop ecx
+ mov edx, ecx ; count
+ mov ecx, eax ; address of string
+ mov eax, 4 ; write angle
+ mov ebx, [f_discr]
+ int 80h
+ vertical
+ push dword tan_value
+ push esi
+ call check_tangent
+ add esp, 8
+ push dword ctg_value
+ push esi
+ call check_cotanget
+ add esp, 8
+ push dword ctg_value ; pointer to catangent buffer
+ push dword tan_value ; pointer to tangent buffer
+ push dword cos_value ; pointer to cosine buffer
+ push dword sin_value ; pointer to sine buffer
+ push esi ; angle
+ call compute
+ add esp, 20
+ push buffer
+ push dword [sin_value]
+ call result_to_string
+ add esp, 8
+ mov edx, 9
+ sub edx, eax ; indent
+ cmp edx, 0
+ je .print_sin
+ push eax ; save length
+ placeholder
+ pop eax
+.print_sin: write_value
+ vertical
+ push buffer
+ push dword [cos_value]
+ call result_to_string
+ add esp, 8
+ mov edx, 9
+ sub edx, eax ; indent
+ cmp edx, 0
+ je .print_cos
+ push eax
+ placeholder
+ pop eax
+.print_cos: write_value
+ vertical
+ cmp dword [tan_value], 0ffffffffh
+ jne .tan
+ mov edx, 8 ; placeholder length
+ placeholder
+ undefined
+ vertical
+ jmp .cmp_ctg
+.tan: push buffer
+ push dword [tan_value]
+ call result_to_string
+ add esp, 8
+ mov edx, 9
+ sub edx, eax ; indent
+ cmp edx, 0
+ je .print_tan
+ push eax
+ placeholder
+ pop eax
+.print_tan: write_value
+ vertical
+.cmp_ctg: cmp dword [ctg_value], 0ffffffffh
+ jne .ctg
+ mov edx, 8
+ placeholder
+ undefined
+ vertical
+ jmp .nl
+.ctg: push buffer
+ push dword [ctg_value]
+ call result_to_string
+ add esp, 8
+ mov edx, 9
+ sub edx, eax ; indent
+ cmp edx, 0
+ je .print_ctg
+ push eax
+ placeholder
+ pop eax
+.print_ctg: write_value
+ vertical
+.nl: new_line
+ cmp byte [step], 0
+ je .quit
+ add esi, [step] ; next step
+ jmp .lp
+.arg_error: mov eax, 4
+ mov ebx, 1
+ mov ecx, err1msg
+ mov edx, err1len
+ int 80h
+ jmp .exit_code
+.angle_error: mov eax, 4
+ mov ebx, 1
+ mov ecx, err2msg
+ mov edx, err2len
+ int 80h
+ jmp .exit_code
+.greater_error: mov eax, 4
+ mov ebx, 1
+ mov ecx, err3msg
+ mov edx, err3len
+ int 80h
+ jmp .exit_code
+.open_error: mov eax, 4
+ mov ebx, 1
+ mov ecx, err4msg
+ mov edx, err4len
+ int 80h
+.exit_code: mov eax, 1
+ mov ebx, 1
+ int 80h
+.quit: border
+ new_line
+ mov eax, 6 ; close file
+ mov ebx, [f_discr]
+ int 80h
+ mov eax, 1 ; finish
+ mov ebx, 0
+ int 80h
+
+section .bss
+
+f_name resd 1
+f_discr resd 1
+beg_angle resd 1
+end_angle resd 1
+step resd 1
+sin_value resd 1
+cos_value resd 1
+tan_value resd 1
+ctg_value resd 1
+buffer resb 8
+
+section .data
+
+err1msg db "Usage <name file> <start angle> <end angle> <step>", 10
+err1len equ $-err1msg
+err2msg db "Angle must be from 0 to 360", 10
+err2len equ $-err2msg
+err3msg db "Start angle is incorrectly entered", 10
+err3len equ $-err3msg
+err4msg db "Couldn't open source file", 10
+err4len equ $-err4msg
+nlstr db 10
+vert_sep db " | "
+beg_sep db " |"
+end_sep db '|', 10
+hor_sep times 53 db '-'
+hor_length equ $-hor_sep
+border_sep times 53 db '-'
+some_spaces times 8 db ' '
+undef_value db '-'
+title db " | deg | sin | cos | tan | ctg |"
+title_len equ $-title
diff --git a/validations.asm b/validations.asm
new file mode 100644
index 0000000..12c8e26
--- /dev/null
+++ b/validations.asm
@@ -0,0 +1,74 @@
+global check_angle
+global check_tangent
+global check_cotanget
+
+section .text
+;
+; angle validation
+; [ebp+8] is end angle
+; [ebp+12] is begin angle
+; returns eax=-1 if begin angle is greater than end angle
+; eax=0 if end angle < 0 or > 360
+; eax=1 if angles are correct
+;
+check_angle: push ebp
+ mov ebp, esp
+ mov eax, [ebp+8] ; end_angle
+ mov edx, [ebp+12] ; begin_angle
+ cmp edx, eax
+ jg .error2
+ cmp eax, 0
+ jl .error1
+ cmp eax, 360
+ jg .error1
+ mov eax, 1
+ jmp .quit
+.error1: xor eax, eax
+ jmp .quit
+.error2: mov eax, -1
+.quit: pop ebp
+ ret
+
+;
+; tangent test
+; [ebp+8] is integer angle
+; [ebp+12] is pointer to tangent buffer
+; buffer=ffffffffh if tangent=90 or 270
+; else buffer=1
+;
+check_tangent: push ebp
+ mov ebp, esp
+ mov eax, [ebp+8] ; value
+ mov ecx, [ebp+12] ; address
+ mov dword [ecx], 1 ; true
+ cmp eax, 90
+ je .undefined
+ cmp eax, 270
+ je .undefined
+ jmp .quit
+.undefined: mov dword [ecx], 0ffffffffh ; false (255)
+.quit: pop ebp
+ ret
+
+;
+; cotangent test
+; [ebp+8] is integer angle
+; [ebp+12] is pointer to cotangent buffer
+; buffer=ffffffffh if cotangent=0, 180 or 360
+; else buffer=1
+;
+check_cotanget: push ebp
+ mov ebp, esp
+ mov eax, [ebp+8] ; value
+ mov ecx, [ebp+12] ; address
+ mov dword [ecx], 1 ; true
+ cmp eax, 0
+ je .undefined
+ cmp eax, 180
+ je .undefined
+ cmp eax, 360
+ je .undefined
+ jmp .quit
+.undefined: mov dword [ecx], 0ffffffffh ; false (255)
+.quit: pop ebp
+ ret