Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- code_seg segment
- ASSUME CS:CODE_SEG,DS:code_seg,ES:code_seg
- org 100h
- start:
- jmp begin
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; macro;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- get_vector macro vector, DD_for_save_vector
- mov AX,35&vector ; получить вектор прерывания
- int 21h ;
- mov word ptr DD_for_save_vector, BX ; ES:BX - вектор
- mov word ptr DD_for_save_vector+2, ES ;
- endm
- ;
- set_vector macro vector, handler
- mov DX,offset handler ; получить смещение точки входа в новый
- ; ; обработчик на DX
- mov AX,25&vector ; функция установки прерывания
- ; ; изменить вектор
- int 21h ; AL - номер прерыв.
- ; DS:DX - указатель программы обработки прер.
- endm
- ;
- recovery_vector macro vector, DD_for_save_vector
- push DS
- lds DX, CS:DD_for_save_vector
- mov AX, 25&vector ; Заполнение вектора старым содержимым
- int 21h
- pop DS ; DS:DX - указатель программы обработки прер.
- endm
- ;
- start_time macro saved_vector_1Ch, count
- local nxt, new_1Ch
- get_vector 1Ch, saved_vector_1Ch
- set_vector 1Ch, new_1Ch
- ;
- jmp nxt
- new_1Ch proc far
- pushf
- inc CS:count
- popf
- jmp dword ptr CS: [saved_vector_1Ch]
- new_1Ch endp
- nxt:
- ;
- endm
- ;
- finish_time macro saved_vector, count
- local nxt, old_1Ch,new_1Ch
- ;
- recovery_vector 1Ch, saved_vector
- Print_Word_hex count
- ;
- endm
- ;
- ;
- Print_Word_hex macro src ; выводит на экран источник src в hex виде
- local next, print_DL, print_hex, print_, msg
- CR EQU 13
- LF EQU 10
- push AX
- push BX
- push CX
- push DX
- ;
- mov DX,offset msg ; CR+LF
- mov AH, 09h
- int 21h
- ;
- mov BX, src
- mov AH,02
- mov DL,BH
- ;rcr DL,4
- call print_DL
- ;mov DL,BH
- ;call print_hex
- ;
- mov DL,BL
- ;rcr DL,4
- call print_DL
- ;mov DL,BL
- ;call print_hex
- ;
- pop DX
- pop CX
- pop BX
- pop AX
- jmp next
- ;
- ;
- print_DL proc near
- push DX
- rcr DL,4
- call print_hex
- ;mov DL,BH
- pop DX
- call print_hex
- ret
- print_DL endp
- ;
- print_hex proc near
- and DL, 0Fh
- add DL, 30h
- cmp DL, 3Ah
- jl print_
- add DL, 07h
- print_:
- int 21H
- ret
- print_hex endp
- ;
- msg DB CR,LF,'runtime:','$'
- next:
- endm
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;
- old_1Ch DD ?
- old_08h DD ?
- time_count DW ?
- count_ DW ?
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;
- count1 DW ?
- msg DB 'Hello world!!!!!!!!!!!',13,10,'$'
- msg1 DB ' ',13,10,'$'
- Filename DB "D:\myf.txt",0
- buf db 30000 dup (' ')
- maxlen dw 30000
- BufIn db 256 dup (' ')
- count db 00
- count2 db 00
- schet db 00
- finish db 00
- deskrd dw 00
- deskwr dw 00
- adres db 00
- flag db 00
- sobk db 00
- handl dw 00
- curlength dw 00
- index dw 00
- flagfile db 00
- begin:
- start_time old_1Ch, time_count
- ;-----Открытие файла
- mov AX, 3D00h
- lea dx,Filename ; DS:dx указатель на имя файла
- int 21h ; в ax деcкриптор файла
- mov handl, AX ; если поднят флаг С, то ошибка открытия
- ;--------------------
- mov bx,ax ; копируем в bx указатель файла
- xor cx,cx
- xor dx,dx
- mov ax,4200h
- int 21h
- mov DI, offset BufIn
- out_str:
- cmp flagfile, 01
- je close
- mov ah,3fh ;будем читать из файла
- mov cx,maxlen ;30000 байт
- mov BX,handl
- lea dx,buf ;в память buf
- int 21h
- mov index, 0
- mov curlength, AX
- lea BX,buf
- cmp ax,maxlen ;если достигнуть EoF или ошибка чтения
- je skip ;то закрываем файл закрываем файл
- inc flagfile
- skip:
- mov dl, [BX+2]
- cmp dl, 40h
- jne awas
- inc sobk
- awas:
- cmp dl, 20h ;сравниваем со знаками ограничителями
- je empty
- cmp dl, 3Bh
- je empty
- cmp dl, 0Dh
- je empty
- cmp dl, 2Ch
- je empty
- cmp dl, 0Ah
- je empty
- mov byte ptr[DI], dl ;записываем символ считанный из файла, по адресу DI
- inc di ;прибаляем к адресу 1
- inc count
- top:
- inc index
- inc BX
- mov CX, index
- cmp CX, curlength
- je out_str
- jmp skip
- ;-------------------Проверка на пустую строку в BufIn или вывод строки
- close: ; закрываем файл, после чтения
- inc finish
- mov ah,3eh
- int 21h
- exit:
- call empty
- there:
- jmp myend
- empty:
- cmp finish, 00
- je here
- cmp count, 00
- je there
- cmp sobk, 01
- jne there
- here:
- cmp count, 00
- jne plus
- jmp top
- plus:
- push AX
- push DX
- mov DL, '$'
- mov byte ptr[DI], dl
- mov flag, 0
- mov schet, 0
- mov count2, 0
- jmp proverka
- metka:
- cmp count2, 00h
- je wrong
- mov ah, 09h
- mov DX, offset BufIn
- int 21h
- mov ah, 2h
- mov dl, 0Ah
- int 21h
- mov dl, 0Dh
- int 21h
- wrong:
- mov DI, offset BufIn
- mov count, 00
- mov sobk,00
- pop DX
- pop AX
- cmp finish, 00
- jne kk1
- jmp out_str
- kk1:
- ret
- ;------------------------------------------------------------------------------
- proverka:
- nachalo:
- mov DI, offset BufIn
- beforeA:
- mov DL, byte ptr[DI]
- cmp sobk, 1
- jne flagok1
- cmp DL, 27h
- jL flagok1
- vozvrat1:
- cmp DL, 0E0h
- jL gran1
- cmp DL, 3Ah
- je flagok1
- cmp DL, 3Ch
- je flagok1
- cmp DL, 3Dh
- je flagok1
- cmp DL, 3Eh
- je flagok1
- cmp DL, 3Fh
- je flagok1
- cmp DL, 7Ah
- jG flagok1
- cmp DL, 2Ah
- je flagok1
- cmp DL, 2Fh
- je flagok1
- cmp DL, 5Ch
- je flagok1
- cmp DL, 5Dh
- je flagok1
- cmp DL, 5Eh
- je flagok1
- cmp DL, 60h
- je flagok1
- cmp DL, 7Bh
- je flagok1
- cmp DL, 7Ch
- je flagok1
- cmp DL, 7Dh
- je flagok1
- cmp DL, 7Eh
- je flagok1
- cmp DL, 7Fh
- je flagok1
- cmp DL, 40h
- je afterA
- cmp DL, '$'
- jne kk2
- jmp wrong
- kk2:
- inc DI
- jmp beforeA
- gran1: cmp DL, 0AFh
- jG flagok1
- jmp vozvrat1
- flagok1:jmp wrong
- afterA:
- inc DI
- mov DL, byte ptr[DI]
- cmp DL, '$'
- jne kk3
- jmp metka
- kk3:
- cmp DL, 2Eh
- jne tron
- cmp count2, 02h
- je flagok2
- inc count2
- cmp schet, 00
- je flagok2
- mov schet, 00
- jmp tron1
- tron:
- inc schet
- cmp DL, 27h
- jl flagok2
- cmp DL, 28h
- je flagok2
- cmp DL, 29h
- je flagok2
- cmp DL, 2Ah
- je flagok2
- cmp DL, 2Fh
- je flagok2
- cmp DL, 3Ah
- je flagok2
- cmp DL, 3Ch
- je flagok2
- cmp DL, 3Dh
- je flagok2
- cmp DL, 3Eh
- je flagok2
- cmp DL, 3Fh
- je flagok2
- cmp DL, 5Bh
- je flagok2
- cmp DL, 5Ch
- je flagok2
- cmp DL, 5Dh
- je flagok2
- cmp DL, 5Eh
- je flagok2
- cmp DL, 60h
- je flagok2
- cmp DL, 7Ah
- jg flagok2
- cmp DL, 40h
- je flagok2
- tron1:
- jmp afterA
- flagok2: jmp wrong
- myend:
- finish_time old_1Ch, time_count
- ;
- ;
- int 20h
- ;============================================================================
- ;
- ;;============================================================================
- code_seg ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement