format PE console
include 'win32a.inc'
entry start

section '.data' data readable writeable 

my_tbl 		 db     0x8f, 0x09, 0x2c, 0xca, 0x00, 0x35, 0xd3, 0xde, 0x6d, 0xed
             db     0xd8, 0xf5, 0x7b, 0x4b, 0xb1, 0x7d, 0x0c, 0x8a, 0x25, 0x8b
             db     0x32, 0x0b, 0x2f, 0x09, 0xf0, 0x37, 0x86, 0x06, 0xda, 0x9d
             db     0xb8, 0x25, 0x17, 0x8c, 0xff, 0x36, 0x56, 0x6e, 0xe3, 0xd2
             db     0x11, 0xa6, 0x8f, 0x8b, 0xb5, 0xc2, 0x8f, 0xcd, 0x05, 0x2b
             db     0x58, 0x0a, 0x56, 0x05, 0x33, 0xe3, 0xa5, 0x07, 0x30, 0x4e
             db     0x63, 0xd2, 0x18, 0x00, 0xb0, 0x6c, 0xc0, 0xdc, 0xd7, 0xcf
             db     0x0d, 0xef, 0x00, 0x71, 0x12, 0x75, 0xb2, 0x2c, 0x52, 0x20
             db     0xda, 0xbe, 0x9f, 0x7d, 0xfe, 0xc0, 0x47, 0x88, 0x03, 0x83
             db     0x29, 0x7f, 0xea, 0x15, 0x86, 0x13, 0x41, 0xa6, 0x1b, 0x7a
             db     0x67, 0xe4, 0x51, 0x97, 0x37, 0x50, 0x67, 0x42, 0xbf, 0x32
             db     0xac, 0xea, 0x88, 0xc1, 0x93, 0x37, 0x33, 0xa7, 0x02, 0x21
             db     0x47, 0x74, 0x8c, 0x9f, 0xc8, 0x59, 0xe1, 0xfe, 0xd9, 0xe1
             db     0x0e, 0xac, 0x38, 0x98, 0x15, 0xe0, 0xf3, 0xd0, 0x1b, 0x4c
             db     0x02, 0x5a, 0xf2, 0x13, 0x19, 0x51, 0xca, 0xd3, 0x33, 0xd4
             db     0x77, 0x1b, 0x28, 0x56, 0x57, 0x99, 0x46, 0x7a, 0xb5, 0xce
             db     0x6d, 0xee, 0x30, 0xd9, 0xcf, 0x13, 0x4a, 0xeb, 0xac, 0x17
             db     0x08, 0x41, 0x32, 0x0a, 0x6e, 0xd4, 0xf7, 0x00, 0x82, 0x12
             db     0xcc, 0xf8, 0xea, 0x17, 0xdd, 0xcb, 0xeb, 0x72, 0x26, 0x04
             db     0x89, 0x4d, 0xfb, 0xae, 0xd6, 0x8b, 0x4a, 0x14, 0xd4, 0xea
             db     0x32, 0x58, 0x91, 0xf7, 0x25, 0xee, 0x51, 0xb7, 0x28, 0x1e
             db     0x98, 0x75, 0xd1, 0xef, 0x99, 0x83, 0x3b, 0x33, 0xa8, 0xa3
             db     0xd2, 0x17, 0x94, 0x6d, 0xad, 0x82, 0x30, 0xdd, 0x93, 0xd6
             db     0x8e, 0x9a, 0x49, 0x77, 0x9d, 0x9d, 0xce, 0x61, 0x71, 0xe4
             db     0xea, 0xa4, 0x8d, 0xfc, 0xf2, 0x62, 0xe4, 0x22, 0xe9, 0x91
             db     0x14, 0x71, 0x83, 0x21, 0x95, 0xc5
			 
tbl_length = $ - my_tbl


start:
		
	mov ecx,tbl_length 		;loop for the amount of times as there are numbers in the list
	xor esi,esi					;esi will be the memory incrementor 
	
	mov al, byte[my_tbl+esi]		;set 1byte AL register to the first number to be tested in the array

loop_tester:
	
	cmp al, byte[my_tbl+esi]		;compare the number in AL to the value of the byte @ my_tbl plus ESI offset incrementor
	jb next_num						;if the value is less than one of them, switch to the next one
	
	inc esi							;increase esi by ONE BYTE to point to the next byte in memory. If this was a word we'd plus 2 and for a dword plus 4Bytes
	loop loop_tester				;ecx gets decreased by one for each iteration until its zero, ecx is always initialized to the size of the array which is the constant 'tbl_length'
	
	jmp exit_process				;if it gets here we have our number stored in al so don't touch anything and jump over to exit process to print it and exit
	
next_num:
	
	mov al, byte[my_tbl+esi]		;overwrite the old AL with the one that just beat it in loop_tester above
	;mov ecx,tbl_length				;reset ecx again so that the new AL is tested against all values, it turns out that this is not actually necessary, it works either way but I suppose its less iterations
	jmp loop_tester					;unconditional jump to get back up into loop_tester and kick ass
	
exit_process:

	movzx eax, al					;you have to use this. I tried to use " movzx eax, byte[my_tbl+esi " and it fucked around hard...
	;movzx eax, byte[my_tbl+esi]
	call print_eax
	
	push 0
	call [ExitProcess]
	
	
	
include 'training.inc'