[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 _gets
global _strstr
global _bzero
global _is_digit
global _strlen
global _atoi
global _scanf
global _print_short
global _printf
global _strcpy
global _getch
global _writefile
global _putc
global _getch
global _strcmp

[segment .text]

%include "io.asm"


%define _ret -2
%define _i -4
%define _n -6
%define _off -8
%define _num -20
%define temp1 -22
%define _str 4

_atoi:
	push bp
	mov bp,sp
	sub sp,word 20
	push word 0
	push 4
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	push 10000
	pop dx
	pop di
	mov [di],dx
	push dx
	pop ax
	push word 0
	push 3
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	push 1000
	pop dx
	pop di
	mov [di],dx
	push dx
	pop ax
	push word 0
	push 2
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	push 100
	pop dx
	pop di
	mov [di],dx
	push dx
	pop ax
	push word 0
	push 1
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	push 10
	pop dx
	pop di
	mov [di],dx
	push dx
	pop ax
	push word 0
	push 0
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	push 1
	pop dx
	pop di
	mov [di],dx
	push dx
	pop ax
	push 0
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	push word [bp+_str]
	call _strlen
	add sp,word 2
	push ax
	pop ax
	mov [bp+_n],ax
	push ax
	pop ax
	push word [bp+_n]
	push 1
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop ax
	mov [bp+_off],ax
	push ax
	pop ax
	push 0
	pop ax
	mov [bp+_i],ax
	push ax
.L53:	
	push word [bp+_i]
	push word [bp+_n]
	pop bx
	pop dx
	cmp dx,bx
	jl .L54
	push 0
	jmp .L55
.L54:	
	push 1
.L55:	
	pop ax
	cmp ax,word 0
	je .L52
	sub sp,word 2
	push word 0
	push word [bp+_i]
	pop bx
	pop dx
	add bx,dx
	push bx
	mov bx,[bp+_str]
	pop dx
	add bx,dx
	push bx
	pop bx
	mov al,[bx]
	cpush al
	pop word [bp+temp1]
	mov ax,'0'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L57
	jmp .L56
.L57:	
	mov ax,'1'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L58
	push word [bp+_ret]
	push 1
	push word 0
	push word [bp+_off]
	push word [bp+_i]
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	pop bx
	mov dx,[bx]
	push dx
	pop bx
	pop dx
	imul bx,dx
	push bx
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	jmp .L56
.L58:	
	mov ax,'2'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L59
	push word [bp+_ret]
	push 2
	push word 0
	push word [bp+_off]
	push word [bp+_i]
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	pop bx
	mov dx,[bx]
	push dx
	pop bx
	pop dx
	imul bx,dx
	push bx
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	jmp .L56
.L59:	
	mov ax,'3'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L60
	push word [bp+_ret]
	push 3
	push word 0
	push word [bp+_off]
	push word [bp+_i]
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	pop bx
	mov dx,[bx]
	push dx
	pop bx
	pop dx
	imul bx,dx
	push bx
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	jmp .L56
.L60:	
	mov ax,'4'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L61
	push word [bp+_ret]
	push 4
	push word 0
	push word [bp+_off]
	push word [bp+_i]
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	pop bx
	mov dx,[bx]
	push dx
	pop bx
	pop dx
	imul bx,dx
	push bx
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	jmp .L56
.L61:	
	mov ax,'5'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L62
	push word [bp+_ret]
	push 5
	push word 0
	push word [bp+_off]
	push word [bp+_i]
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	pop bx
	mov dx,[bx]
	push dx
	pop bx
	pop dx
	imul bx,dx
	push bx
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	jmp .L56
.L62:	
	mov ax,'6'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L63
	push word [bp+_ret]
	push 6
	push word 0
	push word [bp+_off]
	push word [bp+_i]
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	pop bx
	mov dx,[bx]
	push dx
	pop bx
	pop dx
	imul bx,dx
	push bx
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	jmp .L56
.L63:	
	mov ax,'7'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L64
	push word [bp+_ret]
	push 7
	push word 0
	push word [bp+_off]
	push word [bp+_i]
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	pop bx
	mov dx,[bx]
	push dx
	pop bx
	pop dx
	imul bx,dx
	push bx
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	jmp .L56
.L64:	
	mov ax,'8'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L65
	push word [bp+_ret]
	push 8
	push word 0
	push word [bp+_off]
	push word [bp+_i]
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	pop bx
	mov dx,[bx]
	push dx
	pop bx
	pop dx
	imul bx,dx
	push bx
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	jmp .L56
.L65:	
	mov ax,'9'
	mov bx,word [bp+temp1]
	cmp ax,bx
	jne .L66
	push word [bp+_ret]
	push 9
	push word 0
	push word [bp+_off]
	push word [bp+_i]
	pop bx
	pop dx
	sub dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_num]
	pop dx
	imul dx,word 2
	add bx,dx
	push bx
	pop bx
	mov dx,[bx]
	push dx
	pop bx
	pop dx
	imul bx,dx
	push bx
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	jmp .L56
.L66:	
.L56:	
	inc word [bp+_i]
	push word [bp+_i]
	pop ax
	jmp .L53
.L52:	
	push word [bp+_ret]
	pop ax
	leave
	ret
%undef _ret
%undef _i
%undef _n
%undef _off
%undef _num
%undef temp1
%undef _str

%define _i -2
%define _ptr 4
%define _len 6

_bzero:
	push bp
	mov bp,sp
	sub sp,word 2
	push 0
	pop ax
	mov [bp+_i],ax
	push ax
.L41:	
	push word [bp+_i]
	push word [bp+_len]
	pop bx
	pop dx
	cmp dx,bx
	jl .L42
	push 0
	jmp .L43
.L42:	
	push 1
.L43:	
	pop ax
	cmp ax,word 0
	je .L40
	sub sp,word 0
	push word 0
	push word [bp+_i]
	pop bx
	pop dx
	add bx,dx
	push bx
	mov bx,[bp+_ptr]
	pop dx
	add bx,dx
	push bx
	push word 0
	pop dx
	pop di
	mov [di],dx
	push dx
	pop ax
	inc word [bp+_i]
	push word [bp+_i]
	pop ax
	jmp .L41
.L40:	
	leave
	ret

%undef _i
%undef _ptr
%undef _len

%define _ch -2
%define _i -4
%define _ptr 4

_gets:
	push bp
	mov bp,sp
	sub sp,word 4
	push 0
	pop ax
	mov [bp+_i],ax
	push ax
	pop ax
.L13:	
	push word [bp+_ch]
	call _getch
	push ax
	pop bx
	pop dx
	cmp dx,bx
	je .L14
	push 0
	jmp .L15
.L14:	
	push 1
.L15:	
	push word 10
	pop bx
	pop dx
	cmp dx,bx
	jne .L16
	push 0
	jmp .L17
.L16:	
	push 1
.L17:	
	pop ax
	cmp ax,word 0
	je .L12
	sub sp,word 0
	push word [bp+_ch]
	call _putc
	add sp,word 2
	push ax
	pop ax
	push word [bp+_ch]
	push word 10
	pop bx
	pop dx
	cmp dx,bx
	jne .L19
	push 0
	jmp .L20
.L19:	
	push 1
.L20:	
	push word [bp+_ch]
	push word 13
	pop bx
	pop dx
	cmp dx,bx
	jne .L21
	push 0
	jmp .L22
.L21:	
	push 1
.L22:	
	pop bx
	pop ax
	and ax,bx
	push ax
	pop ax
	cmp ax,word 0
	je .L23
	sub sp,word 0
	push word 0
	push word [bp+_i]
	pop bx
	pop dx
	add bx,dx
	push bx
	mov bx,[bp+_ptr]
	pop dx
	add bx,dx
	push bx
	push word [bp+_ch]
	pop dx
	pop di
	mov [di],dx
	push dx
	pop ax
	jmp .L18
.L23:	
.L18:	
	inc word [bp+_i]
	push word [bp+_i]
	pop ax
	jmp .L13
.L12:	
	push word 0
	push word [bp+_i]
	pop bx
	pop dx
	add bx,dx
	push bx
	mov bx,[bp+_ptr]
	pop dx
	add bx,dx
	push bx
	push word 0
	pop dx
	pop di
	mov [di],dx
	push dx
	pop ax
	push word [bp+_ptr]
	pop ax
	leave
	ret
%undef _ch
%undef _i
%undef _ptr

%define _ch 4

_is_digit:
	push bp
	mov bp,sp
	sub sp,word 0
	push word [bp+_ch]
	push word '0'
	pop bx
	pop dx
	cmp dx,bx
	jge .L45
	push 0
	jmp .L46
.L45:	
	push 1
.L46:	
	push word [bp+_ch]
	push word '9'
	pop bx
	pop dx
	cmp dx,bx
	jle .L47
	push 0
	jmp .L48
.L47:	
	push 1
.L48:	
	pop bx
	pop ax
	and ax,bx
	push ax
	pop ax
	cmp ax,word 0
	je .L49
	sub sp,word 0
	push 1
	pop ax
	leave
	ret
	jmp .L44
.L49:	
.L44:	
	push 0
	pop ax
	leave
	ret
%undef _ch

%define _ch -2
%define _i -4
%define _buffer -516
%define _name -616

_main:
	push bp
	mov bp,sp
	sub sp,word 616
	push 512
	lea ax,[bp+_buffer]
	push ax
	call _bzero
	add sp,word 4
	push 100
	lea ax,[bp+_name]
	push ax
	call _bzero
	add sp,word 4
	push C0
	call _printf
	add sp,word 2
	push ax
	pop ax
	lea ax,[bp+_name]
	push ax
	call _gets
	add sp,word 2
	push ax
	pop ax
	push C1
	call _printf
	add sp,word 2
	push ax
	pop ax
	push C2
	call _printf
	add sp,word 2
	push ax
	pop ax
	push 0
	pop ax
	mov [bp+_i],ax
	push ax
	pop ax
.L1:	
	call _getch
	push ax
	pop ax
	mov [bp+_ch],ax
	push ax
	push word '$'
	pop bx
	pop dx
	cmp dx,bx
	jne .L2
	push 0
	jmp .L3
.L2:	
	push 1
.L3:	
	pop ax
	cmp ax,word 0
	je .L0
	sub sp,word 0
	push word [bp+_ch]
	push word 8
	pop bx
	pop dx
	cmp dx,bx
	je .L5
	push 0
	jmp .L6
.L5:	
	push 1
.L6:	
	pop ax
	cmp ax,word 0
	je .L7
	jmp .L1
	jmp .L4
.L7:	
.L4:	
	push word [bp+_ch]
	push C3
	call _printf
	add sp,word 4
	push ax
	pop ax
	push word 0
	push word [bp+_i]
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_buffer]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word [bp+_ch]
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	inc word [bp+_i]
	push word [bp+_i]
	pop ax
	push word [bp+_i]
	push 512
	pop bx
	pop dx
	cmp dx,bx
	jge .L9
	push 0
	jmp .L10
.L9:	
	push 1
.L10:	
	pop ax
	cmp ax,word 0
	je .L11
	sub sp,word 0
	jmp .L0
	jmp .L8
.L11:	
.L8:	
	jmp .L1
.L0:	
	lea ax,[bp+_buffer]
	push ax
	lea ax,[bp+_name]
	push ax
	call _writefile
	add sp,word 4
	push ax
	pop ax
	push 0
	pop ax
	leave
	ret
%undef _ch
%undef _i
%undef _buffer
%undef _name

%define _ret -2
%define _n -4
%define _byte_array -14
%define _buffer -24
%define _index -26
%define _number 4

_print_short:
	push bp
	mov bp,sp
	sub sp,word 26
	push 0
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	push word 0
	push 0
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '0'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word 0
	push 1
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '1'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word 0
	push 2
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '2'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word 0
	push 3
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '3'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word 0
	push 4
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '4'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word 0
	push 5
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '5'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word 0
	push 6
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '6'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word 0
	push 7
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '7'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word 0
	push 8
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '8'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word 0
	push 9
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word '9'
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	push word [bp+_number]
	push 0
	pop bx
	pop dx
	cmp dx,bx
	je .L93
	push 0
	jmp .L94
.L93:	
	push 1
.L94:	
	pop ax
	cmp ax,word 0
	je .L95
	sub sp,word 0
	push word '0'
	call _putc
	add sp,word 2
	push ax
	pop ax
	jmp .L92
.L95:	
.L92:	
	push 0
	pop ax
	mov [bp+_index],ax
	push ax
	pop ax
.L97:	
	push word [bp+_number]
	pop ax
	cmp ax,word 0
	je .L96
	sub sp,word 0
	push word [bp+_number]
	push 10
	pop bx
	pop ax
	xor dx,dx
	idiv bx
	push dx
	pop ax
	mov [bp+_n],ax
	push ax
	pop ax
	push word [bp+_number]
	push 10
	pop bx
	pop ax
	xor dx,dx
	idiv bx
	push ax
	pop ax
	mov [bp+_number],ax
	push ax
	pop ax
	push word 0
	push word [bp+_index]
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_buffer]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word 0
	push word [bp+_n]
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_byte_array]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	pop bx
	mov al,[bx]
	cpush al
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	inc word [bp+_index]
	push word [bp+_index]
	pop ax
	jmp .L97
.L96:	
	dec word [bp+_index]
	push word [bp+_index]
	pop ax
.L99:	
	push word [bp+_index]
	push 0
	pop bx
	pop dx
	cmp dx,bx
	jge .L100
	push 0
	jmp .L101
.L100:	
	push 1
.L101:	
	pop ax
	cmp ax,word 0
	je .L98
	sub sp,word 0
	push word 0
	push word [bp+_index]
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_buffer]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	pop bx
	mov al,[bx]
	cpush al
	call _putc
	add sp,word 2
	push ax
	pop ax
	dec word [bp+_index]
	push word [bp+_index]
	pop ax
	jmp .L99
.L98:	
	push word [bp+_ret]
	pop ax
	leave
	ret
%undef _ret
%undef _n
%undef _byte_array
%undef _buffer
%undef _index
%undef _number

%define _ptr -2
%define _ptr0 -4
%define _ptr1 -6
%define _i -8
%define _j -10
%define _ret -12
%define _fmt 4

_printf:
	push bp
	mov bp,sp
	sub sp,word 12
	push 0
	pop ax
	mov [bp+_ret],ax
	push ax
	pop ax
	push word [bp+_fmt]
	pop ax
	mov [bp+_ptr],ax
	push ax
	pop ax
	push 2
	pop ax
	mov [bp+_i],ax
	push ax
	pop ax
.L103:	
	mov di,[bp+_ptr]
	mov al,[di]
	cpush al
	cpop al
	cmp al,byte 0
	je .L102
	sub sp,word 0
	mov di,[bp+_ptr]
	mov al,[di]
	cpush al
	push word '%'
	pop bx
	pop dx
	cmp dx,bx
	je .L105
	push 0
	jmp .L106
.L105:	
	push 1
.L106:	
	pop ax
	cmp ax,word 0
	je .L107
	sub sp,word 0
	inc word [bp+_ptr]
	push word [bp+_ptr]
	pop ax
	mov di,[bp+_ptr]
	mov al,[di]
	cpush al
	push word '%'
	pop bx
	pop dx
	cmp dx,bx
	je .L109
	push 0
	jmp .L110
.L109:	
	push 1
.L110:	
	pop ax
	cmp ax,word 0
	je .L111
	sub sp,word 0
	push word '%'
	call _putc
	add sp,word 2
	push ax
	pop ax
	inc word [bp+_ptr]
	push word [bp+_ptr]
	pop ax
	jmp .L108
.L111:	
	mov di,[bp+_ptr]
	mov al,[di]
	cpush al
	push word 'x'
	pop bx
	pop dx
	cmp dx,bx
	je .L112
	push 0
	jmp .L113
.L112:	
	push 1
.L113:	
	pop ax
	cmp ax,word 0
	je .L114
	sub sp,word 0
	lea ax,[bp+_fmt]
	push ax
	push word [bp+_i]
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ptr0],ax
	push ax
	pop ax
	push bp
	mov ax,[bp+_ptr0]
	mov bp,ax
	mov dx,[bp]
	pop bp
	push dx
	call _tohex
	add sp,word 2
	push 2
	mov bx,[bp+_i]
	pop dx
	add bx,dx
	push bx
	pop ax
	mov [bp+_i],ax
	push ax
	pop ax
	inc word [bp+_ptr]
	push word [bp+_ptr]
	pop ax
	jmp .L108
.L114:	
	mov di,[bp+_ptr]
	mov al,[di]
	cpush al
	push word 'd'
	pop bx
	pop dx
	cmp dx,bx
	je .L115
	push 0
	jmp .L116
.L115:	
	push 1
.L116:	
	pop ax
	cmp ax,word 0
	je .L117
	sub sp,word 0
	lea ax,[bp+_fmt]
	push ax
	push word [bp+_i]
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ptr0],ax
	push ax
	pop ax
	push bp
	mov ax,[bp+_ptr0]
	mov bp,ax
	mov dx,[bp]
	pop bp
	push dx
	call _print_short
	add sp,word 2
	push ax
	pop ax
	push 2
	mov bx,[bp+_i]
	pop dx
	add bx,dx
	push bx
	pop ax
	mov [bp+_i],ax
	push ax
	pop ax
	inc word [bp+_ptr]
	push word [bp+_ptr]
	pop ax
	jmp .L108
.L117:	
	mov di,[bp+_ptr]
	mov al,[di]
	cpush al
	push word 's'
	pop bx
	pop dx
	cmp dx,bx
	je .L118
	push 0
	jmp .L119
.L118:	
	push 1
.L119:	
	pop ax
	cmp ax,word 0
	je .L120
	sub sp,word 0
	lea ax,[bp+_fmt]
	push ax
	push word [bp+_i]
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ptr0],ax
	push ax
	pop ax
	push bp
	mov ax,[bp+_ptr0]
	mov bp,ax
	mov dx,[bp]
	pop bp
	push dx
	pop ax
	mov [bp+_ptr1],ax
	push ax
	pop ax
.L122:	
	mov di,[bp+_ptr1]
	mov al,[di]
	cpush al
	cpop al
	cmp al,byte 0
	je .L121
	sub sp,word 0
	mov di,[bp+_ptr1]
	mov al,[di]
	cpush al
	call _putc
	add sp,word 2
	push ax
	pop ax
	inc word [bp+_ptr1]
	push word [bp+_ptr1]
	pop ax
	jmp .L122
.L121:	
	push 2
	mov bx,[bp+_i]
	pop dx
	add bx,dx
	push bx
	pop ax
	mov [bp+_i],ax
	push ax
	pop ax
	inc word [bp+_ptr]
	push word [bp+_ptr]
	pop ax
	jmp .L108
.L120:	
	sub sp,word 0
	inc word [bp+_ptr]
	push word [bp+_ptr]
	pop ax
.L108:	
	jmp .L104
.L107:	
	sub sp,word 0
	mov di,[bp+_ptr]
	mov al,[di]
	cpush al
	call _putc
	add sp,word 2
	push ax
	pop ax
	inc word [bp+_ptr]
	push word [bp+_ptr]
	pop ax
.L104:	
	jmp .L103
.L102:	
	push 0
	pop ax
	leave
	ret
%undef _ptr
%undef _ptr0
%undef _ptr1
%undef _i
%undef _j
%undef _ret
%undef _fmt

%define _ptr -2
%define _p -4
%define _temp -6
%define _buffer -106
%define _offset -108
%define _ch -110
%define _count -112
%define _fmt 4

_scanf:
	push bp
	mov bp,sp
	sub sp,word 112
	push 0
	pop ax
	mov [bp+_offset],ax
	push ax
	pop ax
	push 2
	pop ax
	mov [bp+_count],ax
	push ax
	pop ax
	lea ax,[bp+_fmt]
	push ax
	push word [bp+_count]
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ptr],ax
	push ax
	pop ax
	push word [bp+_fmt]
	pop ax
	mov [bp+_p],ax
	push ax
.L68:	
	mov di,[bp+_p]
	mov al,[di]
	cpush al
	cpop al
	cmp al,byte 0
	je .L67
	sub sp,word 0
	mov di,[bp+_p]
	mov al,[di]
	cpush al
	push word '%'
	pop bx
	pop dx
	cmp dx,bx
	je .L70
	push 0
	jmp .L71
.L70:	
	push 1
.L71:	
	pop ax
	cmp ax,word 0
	je .L72
	sub sp,word 0
	inc word [bp+_p]
	push word [bp+_p]
	pop ax
	mov di,[bp+_p]
	mov al,[di]
	cpush al
	push word 'd'
	pop bx
	pop dx
	cmp dx,bx
	je .L74
	push 0
	jmp .L75
.L74:	
	push 1
.L75:	
	pop ax
	cmp ax,word 0
	je .L76
	sub sp,word 0
	push bp
	mov ax,[bp+_ptr]
	mov bp,ax
	mov dx,[bp]
	pop bp
	push dx
	pop ax
	mov [bp+_temp],ax
	push ax
	pop ax
	call _getch
	push ax
	pop ax
	mov [bp+_ch],ax
	push ax
	pop ax
	push word [bp+_ch]
	call _putc
	add sp,word 2
	push ax
	pop ax
	push 0
	pop ax
	mov [bp+_offset],ax
	push ax
	pop ax
.L78:	
	push word [bp+_ch]
	call _is_digit
	add sp,word 2
	push ax
	push word [bp+_ch]
	push word 13
	pop bx
	pop dx
	cmp dx,bx
	jne .L79
	push 0
	jmp .L80
.L79:	
	push 1
.L80:	
	push word [bp+_ch]
	push word 10
	pop bx
	pop dx
	cmp dx,bx
	jne .L81
	push 0
	jmp .L82
.L81:	
	push 1
.L82:	
	pop bx
	pop ax
	and ax,bx
	push ax
	pop bx
	pop ax
	and ax,bx
	push ax
	pop ax
	cmp ax,word 0
	je .L77
	sub sp,word 0
	push word 0
	push word [bp+_offset]
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_buffer]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word [bp+_ch]
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	inc word [bp+_offset]
	push word [bp+_offset]
	pop ax
	call _getch
	push ax
	pop ax
	mov [bp+_ch],ax
	push ax
	pop ax
	push word [bp+_ch]
	call _putc
	add sp,word 2
	push ax
	pop ax
	jmp .L78
.L77:	
	push word 0
	push word [bp+_offset]
	pop bx
	pop dx
	add bx,dx
	push bx
	lea bx,[bp+_buffer]
	pop dx
	imul dx,word 1
	add bx,dx
	push bx
	push word 0
	cpop al
	pop di
	mov [di],al
	cpush al
	pop ax
	lea ax,[bp+_buffer]
	push ax
	call _atoi
	add sp,word 2
	push ax
	pop ax
	mov di,[bp+_temp]
	mov [di],ax
	push ax
	pop ax
	push word [bp+_count]
	push 2
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_count],ax
	push ax
	pop ax
	lea ax,[bp+_fmt]
	push ax
	push word [bp+_count]
	pop bx
	pop dx
	add dx,bx
	push dx
	pop ax
	mov [bp+_ptr],ax
	push ax
	pop ax
	jmp .L73
.L76:	
	mov di,[bp+_p]
	mov al,[di]
	cpush al
	push word 'f'
	pop bx
	pop dx
	cmp dx,bx
	je .L83
	push 0
	jmp .L84
.L83:	
	push 1
.L84:	
	pop ax
	cmp ax,word 0
	je .L85
	sub sp,word 0
	nop
	jmp .L73
.L85:	
	mov di,[bp+_p]
	mov al,[di]
	cpush al
	push word 's'
	pop bx
	pop dx
	cmp dx,bx
	je .L86
	push 0
	jmp .L87
.L86:	
	push 1
.L87:	
	pop ax
	cmp ax,word 0
	je .L88
	sub sp,word 0
	nop
	jmp .L73
.L88:	
	mov di,[bp+_p]
	mov al,[di]
	cpush al
	push word 'c'
	pop bx
	pop dx
	cmp dx,bx
	je .L89
	push 0
	jmp .L90
.L89:	
	push 1
.L90:	
	pop ax
	cmp ax,word 0
	je .L91
	sub sp,word 0
	nop
	jmp .L73
.L91:	
.L73:	
	jmp .L69
.L72:	
	sub sp,word 0
	nop
.L69:	
	inc word [bp+_p]
	push word [bp+_p]
	pop ax
	jmp .L68
.L67:	
	push 0
	pop ax
	leave
	ret
%undef _ptr
%undef _p
%undef _temp
%undef _buffer
%undef _offset
%undef _ch
%undef _count
%undef _fmt

%define _a 4
%define _b 6

_strcpy:
	push bp
	mov bp,sp
	sub sp,word 0
.L124:	
	mov di,[bp+_b]
	mov al,[di]
	cpush al
	cpop al
	mov di,[bp+_a]
	mov [di],al
	cpush al
	cpop al
	cmp al,byte 0
	je .L123
	sub sp,word 0
	inc word [bp+_a]
	push word [bp+_a]
	pop ax
	inc word [bp+_b]
	push word [bp+_b]
	pop ax
	jmp .L124
.L123:	
	leave
	ret

%undef _a
%undef _b

%define _n -2
%define _ptr 4

_strlen:
	push bp
	mov bp,sp
	sub sp,word 2
	push 0
	pop ax
	mov [bp+_n],ax
	push ax
	pop ax
.L51:	
	mov di,[bp+_ptr]
	mov al,[di]
	cpush al
	cpop al
	cmp al,byte 0
	je .L50
	sub sp,word 0
	inc word [bp+_n]
	push word [bp+_n]
	pop ax
	inc word [bp+_ptr]
	push word [bp+_ptr]
	pop ax
	jmp .L51
.L50:	
	push word [bp+_n]
	pop ax
	leave
	ret
%undef _n
%undef _ptr

%define _ptr -2
%define _i -4
%define _j -6
%define _count -8
%define _buffer 4
%define _str 6

_strstr:
	push bp
	mov bp,sp
	sub sp,word 8
	push 0
	pop ax
	mov [bp+_ptr],ax
	push ax
	pop ax
	push 0
	pop ax
	mov [bp+_count],ax
	push ax
	pop ax
	push word [bp+_buffer]
	pop ax
	mov [bp+_ptr],ax
	push ax
	pop ax
	push 0
	pop ax
	mov [bp+_i],ax
	push ax
.L25:	
	push word [bp+_i]
	push word [bp+_buffer]
	call _strlen
	add sp,word 2
	push ax
	pop bx
	pop dx
	cmp dx,bx
	jl .L26
	push 0
	jmp .L27
.L26:	
	push 1
.L27:	
	pop ax
	cmp ax,word 0
	je .L24
	sub sp,word 0
	push 0
	pop ax
	mov [bp+_j],ax
	push ax
.L29:	
	push word [bp+_j]
	push word [bp+_str]
	call _strlen
	add sp,word 2
	push ax
	pop bx
	pop dx
	cmp dx,bx
	jl .L30
	push 0
	jmp .L31
.L30:	
	push 1
.L31:	
	pop ax
	cmp ax,word 0
	je .L28
	sub sp,word 0
	push word 0
	push word [bp+_i]
	push word [bp+_j]
	pop bx
	pop dx
	add dx,bx
	push dx
	pop bx
	pop dx
	add bx,dx
	push bx
	mov bx,[bp+_buffer]
	pop dx
	add bx,dx
	push bx
	pop bx
	mov al,[bx]
	cpush al
	push word 0
	push word [bp+_j]
	pop bx
	pop dx
	add bx,dx
	push bx
	mov bx,[bp+_str]
	pop dx
	add bx,dx
	push bx
	pop bx
	mov al,[bx]
	cpush al
	pop bx
	pop dx
	cmp dx,bx
	je .L33
	push 0
	jmp .L34
.L33:	
	push 1
.L34:	
	pop ax
	cmp ax,word 0
	je .L35
	sub sp,word 0
	inc word [bp+_count]
	push word [bp+_count]
	pop ax
	jmp .L32
.L35:	
	sub sp,word 0
	push 0
	pop ax
	mov [bp+_count],ax
	push ax
	pop ax
.L32:	
	inc word [bp+_j]
	push word [bp+_j]
	pop ax
	jmp .L29
.L28:	
	push word [bp+_count]
	push word [bp+_str]
	call _strlen
	add sp,word 2
	push ax
	pop bx
	pop dx
	cmp dx,bx
	je .L37
	push 0
	jmp .L38
.L37:	
	push 1
.L38:	
	pop ax
	cmp ax,word 0
	je .L39
	sub sp,word 0
	jmp .L24
	jmp .L36
.L39:	
.L36:	
	inc word [bp+_ptr]
	push word [bp+_ptr]
	pop ax
	inc word [bp+_i]
	push word [bp+_i]
	pop ax
	jmp .L25
.L24:	
	push word [bp+_ptr]
	pop ax
	leave
	ret
%undef _ptr
%undef _i
%undef _j
%undef _count
%undef _buffer
%undef _str



[section .data]

C0: db 'Please enter the output file: ',0
C1: db 13,10,0
C2: db 'Please type a $ to end the program...',13,10,13,10,0
C3: db '%c',0

[section .bss]

answer: resb 20

