Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small  
  2. .stack 100h
  3. .data
  4.  
  5. count dw 0
  6.  
  7. data_length dw $-data             ; know size of data
  8.  
  9. .code
  10. old_interrupter dd 0              ;adress of old
  11.  
  12. Check_brackets proc far
  13.  
  14.     cli                           ;dont allow interrupt
  15.     pushf                          
  16.     push ax                      
  17.     in al, 21h                    ;read mask of master
  18.     and al, 10111111b             ;allow interrupts of keybord
  19.                                   ;7-reserve, 6-send scan code from keybord without changing
  20.                                   ;5-work of mouse doesnt allow 4- work of keybord doesnt allow
  21.                                   ;3-reserve, 2- value for register of states; 1-0-allow int from moue and keyb
  22.    
  23.     out 21h, al                   ;write mask of master
  24.     pop ax
  25.     call dword ptr cs:[old_interrupter]   ;call old handler
  26.     pusha                        
  27.  
  28.     push ds
  29.     push es
  30.    
  31.     mov ax, @data
  32.     mov es, ax
  33.     mov ax, 0B800h
  34.     mov ds, ax
  35.        
  36.     xor si, si
  37.      
  38. Drawing:                            ; draw all info in white colour
  39.     cmp si, 4000                    ; if it's end of videobuffer, then we go check brackets
  40.     je end_of_buffer                
  41.                                     ;the first byte -askii, the second- attribute
  42.     inc si
  43.  
  44.     mov al, ds:[si]            
  45.     cmp al, 4                       ; red colour
  46.     je red_colour  
  47.    
  48.    
  49. after_drawing:    
  50.     inc si                          ;after that we'll stay on symbol
  51.     jmp Drawing
  52.    
  53. red_colour:
  54.  
  55.     mov ds:[si], 7                  ; draw in white colour
  56.     jmp after_drawing  
  57.  
  58. end_of_buffer:
  59.  
  60.     xor si, si                  
  61.    
  62. checking:
  63.     cmp si, 4000                
  64.     je draw_brackets            
  65.  
  66.     mov al, ds:[si]                 ; symbol from current position
  67.  
  68.     cmp al, '('
  69.     je opening_ordinary_bracket
  70.  
  71.     cmp al, '{'
  72.     je opening_figure_bracket
  73.  
  74.     cmp al, '['
  75.     je opening_square_bracket
  76.  
  77.     cmp al, ')'
  78.     je closimg_bracket
  79.  
  80.     cmp al, '}'
  81.     je closimg_bracket
  82.  
  83.     cmp al, ']'
  84.     je closimg_bracket
  85.  
  86. after_addition_and_checking:
  87.    
  88.     inc si                          ; stand on next symbol    
  89.     inc si
  90.     jmp checking
  91.  
  92. opening_ordinary_bracket:
  93.    
  94.     push si                         ; remember the position (coordinate)
  95.     mov al, ')'                     ; add to stack needing closing bracket
  96.     push ax                         ; remember the bracket
  97.    
  98.     mov bx, count              
  99.     inc bx                          ; improve counter of numbers in stack
  100.     mov count, bx              
  101.  
  102.     jmp after_addition_and_checking
  103.  
  104. opening_figure_bracket:
  105.    
  106.     push si                    
  107.     mov al, '}'
  108.     push ax                    
  109.    
  110.     mov bx, count            
  111.     inc bx                      
  112.     mov count, bx            
  113.  
  114.     jmp after_addition_and_checking  
  115.  
  116. opening_square_bracket:
  117.    
  118.     push si                      
  119.     mov al, ']'
  120.     push ax                      
  121.    
  122.     mov bx, count            
  123.     inc bx                      
  124.     mov count, bx              
  125.  
  126.     jmp after_addition_and_checking    
  127.  
  128. closimg_bracket:
  129.  
  130.     mov bx, count              
  131.     cmp bx, 0                       ; check amount of brackets
  132.     je draw_closing_bracket         ; if count = 0, stack is empty =>draw all closing brackets
  133.  
  134.     pop bx                          ; get last bracket
  135.     cmp bl, al                    
  136.     jne not_equal_brackets          ; if they don't equal,then go
  137.  
  138.     mov bx, count            
  139.     dec bx                          ; reduce count
  140.     mov count, bx              
  141.  
  142.     pop bx                          ;delete coordinate from stack
  143.  
  144.     jmp after_addition_and_checking
  145.  
  146. not_equal_brackets:
  147.                                     ;check situation like (]) -wrong brackets
  148.     push bx                         ; return symbol in stack
  149.  
  150.     inc si                      
  151.     mov ds:[si], 4                  ;  change colour of bracket
  152.     dec si                      
  153.     push si                         ; remember current coordinate of bracket
  154.  
  155.     cmp al, ')'                     ; if it's not closing ordinary bracket
  156.     jne other_brackets              ;  we need to change askicode of figure or square closing bracket to opening '}' - 2='{'-it's askicode
  157.  
  158.     sub al, 1                       ; change ordinary closing bracket to opening bracket ')' - 1 = '('
  159.     jmp add_to_stack                     
  160.  
  161. other_brackets:
  162.  
  163.     sub al, 2                       ; change aski of not ordinary closing bracket ']' - 2 = '['
  164.  
  165. add_to_stack:
  166.  
  167.     push ax                         ; remember symbol of this bracket
  168.  
  169.     mov bx, count              
  170.     inc bx                          ; improve counter
  171.     mov count, bx              
  172.  
  173.     jmp after_addition_and_checking
  174.  
  175. draw_closing_bracket:
  176.  
  177.     inc si                      
  178.     mov ds:[si], 4                  ; change colour
  179.     dec si                        
  180.  
  181.     jmp after_addition_and_checking
  182.  
  183. draw_brackets:
  184.    
  185.     mov bx, count
  186.  
  187. draw_brackets_in_red:
  188.  
  189.     cmp bx, 0
  190.     je end_check_brackets
  191.                                     ;()       ;1)     ;count=2
  192.     pop si                          ; get coordinate of wrong bracket
  193.     pop si                          ; and bracket too
  194.  
  195.     inc si                          ; stay on attribute
  196.     mov ds:[si], 4            
  197.  
  198.     dec bx
  199.  
  200.     jmp draw_brackets_in_red
  201.  
  202. end_check_brackets:
  203.    
  204.     mov count, bx
  205.  
  206.     pop es
  207.     pop ds
  208.  
  209.     popa  
  210.     sti                          
  211.     iret                        
  212.                                     ;in the begining? get IP from stack, after that CS and register of flags
  213.  
  214. Check_brackets endp
  215.  
  216. main:
  217.  
  218.     mov ax, @data
  219.     mov ds, ax
  220.    
  221.     mov ah, 35h                                 ;read vector of interrupt
  222.     mov al, 09h
  223.     int 21h                                     ;in ES:BX -adress of handler interrupt
  224.     mov word ptr cs:[old_interrupter], bx       ;remember our handler; bx-offset of handler
  225.     mov word ptr cs:[old_interrupter+2], es     ;segment laof handler
  226.     mov ah, 25h                                 ;install new handler
  227.     mov al, 09h                    
  228.     push cs                                     ;install new handler 09h
  229.     pop ds                                      ;move in DS CS (prepare segment of adree for new handler)
  230.     mov dx, offset Check_brackets    
  231.     int 21h                                     ;DS:DX - adree of new handler
  232.    
  233.     mov ah, 31h                                 ;do this program like a resident program
  234.     mov al, 00h                    
  235.     mov dx, (program_length / 16) + (data_length / 16) + 16 + 16 + 2
  236.                                                 ;size in 16bytes segments: size of code+ data+ size of stack+ size of psp + 1
  237.                                                 ;bye for program_lenght and data_lenght
  238.     int 21h
  239.    
  240. program_length dw $-code                        ;size of code
  241. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement