Advertisement
qberik

Untitled

Dec 9th, 2022
3,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. mReplaceString macro s, len
  3.  
  4.   push ax
  5.   push bx
  6.   push cx
  7.   push dx
  8.   push di
  9.   push si
  10.   push bp
  11.  
  12.   mov di, offset s ; откуда начать
  13.   mov bp, offset s ; где закончить
  14.   add bp, len
  15.  
  16.   mov al, 13 ; перевод строки
  17.   mov cx, 0 ; подсчёт линий
  18.  
  19. _search_new_line:
  20.  
  21.   cld
  22.   scasb
  23.   pushf
  24.  
  25.   cmp di, bp ; конец тексте
  26.   ; считаем, что типа конец строки найден
  27.   jge _new_line_found_end_text
  28.  
  29.   popf
  30.   jnz _search_new_line
  31.  
  32.   jmp _new_line_found
  33.  
  34. _new_line_found_end_text:
  35.   inc di
  36.   popf
  37. _new_line_found:
  38.  
  39.   mov dx, cx
  40.   and dx, 1 ; проверка на нечётность
  41.   cmp dx, 1
  42.   pushf
  43.   ; в нечётном числе последний бит 1
  44.   inc cx; увеличиваем счётчик пройденйх линий
  45.   popf
  46.   jne _skip_line
  47.  
  48.   push ax
  49.   push bx
  50.   push cx
  51.   push dx
  52.   push di
  53.  
  54.   dec di
  55.  
  56.   xor ax, ax
  57.   xor bx, bx
  58.   xor cx, cx
  59.   xor dx, dx
  60.   ; si - начало строки
  61.   ; di - конец строки
  62.  
  63.   mov al, ' ' ; разбмение по символу пробела
  64.   mov ah, '!' ; заменяем символом восклицательного знака
  65.   mov cx, si ;начало слова
  66.   mov bx, si ;конец слова
  67.   ;mov dx, di ;конец строки
  68.  
  69.   jmp _search_for_space
  70. _next_letter:
  71.   inc bx
  72. _search_for_space:
  73.  
  74.   cmp al, [bx]
  75.   je _space_found
  76.   pushf
  77.  
  78.   cmp bx, di
  79.   jge _space_found_end_line
  80.   ; конец строки
  81.  
  82.   popf
  83.   jmp _next_letter
  84. _space_found_end_line:
  85.   popf
  86. _space_found:
  87.  
  88.   cmp bx, cx
  89.   je _no_word
  90.  
  91.   mov dx, bx ; конец слова
  92.   sub dx, cx ; минус начало
  93.  
  94.   push dx
  95.   and dx, 1; нечётная длинна слова
  96.   cmp dx, 1
  97.   pop dx
  98.  
  99.   jne _skip_replace
  100.  
  101.     push bx
  102.  
  103.     shr dx, 1
  104.     mov bx, cx
  105.     add bx, dx
  106.  
  107.     mov [bx], ah
  108.  
  109.     pop bx
  110.  
  111. _skip_replace:
  112. _no_word:
  113.  
  114.   cmp bx, di
  115.   jge _end_line
  116.  
  117.   inc bx
  118.   mov cx, bx
  119.  
  120.   jmp _search_for_space
  121.  
  122. _end_line:
  123.  
  124.   pop di
  125.   pop dx
  126.   pop cx
  127.   pop bx
  128.   pop ax
  129.  
  130. _skip_line:
  131.  
  132.   cmp di, bp ; конец тексте
  133.   jge _stop
  134.  
  135.   inc di ; был на 10 стал на новой строке
  136.   mov si, di
  137.  
  138.   jmp _search_new_line
  139.  
  140. _stop:
  141.   pop bp
  142.   pop si
  143.   pop di
  144.   pop dx
  145.   pop cx
  146.   pop bx
  147.   pop ax
  148. endm mReplaceString
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement