SHARE
TWEET

Untitled

thedoublev231 Nov 9th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model SMALL
  2. .stack 100h
  3.  
  4. input_buff_size EQU 1024
  5. output_buff_size EQU 1024
  6.  
  7. .data
  8.   input_file DB "duom.txt", 0
  9.   output_file DB "rez.txt", 0
  10.   input_buff DB input_buff_size dup (?)
  11.   output_buff DB output_buff_size dup (?)
  12.   enteris DB 10, 13, "$"
  13.  
  14.   error_read DB "Klaida atidarant duomenu faila", 10, 13, "$"
  15.   error_write DB "Klaida atidarant rezultatu faila", 10, 13, "$"
  16.   error_reading DB "Klaida skaitant duomenu faila", 10, 13, "$"
  17.   error_writing DB "Klaida rasant i rezultatu faila", 10, 13, "$"
  18.   incomplete_writing DB "Nevisi duomenys surasyti i rezultatu faila", 10, 13, "$"
  19.   error_closing DB "Nepavyko uzdaryti failo", 10, 13, "$"
  20.  
  21.   zero DB "nulis", 10, 13, "$"
  22.   one DB "vienas", 10, 13, "$"
  23.   two DB "du", 10, 13, "$"
  24.   three DB "trys", 10, 13, "$"
  25.   four DB "keturi", 10, 13, "$"
  26.   five DB "penki", 10, 13, "$"
  27.   six DB "sesi", 10, 13, "$"
  28.   seven DB "septyni", 10, 13, "$"
  29.   eight DB "astuoni", 10, 13, "$"
  30.   nine DB "devyni", 10, 13, "$"
  31.  
  32.   input_handle DW ?
  33.   output_handle DW ?
  34.  
  35. .code
  36. pradzia:
  37.   MOV AX, @data
  38.   MOV DS, AX
  39.  
  40.   CALL open_input_file
  41.   CALL open_output_file
  42.  
  43.   read:
  44.     MOV BX, input_handle
  45.     CALL read_input_file
  46.     CMP AX, 0
  47.     JE close_output_file
  48.  
  49.   ; darbas su nuskaityta info
  50.   MOV CX, AX
  51.   PUSH AX
  52.   LEA SI, input_buff
  53.   LEA DI, output_buff
  54.  
  55.   LEA BX, zero
  56.   ; tikrinam ar current symbol == '0'
  57.   lyginimas:
  58.     XOR AX, AX
  59.     MOV DL, [SI]
  60.     CMP DL, '0'
  61.     JE write_zero
  62.     JNE tesinys ; tesk jeigu nera 0
  63.     write_zero:
  64.       MOV DX, [BX]
  65.       MOV [DI], DX
  66.       INC DI
  67.       INC BX
  68.       INC AX
  69.       CMP AL, 5
  70.       JLE write_zero
  71.       JNE tesinys
  72.      
  73.   tesinys:
  74.     INC SI
  75.     LOOP lyginimas
  76.  
  77.   ; rezultatu irasymas
  78.   POP AX
  79.   MOV CX, AX
  80.   MOV BX, output_handle
  81.   CALL output_buffer
  82.   CMP AX, input_buff_size
  83.   JE read
  84.  
  85.   JMP pabaiga
  86.  
  87. close_output_file:
  88.   MOV AH, 3Eh
  89.   MOV BX, output_handle
  90.   INT 21h
  91.   JC error_closing_file
  92.   JMP pabaiga
  93.  
  94. close_input_file:
  95.   MOV AH, 3Eh
  96.   MOV BX, input_handle
  97.   INT 21h
  98.   JC error_closing_file
  99.   JMP pabaiga
  100.  
  101.  
  102. ; ***** klaidos *****
  103. error_opening_read:
  104.   MOV AH, 9
  105.   LEA DX, error_read
  106.   INT 21h
  107.   JMP pabaiga
  108. error_opening_write:
  109.   MOV AH, 9
  110.   LEA DX, error_write
  111.   INT 21h
  112.   JMP pabaiga
  113. error_closing_file:
  114.   MOV AH, 9
  115.   LEA DX, error_closing
  116.   INT 21h
  117.   JMP pabaiga
  118.  
  119.  
  120. PROC open_input_file
  121.   MOV AH, 3Dh
  122.   MOV AL, 00
  123.   LEA DX, input_file
  124.   INT 21h
  125.   JC error_opening_read
  126.   MOV input_handle, AX
  127.   RET
  128. open_input_file ENDP
  129.  
  130. PROC open_output_file
  131.   MOV AH, 3Ch
  132.   MOV CX, 0
  133.   LEA DX, output_file
  134.   INT 21h
  135.   JC error_opening_write
  136.   MOV output_handle, AX
  137.   RET
  138. open_output_file ENDP
  139.  
  140. PROC read_input_file
  141.   PUSH CX
  142.   PUSH DX
  143.  
  144.   MOV AH, 3Fh
  145.   MOV CX, input_buff_size
  146.   LEA DX, input_buff
  147.   INT 21h
  148.   JC error_while_reading
  149.  
  150.   read_input_file_end:
  151.     POP DX
  152.     POP CX
  153.     RET
  154.  
  155.   error_while_reading:
  156.     MOV AX, 0
  157.     MOV AH, 9
  158.     LEA DX, error_reading
  159.     INT 21h
  160.     JMP read_input_file_end
  161. read_input_file ENDP
  162.  
  163. PROC output_buffer
  164.   PUSH DX
  165.  
  166.   MOV AH, 40h
  167.   LEA DX, output_buff
  168.   INT 21h
  169.   JC error_while_writing
  170.   CMP CX, AX
  171.   JNE incomplete_write
  172.  
  173.   incomplete_write:
  174.     MOV AH, 9
  175.     LEA DX, incomplete_writing
  176.     INT 21h
  177.     JMP write_output_end
  178.  
  179.   write_output_end:
  180.     POP DX
  181.     RET
  182.  
  183.   error_while_writing:
  184.     MOV AX, 0
  185.     MOV AH, 9
  186.     LEA DX, error_writing
  187.     INT 21h
  188.     JMP write_output_end
  189. output_buffer ENDP
  190.  
  191. pabaiga:
  192.   MOV AH, 4Ch
  193.   MOV AL, 0
  194.   INT 21h
  195. END pradzia
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top