extern io_get_dec, io_print_dec, io_print_char
section .bss
N resd 1
x resd 1
max1 resd 1
max2 resd 1
max3 resd 1
cnt resd 1
section .text
global main
main:
call io_get_dec
mov dword [N], eax
call io_get_dec
mov dword [max1], eax
call io_get_dec
mov dword [x], eax
mov eax, dword [x]
cmp eax, dword [max1]
jge second_to_first
mov dword [max2], eax
jmp read_third
second_to_first:
mov edx, dword [max1]
mov dword [max2], edx
mov dword [max1], eax
read_third:
call io_get_dec
mov dword [x], eax
mov eax, dword [x]
cmp eax, dword [max1]
jge third_to_first
cmp eax, dword [max2]
jge third_to_second
mov dword [max3], eax
jmp first_three_done
third_to_first:
mov edx, dword [max2]
mov dword [max3], edx
mov edx, dword [max1]
mov dword [max2], edx
mov dword [max1], eax
jmp first_three_done
third_to_second:
mov edx, dword [max2]
mov dword [max3], edx
mov dword [max2], eax
first_three_done:
mov eax, dword [N]
sub eax, 3
mov dword [cnt], eax
rest_loop_start:
cmp dword [cnt], 0
je output_answer
call io_get_dec
mov dword [x], eax
mov eax, dword [x]
cmp eax, dword [max1]
jge new_first
cmp eax, dword [max2]
jge new_second
cmp eax, dword [max3]
jge new_third
dec dword [cnt]
jmp rest_loop_start
new_first:
mov edx, dword [max2]
mov dword [max3], edx
mov edx, dword [max1]
mov dword [max2], edx
mov dword [max1], eax
dec dword [cnt]
jmp rest_loop_start
new_second:
mov edx, dword [max2]
mov dword [max3], edx
mov dword [max2], eax
dec dword [cnt]
jmp rest_loop_start
new_third:
mov dword [max3], eax
dec dword [cnt]
jmp rest_loop_start
output_answer:
mov eax, dword [max1]
call io_print_dec
mov eax, ' '
call io_print_char
mov eax, dword [max2]
call io_print_dec
mov eax, ' '
call io_print_char
mov eax, dword [max3]
call io_print_dec
xor eax, eax
ret