Advertisement
Klenkov

Untitled

Mar 18th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. code_seg segment
  2. ASSUME CS:CODE_SEG,DS:code_seg,ES:code_seg
  3. org 100h
  4. start:
  5. jmp begin
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; macro;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7. get_vector macro vector, DD_for_save_vector
  8. mov AX,35&vector ; получить вектор прерывания
  9. int 21h ;
  10. mov word ptr DD_for_save_vector, BX ; ES:BX - вектор
  11. mov word ptr DD_for_save_vector+2, ES ;
  12. endm
  13. ;
  14. set_vector macro vector, handler
  15. mov DX,offset handler ; получить смещение точки входа в новый
  16. ; ; обработчик на DX
  17. mov AX,25&vector ; функция установки прерывания
  18. ; ; изменить вектор
  19. int 21h ; AL - номер прерыв.
  20. ; DS:DX - указатель программы обработки прер.
  21. endm
  22. ;
  23. recovery_vector macro vector, DD_for_save_vector
  24. push DS
  25. lds DX, CS:DD_for_save_vector
  26. mov AX, 25&vector ; Заполнение вектора старым содержимым
  27. int 21h
  28. pop DS ; DS:DX - указатель программы обработки прер.
  29. endm
  30. ;
  31. start_time macro saved_vector_1Ch, count
  32. local nxt, new_1Ch
  33. get_vector 1Ch, saved_vector_1Ch
  34. set_vector 1Ch, new_1Ch
  35. ;
  36. jmp nxt
  37. new_1Ch proc far
  38. pushf
  39. inc CS:count
  40. popf
  41. jmp dword ptr CS: [saved_vector_1Ch]
  42. new_1Ch endp
  43. nxt:
  44. ;
  45. endm
  46. ;
  47. finish_time macro saved_vector, count
  48. local nxt, old_1Ch,new_1Ch
  49. ;
  50. recovery_vector 1Ch, saved_vector
  51. Print_Word_hex count
  52. ;
  53. endm
  54. ;
  55. ;
  56. Print_Word_hex macro src ; выводит на экран источник src в hex виде
  57. local next, print_DL, print_hex, print_, msg
  58. CR EQU 13
  59. LF EQU 10
  60. push AX
  61. push BX
  62. push CX
  63. push DX
  64. ;
  65. mov DX,offset msg ; CR+LF
  66. mov AH, 09h
  67. int 21h
  68. ;
  69. mov BX, src
  70. mov AH,02
  71. mov DL,BH
  72. ;rcr DL,4
  73. call print_DL
  74. ;mov DL,BH
  75. ;call print_hex
  76. ;
  77. mov DL,BL
  78. ;rcr DL,4
  79. call print_DL
  80. ;mov DL,BL
  81. ;call print_hex
  82. ;
  83. pop DX
  84. pop CX
  85. pop BX
  86. pop AX
  87. jmp next
  88. ;
  89. ;
  90. print_DL proc near
  91. push DX
  92. rcr DL,4
  93. call print_hex
  94. ;mov DL,BH
  95. pop DX
  96. call print_hex
  97. ret
  98. print_DL endp
  99. ;
  100. print_hex proc near
  101. and DL, 0Fh
  102. add DL, 30h
  103. cmp DL, 3Ah
  104. jl print_
  105. add DL, 07h
  106. print_:
  107. int 21H
  108. ret
  109. print_hex endp
  110. ;
  111. msg DB CR,LF,'runtime:','$'
  112. next:
  113. endm
  114. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  115. ;
  116. old_1Ch DD ?
  117. old_08h DD ?
  118. time_count DW ?
  119. count_ DW ?
  120. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  121. ;
  122. count1 DW ?
  123. msg DB 'Hello world!!!!!!!!!!!',13,10,'$'
  124. msg1 DB ' ',13,10,'$'
  125. Filename DB "D:\myf.txt",0
  126. buf db 30000 dup (' ')
  127. maxlen dw 30000
  128. BufIn db 256 dup (' ')
  129. count db 00
  130. count2 db 00
  131. schet db 00
  132. finish db 00
  133. deskrd dw 00
  134. deskwr dw 00
  135. adres db 00
  136. flag db 00
  137. sobk db 00
  138. handl dw 00
  139. curlength dw 00
  140. index dw 00
  141. flagfile db 00
  142. begin:
  143. start_time old_1Ch, time_count
  144. ;-----Открытие файла
  145. mov AX, 3D00h
  146. lea dx,Filename ; DS:dx указатель на имя файла
  147. int 21h ; в ax деcкриптор файла
  148. mov handl, AX ; если поднят флаг С, то ошибка открытия
  149. ;--------------------
  150. mov bx,ax ; копируем в bx указатель файла
  151. xor cx,cx
  152. xor dx,dx
  153. mov ax,4200h
  154. int 21h
  155.  
  156. mov DI, offset BufIn
  157. out_str:
  158. cmp flagfile, 01
  159. je close
  160. mov ah,3fh ;будем читать из файла
  161. mov cx,maxlen ;30000 байт
  162. mov BX,handl
  163. lea dx,buf ;в память buf
  164. int 21h
  165. mov index, 0
  166. mov curlength, AX
  167. lea BX,buf
  168. cmp ax,maxlen ;если достигнуть EoF или ошибка чтения
  169. je skip ;то закрываем файл закрываем файл
  170. inc flagfile
  171. skip:
  172. mov dl, [BX+2]
  173. cmp dl, 40h
  174. jne awas
  175. inc sobk
  176. awas:
  177. cmp dl, 20h ;сравниваем со знаками ограничителями
  178. je empty
  179. cmp dl, 3Bh
  180. je empty
  181. cmp dl, 0Dh
  182. je empty
  183. cmp dl, 2Ch
  184. je empty
  185. cmp dl, 0Ah
  186. je empty
  187. mov byte ptr[DI], dl ;записываем символ считанный из файла, по адресу DI
  188. inc di ;прибаляем к адресу 1
  189. inc count
  190. top:
  191. inc index
  192. inc BX
  193. mov CX, index
  194. cmp CX, curlength
  195. je out_str
  196. jmp skip
  197. ;-------------------Проверка на пустую строку в BufIn или вывод строки
  198. close: ; закрываем файл, после чтения
  199. inc finish
  200. mov ah,3eh
  201. int 21h
  202.  
  203. exit:
  204. call empty
  205. there:
  206. jmp myend
  207.  
  208. empty:
  209. cmp finish, 00
  210. je here
  211. cmp count, 00
  212. je there
  213. cmp sobk, 01
  214. jne there
  215. here:
  216. cmp count, 00
  217. jne plus
  218. jmp top
  219. plus:
  220. push AX
  221. push DX
  222. mov DL, '$'
  223. mov byte ptr[DI], dl
  224. mov flag, 0
  225. mov schet, 0
  226. mov count2, 0
  227. jmp proverka
  228. metka:
  229. cmp count2, 00h
  230. je wrong
  231. mov ah, 09h
  232. mov DX, offset BufIn
  233. int 21h
  234. mov ah, 2h
  235. mov dl, 0Ah
  236. int 21h
  237. mov dl, 0Dh
  238. int 21h
  239. wrong:
  240. mov DI, offset BufIn
  241. mov count, 00
  242. mov sobk,00
  243. pop DX
  244. pop AX
  245. cmp finish, 00
  246. jne kk1
  247. jmp out_str
  248. kk1:
  249. ret
  250. ;------------------------------------------------------------------------------
  251. proverka:
  252. nachalo:
  253. mov DI, offset BufIn
  254. beforeA:
  255. mov DL, byte ptr[DI]
  256. cmp sobk, 1
  257. jne flagok1
  258. cmp DL, 27h
  259. jL flagok1
  260. vozvrat1:
  261. cmp DL, 0E0h
  262. jL gran1
  263. cmp DL, 3Ah
  264. je flagok1
  265. cmp DL, 3Ch
  266. je flagok1
  267. cmp DL, 3Dh
  268. je flagok1
  269. cmp DL, 3Eh
  270. je flagok1
  271. cmp DL, 3Fh
  272. je flagok1
  273. cmp DL, 7Ah
  274. jG flagok1
  275. cmp DL, 2Ah
  276. je flagok1
  277. cmp DL, 2Fh
  278. je flagok1
  279. cmp DL, 5Ch
  280. je flagok1
  281. cmp DL, 5Dh
  282. je flagok1
  283. cmp DL, 5Eh
  284. je flagok1
  285. cmp DL, 60h
  286. je flagok1
  287. cmp DL, 7Bh
  288. je flagok1
  289. cmp DL, 7Ch
  290. je flagok1
  291. cmp DL, 7Dh
  292. je flagok1
  293. cmp DL, 7Eh
  294. je flagok1
  295. cmp DL, 7Fh
  296. je flagok1
  297. cmp DL, 40h
  298. je afterA
  299. cmp DL, '$'
  300. jne kk2
  301. jmp wrong
  302. kk2:
  303. inc DI
  304. jmp beforeA
  305. gran1: cmp DL, 0AFh
  306. jG flagok1
  307. jmp vozvrat1
  308. flagok1:jmp wrong
  309. afterA:
  310. inc DI
  311. mov DL, byte ptr[DI]
  312. cmp DL, '$'
  313. jne kk3
  314. jmp metka
  315. kk3:
  316. cmp DL, 2Eh
  317. jne tron
  318. cmp count2, 02h
  319. je flagok2
  320. inc count2
  321. cmp schet, 00
  322. je flagok2
  323. mov schet, 00
  324. jmp tron1
  325. tron:
  326. inc schet
  327. cmp DL, 27h
  328. jl flagok2
  329. cmp DL, 28h
  330. je flagok2
  331. cmp DL, 29h
  332. je flagok2
  333. cmp DL, 2Ah
  334. je flagok2
  335. cmp DL, 2Fh
  336. je flagok2
  337. cmp DL, 3Ah
  338. je flagok2
  339. cmp DL, 3Ch
  340. je flagok2
  341. cmp DL, 3Dh
  342. je flagok2
  343. cmp DL, 3Eh
  344. je flagok2
  345. cmp DL, 3Fh
  346. je flagok2
  347. cmp DL, 5Bh
  348. je flagok2
  349. cmp DL, 5Ch
  350. je flagok2
  351. cmp DL, 5Dh
  352. je flagok2
  353. cmp DL, 5Eh
  354. je flagok2
  355. cmp DL, 60h
  356. je flagok2
  357. cmp DL, 7Ah
  358. jg flagok2
  359. cmp DL, 40h
  360. je flagok2
  361. tron1:
  362. jmp afterA
  363. flagok2: jmp wrong
  364.  
  365. myend:
  366. finish_time old_1Ch, time_count
  367. ;
  368.  
  369. ;
  370. int 20h
  371. ;============================================================================
  372. ;
  373. ;;============================================================================
  374. code_seg ends
  375. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement