[BITS 16]
[org 0]
[section .text]

start:
	mov ax,cs
	mov ds,ax
	mov es,ax

	mov ah,03
	mov bh,0
	int 10h

	call _main

	jmp 0x1000:0

global _main
global _get_dir
global _print
global _array_get

[segment .text]

%include "io.asm"


%define _dir_buffer -1024
%define _i -1026

_main:
	push bp
	mov bp,sp
	sub sp,word 1026
	lea ax,[_dir_buffer]
	push ax
	call _get_dir
	add sp,word 2
	mov [bp+_i],word 1
	push ax
.L1:	
	push word 0
	mov bx,word [bp+_i]
	pop dx
	add bx,dx
	push bx
	lea bx,[_dir_buffer]
	pop dx
	add bx,dx
	mov al,[bx]
	cpush al
	mov bx,word '}'
	pop dx
	cmp dx,bx
	jne .L2
	mov ax,word 0
	jmp .L3
.L2:	
	mov ax,word 1
.L3:	
	cmp ax,word 0
	je .L0
	push word 0
	mov bx,word [bp+_i]
	pop dx
	add bx,dx
	push bx
	lea bx,[_dir_buffer]
	pop dx
	add bx,dx
	mov al,[bx]
	cpush al
	mov bx,word '-'
	pop dx
	cmp dx,bx
	je .L5
	mov ax,word 0
	jmp .L6
.L5:	
	mov ax,word 1
.L6:	
	cmp ax,word 0
	je .L7
.L9:	
	push word 0
	mov bx,word [bp+_i]
	pop dx
	add bx,dx
	push bx
	lea bx,[_dir_buffer]
	pop dx
	add bx,dx
	mov al,[bx]
	cpush al
	mov bx,word ','
	pop dx
	cmp dx,bx
	jne .L10
	mov ax,word 0
	jmp .L11
.L10:	
	mov ax,word 1
.L11:	
	cmp ax,word 0
	je .L8
	inc word [bp+_i]
	mov ax,word [bp+_i]
	jmp .L9
.L8:	
	push C0
	call _print
	add sp,word 2
	jmp .L4
.L7:	
	push word 0
	mov bx,word [bp+_i]
	pop dx
	add bx,dx
	push bx
	lea bx,[_dir_buffer]
	pop dx
	add bx,dx
	mov al,[bx]
	cpush al
	call _putc
	add sp,word 2
.L4:	
	inc word [bp+_i]
	mov ax,word [bp+_i]
	jmp .L1
.L0:	
	mov ax,word 0
	leave
	ret
%undef _dir_buffer
%undef _i



[section .data]

C0: db 13,10,0

[section .bss]

answer: resb 20
_dir_buffer: resb 1

