[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 _printf

[segment .text]

%include "io.asm"


%define _array -20
%define _i -22

_main:
	push bp
	mov bp,sp
	sub sp,word 22
	mov [bp+_i],word 0
	push ax
.L1:	
	push word [bp+_i]
	mov bx,word 10
	pop dx
	cmp dx,bx
	jl .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,[bp+_array]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	mov dx,word [bp+_i]
	pop di
	mov [di],dx
	mov ax,dx
	inc word [bp+_i]
	mov ax,word [bp+_i]
	jmp .L1
.L0:	
	mov [bp+_i],word 0
	push ax
.L5:	
	push word [bp+_i]
	mov bx,word 10
	pop dx
	cmp dx,bx
	jl .L6
	mov ax,word 0
	jmp .L7
.L6:	
	mov ax,word 1
.L7:	
	cmp ax,word 0
	je .L4
	push word 0
	mov bx,word [bp+_i]
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_array]
	pop dx
	imul dx,word 2
	add bx,dx
	push word [bx]
	push word [bp+_i]
	push C0
	call _printf
	add sp,word 6
	inc word [bp+_i]
	mov ax,word [bp+_i]
	jmp .L5
.L4:	
	mov ax,word 0
	leave
	ret
%undef _array
%undef _i



[section .data]

C0: db 'array[%d] == %d',13,10,0

[section .bss]

answer: resb 20

