extern io_get_dec, io_print_udec
section .bss
x1 resd 1
y1 resd 1
x2 resd 1
y2 resd 1
x3 resd 1
y3 resd 1
double_area_low resd 1
double_area_high resd 1
border_points_low resd 1
border_points_high resd 1
section .text
global main
find_gcd:
push ebp
mov ebp, esp
mov eax, [ebp + 8]
mov ecx, [ebp + 12]
find_gcd_loop:
test ecx, ecx
jz find_gcd_done
xor edx, edx
div ecx
mov eax, ecx
mov ecx, edx
jmp find_gcd_loop
find_gcd_done:
mov esp, ebp
pop ebp
ret
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 [double_area_low], 0
mov dword [double_area_high], 0
mov eax, [x1]
mov ecx, [y2]
sub ecx, [y3]
imul ecx
add dword [double_area_low], eax
adc dword [double_area_high], edx
mov eax, [x2]
mov ecx, [y3]
sub ecx, [y1]
imul ecx
add dword [double_area_low], eax
adc dword [double_area_high], edx
mov eax, [x3]
mov ecx, [y1]
sub ecx, [y2]
imul ecx
add dword [double_area_low], eax
adc dword [double_area_high], edx
cmp dword [double_area_high], 0
jge double_area_absolute_done
not dword [double_area_low]
not dword [double_area_high]
add dword [double_area_low], 1
adc dword [double_area_high], 0
double_area_absolute_done:
mov dword [border_points_low], 0
mov dword [border_points_high], 0
mov eax, [x2]
cmp eax, [x1]
jge edge12_x_ok
mov eax, [x1]
sub eax, [x2]
jmp edge12_x_push
edge12_x_ok:
sub eax, [x1]
edge12_x_push:
push eax
mov eax, [y2]
cmp eax, [y1]
jge edge12_y_ok
mov eax, [y1]
sub eax, [y2]
jmp edge12_y_push
edge12_y_ok:
sub eax, [y1]
edge12_y_push:
push eax
call find_gcd
add esp, 8
add dword [border_points_low], eax
adc dword [border_points_high], 0
mov eax, [x3]
cmp eax, [x2]
jge edge23_x_ok
mov eax, [x2]
sub eax, [x3]
jmp edge23_x_push
edge23_x_ok:
sub eax, [x2]
edge23_x_push:
push eax
mov eax, [y3]
cmp eax, [y2]
jge edge23_y_ok
mov eax, [y2]
sub eax, [y3]
jmp edge23_y_push
edge23_y_ok:
sub eax, [y2]
edge23_y_push:
push eax
call find_gcd
add esp, 8
add dword [border_points_low], eax
adc dword [border_points_high], 0
mov eax, [x1]
cmp eax, [x3]
jge edge31_x_ok
mov eax, [x3]
sub eax, [x1]
jmp edge31_x_push
edge31_x_ok:
sub eax, [x3]
edge31_x_push:
push eax
mov eax, [y1]
cmp eax, [y3]
jge edge31_y_ok
mov eax, [y3]
sub eax, [y1]
jmp edge31_y_push
edge31_y_ok:
sub eax, [y3]
edge31_y_push:
push eax
call find_gcd
add esp, 8
add dword [border_points_low], eax
adc dword [border_points_high], 0
mov eax, [border_points_low]
mov edx, [border_points_high]
sub dword [double_area_low], eax
sbb dword [double_area_high], edx
add dword [double_area_low], 2
adc dword [double_area_high], 0
mov eax, [double_area_low]
mov edx, [double_area_high]
shrd eax, edx, 1
call io_print_udec
ret