Advertisement
Neveles

Untitled

Dec 18th, 2019
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DOSSEG
  2. .MODEL TINY
  3. .STACK 100h
  4. .DATA
  5. inputFile DB 'input.txt',0
  6. outputFile DB 'output.txt',0    
  7. error DB 'Error unable to open file.',0
  8. text DB 2000 DUP('$')
  9. buffer DB '2', '$'
  10. .CODE
  11. .386
  12.  
  13. file_write macro str
  14.  mov ah, 40h
  15.  push bx
  16.  mov bx, di
  17.  mov cx, 1
  18.  lea si, buffer
  19.  mov [si], str
  20.  mov dx, si
  21.  int 21h  
  22.  pop bx  
  23. endm
  24.  
  25. start:
  26. mov ax, @Data
  27. mov ds, ax
  28. mov es, ax
  29.  
  30. ; opening file
  31. mov ah, 3Dh
  32. mov al, 0
  33. lea dx, inputFile
  34. int 21h
  35. jc error_no_file
  36.    
  37. mov si, ax        
  38.  
  39. ; reading
  40. lea dx, text
  41.  
  42. reading_file:
  43.  mov ah, 3Fh
  44.  mov bx, si
  45.  mov cx, 1
  46.  int 21h  
  47.  inc dx  
  48.  cmp ax, 1        
  49.  je reading_file
  50.  
  51. ; closing inputfile
  52.  mov ah, 3Eh
  53.  mov bx, si
  54.  int 21h    
  55.  
  56. ; creating new file
  57. mov al, 1h
  58. mov ah, 3Ch
  59. mov cx, 0
  60. lea dx, outputFile
  61. int 21h
  62. mov di, ax
  63.  
  64. ; main part
  65. mov cx, 0
  66. mov bx, OFFSET text
  67. mov dx, bx
  68.  
  69. iter:
  70.  cmp cx, 0
  71.  je met
  72.  add bx, 1
  73.  met:
  74.   mov cx, 1
  75.  mov al, [bx]  
  76.  cmp al, 40h    
  77.  jbe nextword      
  78.  cmp al, 4Dh  
  79.  jbe print        
  80.  cmp al, 60h  
  81.  jbe nextword
  82.  cmp al, 6Dh      
  83.  jbe print
  84.  jmp nextword
  85.  
  86. print:
  87.  mov ah, 2
  88.  mov dl, al
  89.  int 21h  
  90.  file_write al    
  91.  cmp al, 20h
  92.  jz iter
  93.  
  94. znaki:      
  95.  cmp [bx + 1], ah
  96.  jz printspace
  97.  add ah, 1
  98.  cmp ah, 30h
  99.  jbe znaki
  100.  add bx, 1
  101.  mov al, [bx]
  102.  cmp al, 13
  103.  jz cancel
  104.  jmp print
  105.  
  106. nextword:
  107.  cmp al, 20h
  108.  jz iter
  109.  add bx, 1
  110.  mov al, [bx]
  111.  cmp al, 13
  112.  jz cancel
  113.  jmp nextword
  114.  
  115. printspace:
  116.  mov ah, 2
  117.  mov dl, 20h
  118.  int 21h
  119.  file_write 20h
  120.  jmp iter
  121.  
  122. cancel:
  123.  mov ah, 2
  124.  mov dl, 10
  125.  int 21h
  126. ; closing outputFile
  127.  mov ah, 3Eh
  128.  mov bx, di
  129.  int 21h    
  130.  mov ah, 4ch
  131.  int 21h
  132.  
  133. error_no_file:  
  134.  lea dx, error
  135.  mov ah, 9h
  136.  int 21h
  137.  mov ah, 4ch
  138.  int 21h
  139.  
  140. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement