extern io_get_dec
extern io_print_dec
section .bss
x1 resd 1
x2 resd 1
x3 resd 1
y1 resd 1
y2 resd 1
y3 resd 1
B resd 1
S2 resd 1
I2 resd 1
section .text
global main
abs_val:
push ebp
mov ebp, esp
mov eax, [ebp + 8]
cmp eax, 0
jge .done
neg eax
.done:
pop ebp
ret
gcd_func:
push ebp
mov ebp, esp
mov eax, [ebp + 8]
mov ecx, [ebp + 12]
;eax > ecx
cmp eax, ecx
jge .loop
mov ebx, ecx
mov ecx, eax
mov eax, ebx
.loop:
test ecx, ecx
jz .done
xor edx, edx
div ecx
mov eax, ecx
mov ecx, edx
jmp .loop
get_boundary_pts:
push ebp
mov ebp, esp
push ebx
mov eax, [ebp + 8]
sub eax, [ebp + 16]
;считаем |xa - xb|
push eax
call abs_val
add esp, 4
mov ebx, eax
mov eax, [ebp + 12]
sub eax, [ebp + 20]
;считаем |ya - yb|
push eax
call abs_val
add esp, 4
mov ecx, eax
;считаем их НОД
push ebx
push ecx
call gcd_func
main:
call io_get_dec
mov [x1], eax
call io_get_dec
mov [y1], eax
call io_get_dec
mov [x2], eax
call io_get_dec
mov [y2], eax
call io_get_dec
mov [x3], eax
call io_get_dec
mov [y3], eax
mov dword [B], 0
push dword [y2]
push dword [x2]
push dword [y1]
push dword [x1]
call get_boundary_pts
add dword [B], eax
add esp, 16
push dword [y3]
push dword [x3]
push dword [y2]
push dword [x2]
call get_boundary_pts
add dword [B], eax
add esp, 16
push dword [y3]
push dword [x3]
push dword [y1]
push dword [x1]
call get_boundary_pts
add dword [B], eax
add esp, 16
mov eax, [x2]
sub eax, [x1]
mov ebx, [y3]
sub ebx, [y1]
imul [S2], eax, ebx
mov eax, [x3]
sub eax, [x1]
mov ebx, [y2]
sub ebx, [y1]
imul ecx, eax, ebx
sub [S2], ecx
mov [I2], [S2]
sub [I2], [B]
add [I2], 2
shr dword [I2], 1
xor eax, eax
ret