back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/trigonometric_table.asm
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 /trigonometric_table.asm
downloadtrigonometric-table-21f616b5593d87d6381c1f3d67a3df0c442dba44.tar.gz
trigonometric-table-21f616b5593d87d6381c1f3d67a3df0c442dba44.tar.bz2
trigonometric-table-21f616b5593d87d6381c1f3d67a3df0c442dba44.zip
Initial commit
Diffstat (limited to 'trigonometric_table.asm')
-rw-r--r--trigonometric_table.asm249
1 files changed, 249 insertions, 0 deletions
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