Advertisement
Guest User

Untitled

a guest
Nov 24th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. text segment
  2. assume   CS:text, DS:data    
  3.  
  4.  
  5. search proc                
  6.     mov DI, AX          ; copy string for searching    
  7.     ;add DI, TokenLenght              
  8.     mov Left, DI          
  9.     mov CL, String_Lenght            
  10.     ;sub CX, AX              
  11.     mov BX, AX              
  12.     mov AL, ' '            
  13.     cld                    
  14.     repne scasb             ; search index, that not equal ' '
  15.                             ; DI - index next of last symbol, that
  16.                             ; compare                
  17.     mov AX, DI              
  18.     mov Right, AX        
  19.     ret                    
  20. search endp                  
  21.  
  22. missspace proc              
  23.     mov DI, AX              ; offset of string
  24.     mov CL, String_Lenght                
  25.     ;sub CX, AX              ; cause of offset, loop can't
  26.                             ; work more, that why we sub that    
  27.     mov BX, AX              ; save offset                                
  28.     mov AL, ' '                                
  29.     cld                                        
  30.     repe scasb  
  31.     mov AX, DI
  32.     sub AX, Right           ; index of new word - index of last
  33.                             ; word = count of space
  34.     add Spaces_Count, AL    ; save count of space        
  35.     mov SpaceMiss, AX
  36.     mov AX, DI              ; index next of last element, that not
  37.                             ; equal ' '
  38.     ret                              
  39. missspace endp
  40.  
  41.  
  42. ;--------------------------------start-------------------------------------
  43.                  
  44. begin:
  45.     mov AX, data
  46.     mov DS, AX  
  47.    
  48.     ; Create file
  49.     mov AH, 3Ch            ; func create file
  50.     mov CX, 0              ; without attr
  51.     mov DX, offset fname   ; file_name
  52.     int 21h
  53.    
  54.    
  55.     mov handle, AX         ; save handler file
  56.    
  57.     ;write to file
  58.     mov AH, 40h            ; func to write to file
  59.     mov BX, handle         ; file's handler
  60.     mov CX, buflen         ; number of byte, that to write
  61.     mov DX, offset bufout  ;adress of data
  62.     int 21h                              
  63.    
  64.     ;close file
  65.     mov AH, 3Eh            ; func close file
  66.     mov BX, handle         ; handler
  67.     int 21h
  68.    
  69.     ; allocate 160 byte
  70.     mov AH, 48h            ; func allocate
  71.     mov BX, 10h            ; 10 * 16 byte
  72.     int 21h                  
  73.    
  74.     mov allocseg, AX       ;adress of allocated memory
  75.     mov ES, AX
  76.     xor DI, DI
  77.    
  78.     ; open file
  79.     mov AH, 3Dh            ;func open file
  80.     mov AL, 2              ;for read/write
  81.     mov DX, offset fname   ;adress name file
  82.     int 21h
  83.    
  84.     mov handler, AX        ;save handler
  85.    
  86.     ;read file
  87.     mov AH, 3Fh            ;func to read
  88.     mov BX, handler        ;handler file
  89.     mov CX, 200            ;how much to read
  90.     mov DX, allocseg       ;save there
  91.     int 21h    
  92.    
  93.    
  94.     mov CX, AX             ;how much symbols is read
  95.     mov AH, 40h            ;func to show
  96.     mov BX, 1              ;standart handler
  97.     mov DX, allocseg       ;show this
  98.     int 21h      
  99.    
  100.          
  101.     mov AX, data           ; init data segment          
  102.     mov ES, AX  
  103.          
  104.     xor CX, CX
  105.     mov CL, String_Lenght
  106.     lea SI, DX
  107.     lea DI, String
  108.     cld
  109.     rep movsb;
  110.                
  111.     lea DI, String         ; DI = address String
  112.     mov AX, DI;              
  113.  
  114.     ;find surname:  
  115.     call search            ; searching index firts element,
  116.     dec AX                 ; that equal ' ', return index of next
  117.                            ; symbol    
  118.     mov BP, Right
  119.     sub BP, Left
  120.     dec BP
  121.     mov TokenLenght, BP
  122.     mov CX, BP             ; calculate length                      
  123.     mov Surname_Lenght,  CL          
  124.     lea SI, bufout          
  125.     lea DI, Surname        ; copy string to vars Surname    
  126.     cld                    
  127.     rep movsb                  
  128.    
  129.     mov AX, Right
  130.     ;find name:            
  131.     call missspace         ; call func, that count space and miss    
  132.     dec AX                 ; dec cause MissSpace return index of
  133.                            ; element, that not equal ' '    
  134.    
  135.     call search            ; call func, that searching index    
  136.     dec AX                 ; first element, that equal ' '
  137.                            ; with offset AX                                          
  138.     mov BP, Right
  139.     sub BP, Left
  140.     dec BP
  141.     mov TokenLenght, BP
  142.     mov CX, BP              ; end_word_Index - start_word_Index =
  143.                            ; loop_count && length of word                                    
  144.     mov Name_Lenght, CL
  145.        
  146.     mov SI, Left            ; SI = string[0]                                    
  147.                             ; add offset of name,
  148.                            ; SI = string[end_word_index]          
  149.     lea DI, Name_          ; copy name string  
  150.     cld                    
  151.     rep movsb                                                        
  152.        
  153.     mov AX, Right
  154.     ;find birhday:        
  155.     call missspace                                                    
  156.     dec AX    
  157.                                                    
  158.     call search
  159.     dec AX  
  160.    
  161.     mov BP, Right
  162.     sub BP, Left
  163.     dec BP
  164.     mov TokenLenght, BP
  165.     mov CX, BP
  166.                                                              
  167.     mov SI, Left                                                                                            
  168.     mov BirthDate_Lenght, CL                                                                                  
  169.     lea DI, BirthDate                                                            
  170.     cld                                                                      
  171.     rep movsb                                                        
  172.      
  173.     mov AX, Right                                              
  174.     ;find city:          
  175.     call missspace                                                      
  176.     dec AX                
  177.                                        
  178.     call search  
  179.     dec AX
  180.            
  181.     mov BP, Right
  182.     sub BP, Left
  183.     dec BP
  184.     mov TokenLenght, BP
  185.     mov CX, BP  
  186.                                                        
  187.     mov SI, Left                                                                      
  188.     mov City_Lenght, CL                                                                                                
  189.     lea DI, City                                                                
  190.     cld                                                                          
  191.     rep movsb                                                        
  192.    
  193.     mov AX, Right                                                
  194.     ;find group:                      
  195.     call missspace                                                      
  196.     dec AX              
  197.                                        
  198.     call search  
  199.     dec AX      
  200.    
  201.     mov BP, Right
  202.     sub BP, Left
  203.     dec BP
  204.     mov TokenLenght, BP
  205.     mov CX, BP
  206.    
  207.     mov SI, Left                                                
  208.    
  209.     mov Group_Lenght, CL                                    
  210.     lea DI, Group                                                                                                                      
  211.     cld                                                                              
  212.     rep movsb
  213.    
  214.     mov DL, 10
  215.     mov AH, 02h
  216.     int 21h
  217.     mov DL, 13
  218.     mov AH, 02h
  219.     int 21h        
  220.    
  221.     xor CX, CX;;
  222.     add CL, Surname_Lenght
  223.     mov AH, 40h ; func to show
  224.     mov BX, 1   ; standart handler
  225.     mov DX, offset Surname ; show this
  226.     int 21h  
  227.    
  228.     mov DL, 10
  229.     mov AH, 02h
  230.     int 21h
  231.     mov DL, 13
  232.     mov AH, 02h
  233.     int 21h  
  234.          
  235.     xor CX, CX;;
  236.     add CL, Name_Lenght          
  237.     mov AH, 40h ; func to show
  238.     mov BX, 1   ; standart handler
  239.     mov DX, offset Name_ ; show this
  240.     int 21h  
  241.    
  242.     mov DL, 10
  243.     mov AH, 02h
  244.     int 21h
  245.     mov DL, 13
  246.     mov AH, 02h
  247.     int 21h
  248.    
  249.     xor CX, CX;;
  250.     add CL, BirthDate_Lenght          
  251.     mov AH, 40h ; func to show
  252.     mov BX, 1   ; standart handler
  253.     mov DX, offset BirthDate ; show this
  254.     int 21h  
  255.    
  256.     mov DL, 10
  257.     mov AH, 02h
  258.     int 21h
  259.     mov DL, 13
  260.     mov AH, 02h
  261.     int 21h
  262.    
  263.     xor CX, CX;;
  264.     add CL, City_Lenght          
  265.     mov AH, 40h ; func to show
  266.     mov BX, 1   ; standart handler
  267.     mov DX, offset City ; show this
  268.     int 21h  
  269.    
  270.     mov DL, 10
  271.     mov AH, 02h
  272.     int 21h
  273.     mov DL, 13
  274.     mov AH, 02h
  275.     int 21h
  276.    
  277.     xor CX, CX;;
  278.     add CL, Group_Lenght          
  279.     mov AH, 40h ; func to show
  280.     mov BX, 1   ; standart handler
  281.     mov DX, offset Group ; show this
  282.     int 21h        
  283.  
  284. ;free memory
  285.  
  286. mov AH, 49h                 ; func to free memory
  287. int 21h
  288.  
  289.  
  290. mov Ax, 4c00h;
  291. int 21h
  292. text ends  
  293. data segment
  294.     bufout db 'Kostiv     Ivan    20.01.2000    Lviv  PZ-23 $' ;
  295.     buflen=$-bufout  
  296.     handle dw 0 ;
  297.     allocseg dw 0 ;
  298.     handler dw 0 ;
  299.     fname db 'File10.txt', 0  
  300.    
  301.     String      db  45 dup('$')
  302.     Surname     db  23 dup('$')      
  303.     Name_       db  23 dup('$')    
  304.     BirthDate   db  23 dup('$')    
  305.     City        db  23 dup('$')    
  306.     Group       db  23 dup('$')    
  307.          
  308.     String_Lenght       db 45            
  309.     Surname_Lenght      db 0              
  310.     Name_Lenght         db 0              
  311.     BirthDate_Lenght    db 0              
  312.     City_Lenght         db 0              
  313.     Group_Lenght        db 0  
  314.                
  315.     Left            dw 0          
  316.     Right           dw 0
  317.     TokenLenght     dw 0
  318.     SpaceMiss       dw 0        
  319.     Spaces_Count    db 0  
  320. data ends ;
  321. end begin ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement