Advertisement
HabKaffee

Untitled

Mar 11th, 2021
2,811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. code_seg segment
  2. assume cs:code_seg, ds:code_seg,ss:code_seg
  3. org 100h
  4.  
  5. ;============ macro ====================
  6. EM EQU 13
  7. NL EQU 10
  8. Space EQU 20h
  9.  
  10. print_letter macro letter
  11. push AX
  12. push DX
  13. mov DL, letter
  14. mov AH, 02
  15. int 21h
  16. pop DX
  17. pop AX
  18. endm
  19.  
  20. print_mes macro message
  21. local msg, nxt
  22. push AX
  23. push DX
  24. mov DX, offset msg
  25. mov AH, 09h
  26. int 21h
  27. pop DX
  28. pop AX
  29. jmp nxt
  30. msg DB message,'$'
  31. nxt:
  32. endm
  33.  
  34. ;================ start of program ============
  35. ;================== read files =================
  36. start:
  37. ; read recoder file
  38. mov al, 2 ; open existing file
  39.     mov dx, offset filename
  40.     mov ah, 3dh
  41.     int 21h
  42.     jc error
  43.     mov handle, ax; save descriptor
  44.     jmp cont
  45. error:
  46.     print_mes 'Cannot open Recoder.txt';
  47.     int 20h
  48. cont:
  49.     mov AH,3Fh; read
  50.     mov BX, handle ; descriptor
  51.     mov CX, 52*5; how much to read
  52.     mov DX, offset bufDescr ; read here
  53.     int 21h
  54.     mov CX,AX ; Real readed
  55. ;close Recoder.txt
  56. MOV AH, 3Eh ;
  57. MOV BX, handle
  58. INT 21h
  59. ;=======================================================    
  60. ; read file to recode
  61. print_mes 'Input File Name > '
  62. mov AH, 0Ah
  63. mov DX, offset FileName
  64. int 21h
  65. print_letter EM
  66. print_letter NL
  67. ;===============================================================
  68. xor BH, BH
  69. mov BL, FileName[1]
  70. mov FileName[BX+2], 0
  71. ;===============================================================
  72. mov AX, 3D02h ; Open file for read /write
  73. mov DX, offset FileName+2
  74. int 21h
  75. jnc openOK
  76. print_letter EM
  77. print_letter NL
  78. print_mes 'Cannot open Text.txt'
  79. int 20h
  80. ;===============================================================
  81. openOK:
  82. mov handle, ax
  83. print_letter EM
  84. print_letter NL
  85. print_mes 'Text.txt is opened'
  86. mov AH,3Fh; read
  87. mov BX, handle ; descriptor
  88. mov CX, 80; how much to read
  89. mov DX, offset bufFile ; read here
  90. int 21h
  91. mov CX,AX ; Real readed  
  92. mov readed1, cx; copy readed
  93. ;============= end of reading files ============  
  94. mov AX, 3D02h ; Open file for read /write
  95. mov DX, offset FileOutName
  96. int 21h
  97. mov handleOut,  AX;
  98. jnc openOK1
  99. print_letter EM
  100. print_letter NL
  101. print_mes 'Cannot open TextOut.txt'
  102. int 20h
  103. openOK1:
  104. print_letter EM
  105. print_letter NL
  106.   print_mes 'open TextOut.txt'
  107. ; change Text.txt
  108. mov BX, offset bufOut
  109. cycle:    
  110.     mov SI, offset bufFile
  111. cycle1:
  112.     push CX;
  113.     mov DL, byte ptr [SI]
  114.     mov CX,52*5
  115.     mov DI, offset bufDescr
  116. @:      
  117.     mov DH, byte ptr [DI]
  118.     cmp DL, DH
  119.     je change
  120.     inc DI; go to next symbol in Recoder.txt
  121.     inc DI
  122.     inc DI
  123.     inc DI
  124.     inc DI
  125.      loop @
  126.  change:
  127.     inc DI
  128.     inc DI
  129.     ; change symbol
  130.     mov AL, byte ptr [DI]
  131.     mov byte ptr [BX], AL
  132.     inc BX
  133.     inc SI; go to next symbol in file
  134.     pop CX
  135.      loop cycle1
  136. ;=================================================    
  137. @cont:
  138. MOV AH, 40h ; Write in file function
  139. MOV BX, handleOut ; descriptor
  140. MOV CX, readed1 ; Number of writed bytes
  141. MOV DX, OFFSET bufOut ; Buffer adress
  142. INT 21h
  143. ; close files
  144. MOV AH, 3Eh ;
  145. MOV BX, handle
  146. INT 21h
  147. mov AH,3Eh
  148. mov BX, handleOut
  149. int 21h
  150.  
  151. ;================ end of program ==============
  152. print_letter EM
  153. print_letter NL
  154. print_mes 'Program completed'
  155.  
  156. ;output buffers after program
  157. print_letter EM
  158. print_letter NL
  159.  
  160. print_letter EM
  161. print_letter NL
  162. mov AH, 09h
  163. mov DX, offset bufFile
  164. int 21h
  165. print_letter EM
  166. print_letter NL
  167. mov AH, 09h
  168. mov DX, offset bufout
  169. int 21h
  170.  
  171. mov AX, 4c00h; exit function
  172. int 21h    
  173. ;===================== data ====================
  174. bufDescr db 52*5 dup (' '),'$';
  175. bufFile  db 80 dup (' ');
  176. DB '$'
  177. BufLen EQU $ - bufFile
  178. bufout  db 80 dup (' ');
  179. BufLenOut EQU $ - bufOut
  180. DB '$'
  181. readed1 dw ?
  182. FileOut db "TextOut.txt",0
  183. File db 14,0,14 dup (0)
  184. filename db "Recoder.txt", 0
  185. FileOutName DB 'TextOut.txt',0
  186. handleOut dw ?
  187. handle dw ?
  188. code_seg ends
  189. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement