Online Compiler Nasm

%include 'io.inc' section .bss max1 resd 1 max2 resd 1 max3 resd 1 section .text global main main: GET_DEC 4, ebx mov eax, -2147483648 mov [max1], eax mov [max2], eax mov [max3], eax .loop: cmp ebx, 0 je .print GET_DEC 4, eax cmp eax, [max1] jg .u1 cmp eax, [max2] jg .u2 cmp eax, [max3] jg .u3 jmp .loop .u1: mov edx, [max2] mov [max3], edx mov edx, [max1] mov [max2], edx mov [max1], eax jmp .loop .u2: mov edx, [max2] mov [max3], edx mov [max2], eax jmp .loop .u3: mov [max3], eax jmp .loop .print: PRINT_DEC 4, [max1] PRINT_CHAR ' ' PRINT_DEC 4, [max2] PRINT_CHAR ' ' PRINT_DEC 4, [max3] xor eax, eax ret
1) This code reads a series of integers from input. The first integer specifies how many numbers follow. It then finds and prints the three largest numbers among those following integers.

2) Hint 1: The initial value used for `max1`, `max2`, and `max3` is the smallest possible 32-bit signed integer. Think about why this is a good starting value when searching for maximums.

Hint 2: Pay attention to the order of updates in the `.u1`, `.u2`, and `.u3` labels. Notice how values are shifted downward when a new maximum is found.