@@ 0,0 1,140 @@
+section .text
+org 0x100
+
+
+main_loop:
+
+ ; make sure digits aren't descending
+ mov bx, 0
+ascending_loop:
+ mov al, byte [number+0+bx]
+ cmp al, byte [number+1+bx]
+ jg thank_u_next
+ inc bx
+ cmp bx, 5
+ jne ascending_loop
+
+adjacent:
+ ; find adjacent digits
+ mov bx, 0
+adjacent_loop:
+ mov al, byte [number+bx]
+ cmp al, byte [number+bx+1]
+ je found_adjacent
+continue_adjacent:
+ inc bx
+ cmp bx, 5
+ jne adjacent_loop
+ jmp thank_u_next
+
+skip_rest_of_group:
+ inc bx
+ cmp bx, 5
+ je thank_u_next
+ mov al, byte [number+bx]
+ cmp al, byte [number+bx+1]
+ je skip_rest_of_group
+ jmp adjacent_loop
+
+found_adjacent:
+ mov al, byte [number+bx]
+ cmp al, byte [number+bx+2]
+ je skip_rest_of_group ; group of 3 or more
+ ; found exactly two
+ jmp found
+
+found:
+ ; found an answer!
+ mov di, count
+ call increment_number
+ jmp thank_u_next
+
+ mov di, number
+ call print_number
+
+thank_u_next:
+; increment nuber
+ mov di, number
+ call increment_number
+
+; loop if we haven't reached 789857
+ cmp byte [number+0], 7
+ jne main_loop
+ cmp byte [number+1], 8
+ jne main_loop
+ cmp byte [number+2], 9
+ jne main_loop
+ cmp byte [number+3], 8
+ jne main_loop
+ cmp byte [number+4], 5
+ jne main_loop
+ cmp byte [number+5], 7
+ jne main_loop
+
+ jmp exit
+
+
+
+; increment the number
+increment_number:
+ ; bl holds the digit number
+ mov bx, 5
+increment_number_loop:
+ inc byte [di + bx]
+ cmp byte [di + bx], 10
+ jne increment_number_done
+ ; digit overflowed
+ mov byte [di + bx], 0
+ cmp bx, 0
+ je increment_number_overflow
+ dec bx
+ jmp increment_number_loop
+increment_number_done:
+ ret
+increment_number_overflow:
+ ; panic
+ int 3
+
+; prints the number
+print_number:
+ mov bx, 0
+print_number_loop:
+ ; load next digit
+ mov dl, [ds:di + bx]
+ ; make it ascii
+ add dl, '0'
+ ; print to stdout
+ mov ah, 0x02
+ int 0x21
+
+ inc bl
+ cmp bl, 6
+ jne print_number_loop
+
+ ; print crlf
+ mov ah, 0x9
+ mov dx, crlf
+ int 0x21
+ ret
+
+
+
+
+exit:
+
+ mov di, count
+ call print_number
+
+ mov ax, 0x4c00
+ int 0x21
+
+section .data
+; constants
+crlf: db 13, 10, '$'
+
+; number digits
+number: db 2, 4, 0, 9, 2, 0
+past_the_number: db 0xff ; to make comparisons simpler
+
+; number of possible passwords
+count: db 0, 0, 0, 0, 0, 0<
\ No newline at end of file