back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/trigonometric_table.asm
blob: d596204efb93a9139a95555a2f1da180bdb60e63 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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