Advertisement
Levii_Valenok

Untitled

May 31st, 2022
3,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model tiny
  2. .386
  3.  
  4. .code
  5.     org 80h        
  6.     COMAND_LENGHT db ?     
  7.     COMAND_LINE db ?       
  8.     org 100h
  9.    
  10.  
  11.  
  12.    
  13. start:
  14.     cld
  15.     mov cl, COMAND_LENGHT
  16.     cmp cl, 1        
  17.     jle BAD_PARAMETRES        
  18.  
  19.     mov cx, -1
  20.     mov di, offset COMAND_LINE    
  21.          
  22.     mov al, ' '
  23.     repz scasb
  24.     dec di  
  25.     inc argc
  26.     mov si,di      
  27. READ_PARAMETRES:
  28.     lodsb          
  29.     cmp al, 0Dh      
  30.     je END_PARAMETRES
  31.     cmp al, 20h      
  32.     jne READ_PARAMETRES
  33.     dec si
  34.     mov byte ptr [si], 0    
  35.     mov di,si
  36.     inc di  
  37.  
  38. END_PARAMETRES:
  39.     dec si
  40.     mov byte ptr [si], 0
  41.     cmp argc, 1
  42.     jne BAD_PARAMETRES
  43.  
  44.     mov [NUMBER_OF_STRING], 0
  45.  
  46.     mov [MAX_NUMBERS],0
  47.    
  48.     CLEAR_PATH:
  49.     mov si,0
  50.     WHILE:
  51.     mov byte ptr[PATH_TO_RUNNING+si],""
  52.     mov byte ptr[BUFFER+si],""
  53.     inc si
  54.     cmp si,80
  55.     je FINDED_PARAMETRES
  56.     jmp WHILE
  57.     FINDED_PARAMETRES:
  58.     call FOPEN
  59.     call READ_FILEPATH
  60.     call FCLOSE
  61.    
  62.     mov sp, PROGRAM_LENGHT+100h + 200h  
  63.    
  64.     mov ah, 4Ah    
  65.     stack_offset = PROGRAM_LENGHT + 100h + 200h    
  66.     mov bx, stack_offset shr 4 + 1                 
  67.     int 21h
  68.     jnc INITIALIZE_EPB
  69.     lea dx, ERROR
  70.     mov ah, 9
  71.     int 21h
  72.     inc byte ptr [MAX_NUMBERS]
  73.     mov ah, [MAX_NUMBERS]
  74.     mov [NUMBER_OF_STRING], ah
  75.     jmp CLEAR_PATH
  76. INITIALIZE_EPB:
  77.     mov ax,cs                  
  78.     mov word ptr EPB+4, ax          ;cmd
  79.    
  80.     xor cx, cx
  81.     mov cl, 1  
  82.    
  83. MAIN_CYCLE:
  84.     mov ax, 4B00h  
  85.     mov dx, offset PATH_TO_RUNNING
  86.     mov bx, offset EPB     
  87.     int 21h
  88.    
  89.     jnc RUN_NEXT           
  90.     mov ah,9
  91.     lea dx, ERROR
  92.     int 21h
  93. RUN_NEXT:
  94.     inc byte ptr [MAX_NUMBERS]
  95.     mov ah, [MAX_NUMBERS]
  96.     mov [NUMBER_OF_STRING], ah
  97.     jmp CLEAR_PATH
  98.     loop MAIN_CYCLE
  99.    
  100.    
  101. EXIT:
  102.     int 20h
  103.  
  104. BAD_PARAMETRES:
  105.     mov dx, offset ERROR_PARAMS
  106.     mov ah, 9
  107.     int 21h
  108.     int 20h
  109.  
  110. CHECK_CURRENT:
  111.    
  112.     mov di, offset COMAND_LINE + 1
  113.     lea si, NAME_CURRENT
  114.     xor cx, cx
  115.     mov cx, 8
  116.     looop:
  117.         mov bx, [di]
  118.         mov dx, [si]
  119.         cmp bx, dx
  120.         jne end_check
  121.         inc si
  122.         inc di
  123.         loop looop
  124.     wrong:
  125.         lea dx, ERROR_CURRENT
  126.         xor ax, ax
  127.         mov ah, 9
  128.         int 21h
  129.         int 20h
  130.     end_check:
  131.     jmp CURRENT_BACK
  132.  
  133.  
  134.  
  135. FOPEN proc
  136.     push dx
  137.     push ax
  138.     mov dx,offset COMAND_LINE + 1
  139.     pusha
  140.     jmp CHECK_CURRENT
  141.     CURRENT_BACK:
  142.     popa
  143.     mov ah, 3Dh  
  144.     mov al, 00h            
  145.     int 21h
  146.    
  147.     jnc GOOD_OPEN           ;if cf == 1 ERROR
  148.     lea dx, ERROR_OPENING
  149.     mov ah, 9
  150.     int 21h
  151.     mov ax, 4C00h        
  152.     int 21h  
  153.  
  154. GOOD_OPEN:
  155.     mov [FILE_DESCRIPTOR], ax
  156.     pop ax
  157.     pop dx
  158.     ret
  159. FOPEN endp
  160.  
  161. READ_FILEPATH proc
  162.     mov di, offset PATH_TO_RUNNING
  163. END_LINE:
  164.     cmp byte ptr [NUMBER_OF_STRING], 0
  165.     jle CURRENT_LINE   
  166.     dec byte ptr [NUMBER_OF_STRING]
  167. READ_CYCLE:
  168.     mov ah, 3fh                
  169.     mov bx, [FILE_DESCRIPTOR]
  170.     mov cx, 1
  171.     lea dx, [BUFFER]       
  172.     int 21h
  173.     cmp ax, 0
  174.     je FILE_END
  175.     cmp byte ptr [BUFFER], 0Ah
  176.     jne READ_CYCLE
  177.  
  178.     jmp END_LINE
  179.    
  180. FILE_END:
  181.     call FCLOSE
  182.     int 20h
  183.    
  184. CURRENT_LINE:
  185.     mov ah, 3fh                
  186.     mov bx, [FILE_DESCRIPTOR]
  187.     mov cx, 80
  188.     lea dx, [BUFFER]       
  189.     int 21h
  190.     cmp ax, 0
  191.     je EXIT_FROM_FINDING
  192.     lea si, BUFFER
  193.     mov cx, 80
  194. CURRENT_LINE_LOOP: 
  195.     lodsb
  196.     cmp al, 0Dh
  197.     je EXIT_FROM_FINDING
  198.     stosb
  199.     loop CURRENT_LINE_LOOP
  200.    
  201. EXIT_FROM_FINDING: 
  202.  
  203.     ret
  204. READ_FILEPATH endp
  205.  
  206.  
  207. FCLOSE proc
  208.     mov ah, 3Eh
  209.     mov bx, [FILE_DESCRIPTOR]
  210.     int 21h
  211.     ret
  212. FCLOSE  endp
  213.  
  214.  
  215. PATH_TO_RUNNING db 20 dup(0)
  216. BUFFER db 80 dup(0)
  217. FILE_DESCRIPTOR dw 0   
  218. ERROR_OPENING db 'ERROR with opening the file with entered name!', 0Dh, 0Ah, '$'
  219. ERROR_PARAMS db 'ERROR in comand line params and try again!', 0Dh, 0Ah, '$'
  220. NAME_CURRENT db "lab7_1.com"
  221. ERROR_CURRENT db 0Dh, 0Ah, "ERROR: you can't open this program", 0Dh, 0Ah, '$'
  222. NUMBER_OF_STRING db 20 dup('$')
  223. MAX_NUMBERS db 20 dup('$')
  224. argc db 0
  225.  
  226.  
  227. ERROR       db "ERROR in running program ",10,13,'$'    
  228. EPB         dw 0000                        
  229.             dw offset CMD_LINE, 0        
  230.             dd 0                           
  231.             dd 0                           
  232.  
  233. CMD_LINE db 5                          
  234.             db " /?"                        
  235.             db 2 dup(?)                    
  236. PROGRAM_LENGHT equ $-start                 
  237.  
  238. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement