.model small
.stack 256
.data
msg0 db 13,10,'Enter number: $'
b1 db 'b1.txt',0
sizeB dw 0
hndl2 dw 0
hndl3 dw 0
hndl4 dw 0
var dw 0
bufer db 80 DUP (?)
.code
assume ds:@data, es:@data, cs:@code
start:
mov ax,@data
mov ds,ax
mov es,ax
;\
; >-----\/----- enter the keyboard -----\/-----
;/
mov ah, 9 ;
int 21h ;
mov di, offset bufer ;
xor bx, bx ;
;
level1: ;
mov cx, 4 ;
mov ah, 1 ; ;
@@: ; cykl vvodu 4 symboliv
int 21h ;
cmp al, 13 ;
je level2 ;
stosb ;
inc bx ;
loop @@ ;
;
mov ah, 2 ;
mov dl, ' ' ; pislya 4 symboliv stavum propusk
int 21h ;
stosb ;
inc bx ;
jmp level1 ; i prodovzhuem vvid z klaviatury
;\
; >-----\/----- create file, compare number -----\/-----
;/
level2:
push bx ;
mov [sizeB], bx ;
mov dx, offset b1 ;
;
call createFile ;
pop cx ;
mov bx,ax ;
mov dx, offset bufer ;
;
call writeFile ;
call closeFile ;
;-----------------------------
mov cx, 3 ;
mov bp, hndl2 ;
@1: ;
inc Byte Ptr [b1+1] ;
mov dx, offset b1 ;
call createFile ;
cmp cx, 3
je hd2
cmp cx, 2
je hd3
cmp cx, 1
je hd4
loop @1 ;
;
;-------------------------- ;
@5:
mov cx, [sizeB] ;
shr cx, 2 ;
mov di, offset bufer ;
;
begin: ;
push cx ;
call FindNull ;
mov var, bx ;
cmp bx, 1 ;
jnz file3 ;
mov bx, hndl2 ;
jmp ok ;
;
file3: ;
cmp bx, 2 ;
jnz file4 ;
mov bx, hndl3 ;
jmp ok ;
;
file4: ;
cmp bx, 3 ;
jnz error ;
mov bx, hndl4 ;
ok: ;
mov cx, 5 ;
mov dx, di ;
sub dx, cx ;
call writeFile ;
error: ;
pop cx ;
loop begin ;
;
;---------------------------;-----------
;
mov cx, 3 ;
mov ax, offset hndl2 ;
@3: ;
mov bx, ax ;
call CloseFile ;
add ax, 2 ;
loop @3 ;
;
jmp exit ;
;
;------------------PROCEDURE;---------------
;
createFile: ;
push cx ;
mov ah, 3ch ;
mov cx, 20h ;
int 21h ;
pop cx ;
ret ;
;
writeFile: ;
push cx ;
mov ah, 40h ;
int 21h ;
pop cx ;
ret ;
;
closeFile: ;
mov ah, 3eh ;
int 21h ;
ret ;
;
FindNull: ;
mov cx, 5 ;
xor bx, bx ;
mov al, '0' ;
@2: ;
repne scasb ;
jcxz endpro ;
inc bx ;
jmp @2 ;
endpro:
ret
;-----------------------------
hd2:
mov hndl2, ax
dec cx
jmp @1
ret
hd3:
mov hndl3, ax ;\
dec cx ; > Write HANDLE
jmp @1 ;/
ret
hd4:
mov hndl4, ax
dec cx
jmp @5
ret
;--------------------------------
exit: ;
xor ax,ax ;
int 16h ;
int 20h ;
;
end start ;