Making a File Compressor. Need Help

Reply

Join Date: Nov 2009
Posts: 4
Reputation: leftovas17 is an unknown quantity at this point 
Solved Threads: 0
leftovas17 leftovas17 is offline Offline
Newbie Poster

Making a File Compressor. Need Help

 
0
  #1
21 Days Ago
Here is the deal. I am writing a program in assembly that compresses and decompresses text based files. The user should be able to input a text file, and declare the name of what that file should be name when turned into a .drl file (just a random extension for my prog).

Right now I am working on reading the file to be compressed. First off I am reading the file one byte at a time and looking for " "(the space character). I want to search the text files for " word" and replace each instance of that word preceded with a space with a "key." This key will be designed using Huffman's Algorithm.

Anyways I want to read the character and as long as its not null, append it to the end of a string. How do I do that?(might be simple, but I'm not seeing it)

Next, how do I read from the file one byte prior to where I finished. Meaning: if I read a space and stop the read(because its the start of a new word) how do I re-read that space to add it to the word next time around?

Those are all the questions I am at the point of asking right now, but as I have seen plenty of times before, you guys are pretty strict on not giving out help on homework without effort shown. So here is my incomplete code. Feel free to make any and all helpful criticism.

Thank You.

  1. Include Irvine32.inc ;includes Master Irvine's Library
  2.  
  3. .data
  4. message1 BYTE "Please type the file name of the file to be compressed",0 ;initiates the variable message1 and assigns it "Please type the file name of the file to be compressed", 0
  5. message2 BYTE "Please type the filename to save the compression to(must end in .drl):",0 ;initiates the variable message2 and assigns it "Please type the filename to save the compression to:", 0
  6. message3 BYTE "Cannot compress an empty file!",0 ;initiates the variable message3 and assigns it "Cannot compress and empty file", 0
  7. message4 BYTE "Please select one of the options:",0dh, 0Ah,
  8. "1. Compress a file",0dh,0ah,
  9. "2. DeCompress a file",0dh,0ah,0 ;initiates the variable message4 and assigns it "PLease select one 1. Compress 2. DeCompress", 0
  10. message5 BYTE "Please type the file name of the file to be DeCompressed(must be a .drl file):",0 ;initiates the variable message1 and assigns it "Please type the file name of the file to be Decompressed", 0
  11. message6 BYTE "Please type the filename to save the DeCompressed File to:",0 ;initiates the variable message2 and assigns it "Please type the filename to save the DeCompression to:", 0
  12. handle1 DWORD ? ;Uninitialized variable for handle1
  13. handle2 DWORD ? ;Uninitialized variable for handle2
  14. BUFFER_SIZE = 1 ;sets buffer size to 1
  15. buffer BYTE BUFFER_SIZE DUP(0) ;Duplicates buffer to buffer size and sets to 0
  16. bytesRead DWORD ? ;Unintialized variable for bytesread
  17. bytesWritten DWORD ? ;Unintialized variable for byteswritten
  18. sourceFile BYTE 20 DUP(0),0 ;initiates the variable for the sourceFile
  19. destinationFile BYTE 20 DUP(0),0 ;initiates the variable for the destinationFile
  20.  
  21. .code
  22. main PROC ;beginning of main proc
  23. call ShowPrompt ;calls showprompt proc
  24. call checkForEmptyFile ;calls checkforemptyfile proc
  25. call getFileHandles ;calls getfilehandles proc
  26. call ReadFromFile1 ;calls read from file1 proc
  27. call closeFiles ;calls the closeFiles proc
  28. exit ;properly exits
  29. main ENDP ;end of main proc
  30.  
  31. ;--------------------------------------------------------------------------------------------------------------;
  32. showPrompt PROC ;beginning of showPrompt proc
  33. L1: ;loop one
  34. mov edx, OFFSET message4 ;moves the offset of message 4 into edx
  35. call WriteString ;displays message4
  36. call crlf ;new line
  37. call ReadChar ;reads user input of a char
  38. cmp al, "1" ;compares input to the char '1'
  39. je Compress ;if equal then jump to Compress
  40. cmp al, "2" ;compares user input to the char '2'
  41. je DeCompress ;if equal then jump to DeCompress
  42. jmp L1 ;start loop over again if neither '1' nor '2'
  43.  
  44. Compress: ;beginning of Compress label
  45. mov edx, OFFSET message1 ;moves the offset of message1 into edx
  46. call WriteString ;displays message1
  47. call crlf ;new line
  48. mov edx, OFFSET sourceFile ;moves the offset of sourceFile into edx
  49. mov ecx, SIZEOF sourceFile ;moves the sizeOf sourceFile into ecx
  50. call ReadString ;reads the user input of a string
  51. call crlf ;new line
  52. Compressb: ;destination
  53. mov edx, OFFSET message2 ;moves the offset of message2 into edx
  54. call WriteString ;displays message2
  55. call crlf ;new line
  56. mov edx, OFFSET destinationFile ;moves the offset of destinationFile into edx
  57. mov ecx, SIZEOF destinationFile ;moves the sizeOf destinationFile into ecx
  58. call ReadString ;reads the user input of a string
  59. call crlf ;new line
  60.  
  61. mov edi, OFFSET destinationFile
  62. mov eax, ".drl"
  63. mov ecx, SIZEOF destinationFile
  64. cld
  65. repne scasb
  66. jnz Compressb
  67. dec edi
  68. ret ;return
  69.  
  70. DeCompress: ;beginning of DeCompress Label
  71. mov edx, OFFSET message5 ;moves the offset of message5 into ex
  72. call WriteString ;displays message5
  73. call crlf ;new line
  74. mov edx, OFFSET sourceFile ;moves the offset of sourceFile into edx
  75. mov ecx, SIZEOF sourceFile ;moves the sizeOf sourceFile into ecx
  76. call ReadString ;reads the user input of a string
  77. call crlf ;new line
  78.  
  79. mov edi, OFFSET sourceFile
  80. mov eax, ".drl"
  81. mov ecx, SIZEOF sourceFile
  82. cld
  83. repne scasb
  84. jnz DeCompress
  85. dec edi
  86.  
  87. mov edx, OFFSET message6 ;moves the offset of message6 into edx
  88. call WriteString ;displays message6
  89. call crlf ;new line
  90. mov edx, OFFSET destinationFile ;moves the offset of destinationFile into edx
  91. mov ecx, SIZEOF destinationFile ;moves the sizeOf destinationFile into ecx
  92. call ReadString ;reads the user input of a string
  93. call crlf ;new line
  94. ret ;return
  95. showPrompt ENDP ;end of ShowPrompt proc
  96.  
  97. ;--------------------------------------------------------------------------------------------------------------;
  98. checkForEmptyFile PROC
  99. mov edx, OFFSET sourceFIle ; moves the offset of sourceFile into edx
  100. call OpenInputFile ; calls openinputfile proc
  101. cmp eax, INVALID_HANDLE_VALUE ;check validity of file handle
  102. je Quit2
  103. mov handle3, eax ;jumps to quit label if invalid
  104. mov edx, OFFSET buffer ;moves the offset of buffer into edx
  105. mov ecx, BUFFER_SIZE
  106. mov eax, handle3 ;moves the buffer_Size into ecx
  107. call ReadFromFile ;calls ReadFromFile
  108. mov bytesRead, eax ;move eax into bytesRead
  109. cmp eax, 0 ;compare eax to 0
  110. je QUIT ;if eax=0 then jump to quit
  111. mov eax, handle3
  112. call Closefile ;calls closeFiles proc
  113. ret ;return
  114.  
  115. QUIT: ;beginning of QUIT label
  116. mov edx, OFFSET message9 ;moves the offset of message9 into edx
  117. call WriteString ;displays message9
  118. exit ;properly exits
  119.  
  120. QUIT2:
  121. mov edx, OFFSET message6 ;moves the offset of message6 into edx
  122. call WriteString ;calls writestring
  123. exit ;exits
  124. checkForEmptyFile ENDP ;end of checkForEmptyFile proc
  125.  
  126. ;--------------------------------------------------------------------------------------------------------------;
  127. getFileHandles PROC ;beginning of getfilehandles proc
  128. mov edx, OFFSET sourceFIle ; moves the offset of sourceFile into edx
  129. call OpenInputFile ; calls openinputfile proc
  130. cmp eax, INVALID_HANDLE_VALUE ;check validity of file handle
  131. je Quit ;jumps to quit label if invalid
  132. mov handle1, eax ;moves eax into handle1
  133. mov edx, OFFSET destinationFile ;moves the offset of the destination file into edx
  134. call CreateOutputFile ;calls the CreatOutputFile proc
  135. cmp eax, INVALID_HANDLE_VALUE ;check validity of file handle
  136. je Quit ;jumps to quit label if invalid
  137. mov handle2, eax ;moves eax into handle2
  138. ret ;return
  139.  
  140. QUIT: ;beginning of quit label
  141. mov edx, OFFSET message6 ;moves the offset of message6 into edx
  142. call WriteString ;writes edx
  143. call crlf ;new line
  144. call crlf ;new line
  145. call main ;calls main proc
  146. getFileHandles ENDP ;end of getFileHandles Proc
  147.  
  148. ;--------------------------------------------------------------------------------------------------------------;
  149. readFromFile1 PROC ;begining of readFromfile1 proc
  150. Read: ;beginning of read label
  151. mov eax, handle1 ;moves handle1 into eax
  152. mov edx, OFFSET buffer ; moves the offset of the buffer into edx
  153. mov ecx, BUFFER_SIZE ;moves the buffer size into ecx
  154. First:
  155. call ReadFromFile
  156. cmp eax, 0
  157. je Quit2
  158. cmp eax, " "
  159. je Next
  160.  
  161.  
  162. jmp New
  163. NEXT:
  164. mov bytesread, eax ;moves the data into bytesread
  165. New:
  166. call ReadFromFile ;reads data from file
  167. cmp eax, 0 ;compares eax to 0
  168. je Quit2 ;if eax = 0 then jump to Quit2
  169. cmp eax, " "
  170. jne NEXT
  171. push eax ;push eax onto stack
  172.  
  173. pop eax ;pops eax off stack
  174. cmp eax, 5 ;compares eax to 5
  175. jb Quit ;jump to quit if carry
  176. call clear ;new line
  177. jmp Read ;jump back to Read
  178.  
  179. Quit: ;beginning of Quit label
  180. call crlf ;new line
  181. mov edx, OFFSET message8 ;moves the offset of message8 into edx
  182. call WriteString ;displays message8
  183. ret ;return
  184.  
  185.  
  186. Quit2: ;beginning of Quit2 label
  187. ret ;return
  188. readFromFile1 ENDP ;end of readFromFile1 proc
  189.  
  190. ;--------------------------------------------------------------------------------------------------------------;
  191. closeFiles PROC ;beginning of closeFiles proc
  192. mov eax, handle1 ;moves handle1 into eax
  193. call CloseFile ;closes the file
  194. mov eax, handle2 ;moves handle2 into eax
  195. call CloseFile ;close the file
  196. ret ;return
  197. closeFiles ENDP ;end of the closeFiles proc
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: leftovas17 is an unknown quantity at this point 
Solved Threads: 0
leftovas17 leftovas17 is offline Offline
Newbie Poster
 
0
  #2
21 Days Ago
And I, like other recent posts, am using MASM and use the Assembly Language for Intel-Based Computers (5e)- Irvine
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: leftovas17 is an unknown quantity at this point 
Solved Threads: 0
leftovas17 leftovas17 is offline Offline
Newbie Poster
 
0
  #3
21 Days Ago
UPDATE: Kinda bummed that over 70 people have viewed and no one can help, but I'm hoping that someone will see this soon who can help. I am working on solving the problem of reading the file byte by byte and storing into 1 variable. The best solution so far is to setup a variable such as word dword 45 dup('~'), 0 which i can then add to each byte of the 'word', is this right? then my terminating character is '~' since this is my least likely character(i think) to encounter in my file.

Here is an updated code. It works up to the point of creating the new file, then it basically just freezes.

Is there a way to edit previous posts so that I don't have to keep making this longer and longer?

  1. Include Irvine32.inc ;includes Master Irvine's Library
  2.  
  3. .data
  4. message1 BYTE "Please type the file name of the file to be compressed",0 ;initiates the variable message1 and assigns it "Please type the file name of the file to be compressed", 0
  5. message2 BYTE "Please type the filename to save the compression to(must end in .drl):",0 ;initiates the variable message2 and assigns it "Please type the filename to save the compression to:", 0
  6. message3 BYTE "Cannot compress an empty file!",0 ;initiates the variable message3 and assigns it "Cannot compress and empty file", 0
  7. message4 BYTE "Please select one of the options:",0dh, 0Ah,
  8. "1. Compress a file",0dh,0ah,
  9. "2. DeCompress a file",0dh,0ah,0 ;initiates the variable message4 and assigns it "PLease select one 1. Compress 2. DeCompress", 0
  10. message5 BYTE "Please type the file name of the file to be DeCompressed(must be a .drl file):",0 ;initiates the variable message1 and assigns it "Please type the file name of the file to be Decompressed", 0
  11. message6 BYTE "Please type the filename to save the DeCompressed File to:",0 ;initiates the variable message2 and assigns it "Please type the filename to save the DeCompression to:", 0
  12. message7 BYTE "Cannot compress an empty file!",0 ;initiates the variable message7 and assigns it "Cannot compress and empty file", 0
  13. message8 BYTE "Complete!",0 ;initiates the variable message8 and assigns it "Complete!", 0
  14. handle1 DWORD ? ;Uninitialized variable for handle1
  15. handle2 DWORD ? ;Uninitialized variable for handle2
  16. handle3 DWORD ? ;Uninitialized variable for handle3
  17. BUFFER_SIZE = 1 ;sets buffer size to 1
  18. buffer BYTE BUFFER_SIZE DUP(0) ;Duplicates buffer to buffer size and sets to 0
  19. bytesRead DWORD ? ;Unintialized variable for bytesread
  20. bytesWritten DWORD ? ;Unintialized variable for byteswritten
  21. sourceFile BYTE 20 DUP(0),0 ;initiates the variable for the sourceFile
  22. destinationFile BYTE 20 DUP(0),0 ;initiates the variable for the destinationFile
  23. times dword 46 DUP('~'),0
  24.  
  25. .code
  26. main PROC ;beginning of main proc
  27. call ShowPrompt ;calls showprompt proc
  28. call checkForEmptyFile ;calls checkforemptyfile proc
  29. call getFileHandles ;calls getfilehandles proc
  30. call ReadFromFile1 ;calls read from file1 proc
  31. call closeFiles ;calls the closeFiles proc
  32. exit ;properly exits
  33. main ENDP ;end of main proc
  34.  
  35. ;--------------------------------------------------------------------------------------------------------------;
  36. showPrompt PROC ;beginning of showPrompt proc
  37. L1: ;loop one
  38. mov edx, OFFSET message4 ;moves the offset of message 4 into edx
  39. call WriteString ;displays message4
  40. call crlf ;new line
  41. call ReadChar ;reads user input of a char
  42. cmp al, "1" ;compares input to the char '1'
  43. je Compress ;if equal then jump to Compress
  44. cmp al, "2" ;compares user input to the char '2'
  45. je DeCompress ;if equal then jump to DeCompress
  46. jmp L1 ;start loop over again if neither '1' nor '2'
  47.  
  48. Compress: ;beginning of Compress label
  49. mov edx, OFFSET message1 ;moves the offset of message1 into edx
  50. call WriteString ;displays message1
  51. call crlf ;new line
  52. mov edx, OFFSET sourceFile ;moves the offset of sourceFile into edx
  53. mov ecx, SIZEOF sourceFile ;moves the sizeOf sourceFile into ecx
  54. call ReadString ;reads the user input of a string
  55. call crlf ;new line
  56. Compressb: ;destination
  57. mov edx, OFFSET message2 ;moves the offset of message2 into edx
  58. call WriteString ;displays message2
  59. call crlf ;new line
  60. mov edx, OFFSET destinationFile ;moves the offset of destinationFile into edx
  61. mov ecx, SIZEOF destinationFile ;moves the sizeOf destinationFile into ecx
  62. call ReadString ;reads the user input of a string
  63. call crlf ;new line
  64.  
  65. mov edi, OFFSET destinationFile
  66. mov eax, ".drl"
  67. mov ecx, SIZEOF destinationFile
  68. cld
  69. repne scasb
  70. jnz Compressb
  71. dec edi
  72. ret ;return
  73.  
  74. DeCompress: ;beginning of DeCompress Label
  75. mov edx, OFFSET message5 ;moves the offset of message5 into ex
  76. call WriteString ;displays message5
  77. call crlf ;new line
  78. mov edx, OFFSET sourceFile ;moves the offset of sourceFile into edx
  79. mov ecx, SIZEOF sourceFile ;moves the sizeOf sourceFile into ecx
  80. call ReadString ;reads the user input of a string
  81. call crlf ;new line
  82.  
  83. mov edi, OFFSET sourceFile
  84. mov eax, ".drl"
  85. mov ecx, SIZEOF sourceFile
  86. cld
  87. repne scasb
  88. jnz DeCompress
  89. dec edi
  90.  
  91. mov edx, OFFSET message6 ;moves the offset of message6 into edx
  92. call WriteString ;displays message6
  93. call crlf ;new line
  94. mov edx, OFFSET destinationFile ;moves the offset of destinationFile into edx
  95. mov ecx, SIZEOF destinationFile ;moves the sizeOf destinationFile into ecx
  96. call ReadString ;reads the user input of a string
  97. call crlf ;new line
  98. ret ;return
  99. showPrompt ENDP ;end of ShowPrompt proc
  100.  
  101. ;--------------------------------------------------------------------------------------------------------------;
  102. checkForEmptyFile PROC
  103. mov edx, OFFSET sourceFIle ; moves the offset of sourceFile into edx
  104. call OpenInputFile ; calls openinputfile proc
  105. cmp eax, INVALID_HANDLE_VALUE ;check validity of file handle
  106. je Quit2
  107. mov handle3, eax ;jumps to quit label if invalid
  108. mov edx, OFFSET buffer ;moves the offset of buffer into edx
  109. mov ecx, BUFFER_SIZE
  110. mov eax, handle3 ;moves the buffer_Size into ecx
  111. call ReadFromFile ;calls ReadFromFile
  112. mov bytesRead, eax ;move eax into bytesRead
  113. cmp eax, 0 ;compare eax to 0
  114. je QUIT ;if eax=0 then jump to quit
  115. mov eax, handle3
  116. call Closefile ;calls closeFiles proc
  117. ret ;return
  118.  
  119. QUIT: ;beginning of QUIT label
  120. mov edx, OFFSET message7 ;moves the offset of message7 into edx
  121. call WriteString ;displays message7
  122. exit ;properly exits
  123.  
  124. QUIT2:
  125. mov edx, OFFSET message6 ;moves the offset of message6 into edx
  126. call WriteString ;calls writestring
  127. exit ;exits
  128. checkForEmptyFile ENDP ;end of checkForEmptyFile proc
  129.  
  130. ;--------------------------------------------------------------------------------------------------------------;
  131. getFileHandles PROC ;beginning of getfilehandles proc
  132. mov edx, OFFSET sourceFIle ; moves the offset of sourceFile into edx
  133. call OpenInputFile ; calls openinputfile proc
  134. cmp eax, INVALID_HANDLE_VALUE ;check validity of file handle
  135. je Quit ;jumps to quit label if invalid
  136. mov handle1, eax ;moves eax into handle1
  137. mov edx, OFFSET destinationFile ;moves the offset of the destination file into edx
  138. call CreateOutputFile ;calls the CreatOutputFile proc
  139. cmp eax, INVALID_HANDLE_VALUE ;check validity of file handle
  140. je Quit ;jumps to quit label if invalid
  141. mov handle2, eax ;moves eax into handle2
  142. ret ;return
  143.  
  144. QUIT: ;beginning of quit label
  145. mov edx, OFFSET message6 ;moves the offset of message6 into edx
  146. call WriteString ;writes edx
  147. call crlf ;new line
  148. call crlf ;new line
  149. call main ;calls main proc
  150. getFileHandles ENDP ;end of getFileHandles Proc
  151.  
  152. ;--------------------------------------------------------------------------------------------------------------;
  153. readFromFile1 PROC ;begining of readFromfile1 proc
  154. Read: ;beginning of read label
  155. mov eax, handle1 ;moves handle1 into eax
  156. mov edx, OFFSET buffer ; moves the offset of the buffer into edx
  157. mov ecx, BUFFER_SIZE ;moves the buffer size into ecx
  158. First:
  159. call ReadFromFile
  160. cmp eax, 0
  161. je Quit2
  162. cmp eax, " "
  163. je Next
  164.  
  165.  
  166. jmp New
  167. NEXT:
  168. mov bytesread, eax ;moves the data into bytesread
  169. New:
  170. call ReadFromFile ;reads data from file
  171. cmp eax, 0 ;compares eax to 0
  172. je Quit2 ;if eax = 0 then jump to Quit2
  173. cmp eax, " "
  174. jne NEXT
  175. push eax ;push eax onto stack
  176.  
  177. pop eax ;pops eax off stack
  178. cmp eax, 5 ;compares eax to 5
  179. jb Quit ;jump to quit if carry
  180. call clear ;new line
  181. jmp Read ;jump back to Read
  182.  
  183. Quit: ;beginning of Quit label
  184. call crlf ;new line
  185. mov edx, OFFSET message8 ;moves the offset of message8 into edx
  186. call WriteString ;displays message8
  187. ret ;return
  188.  
  189.  
  190. Quit2: ;beginning of Quit2 label
  191. ret ;return
  192. readFromFile1 ENDP ;end of readFromFile1 proc
  193.  
  194. ;--------------------------------------------------------------------------------------------------------------;
  195. clear PROC ;beginning of Clear proc
  196. mov ecx, SIZEOF buffer ;moves the sizeOf buffer into ecx
  197. mov esi,0 ;moves 0 into esi
  198. L2: ;loop two
  199. mov buffer[esi],0 ;moves 0 into buffer at esi
  200. inc esi ;increment esi
  201. loop L2 ;loop back
  202. ret ;return
  203. clear ENDP ;end of clear proc
  204.  
  205. ;--------------------------------------------------------------------------------------------------------------;
  206. closeFiles PROC ;beginning of closeFiles proc
  207. mov eax, handle1 ;moves handle1 into eax
  208. call CloseFile ;closes the file
  209. mov eax, handle2 ;moves handle2 into eax
  210. call CloseFile ;close the file
  211. ret ;return
  212. closeFiles ENDP ;end of the closeFiles proc
  213.  
  214.  
  215. end MAIN
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: leftovas17 is an unknown quantity at this point 
Solved Threads: 0
leftovas17 leftovas17 is offline Offline
Newbie Poster
 
0
  #4
20 Days Ago
ANOTHER UPDATE: Hoping someone will be able to help soon! Haha.

Right now my major problem is that I read a word, put it into the newword variable and then try to add that to an array of words to store till I write the output file. However, every time I add the word and then display it to check I only get random symbols and junk. Any ideas why? here is my updated code....

  1. ;AUTHOR: DANIEL LUCAS
  2.  
  3. Include Irvine32.inc ;includes Master Irvine's Library
  4.  
  5. .data
  6. message1 BYTE "Please type the file name of the file to be compressed",0 ;initiates the variable message1 and assigns it "Please type the file name of the file to be compressed", 0
  7. message2 BYTE "Please type the filename to save the compression to(must end in .drl):",0 ;initiates the variable message2 and assigns it "Please type the filename to save the compression to:", 0
  8. message3 BYTE "Cannot compress an empty file!",0 ;initiates the variable message3 and assigns it "Cannot compress and empty file", 0
  9. message4 BYTE "Please select one of the options:",0dh, 0Ah,
  10. "1. Compress a file",0dh,0ah,
  11. "2. DeCompress a file",0dh,0ah,0 ;initiates the variable message4 and assigns it "PLease select one 1. Compress 2. DeCompress", 0
  12. message5 BYTE "Please type the file name of the file to be DeCompressed(must be a .drl file):",0 ;initiates the variable message1 and assigns it "Please type the file name of the file to be Decompressed", 0
  13. message6 BYTE "Please type the filename to save the DeCompressed File to:",0 ;initiates the variable message2 and assigns it "Please type the filename to save the DeCompression to:", 0
  14. message7 BYTE "Cannot compress an empty file!",0 ;initiates the variable message7 and assigns it "Cannot compress and empty file", 0
  15. message11 BYTE "Here3", 0dh, 0Ah,0 ;initiates the variable message8 and assigns it "Complete!", 0
  16. message9 BYTE "Here1", 0dh, 0Ah,0
  17. message10 BYTE "Here2", 0dh, 0Ah,0
  18. message8 BYTE "Complete!",0
  19. handle1 DWORD ? ;Uninitialized variable for handle1
  20. handle2 DWORD ? ;Uninitialized variable for handle2
  21. handle3 DWORD ? ;Uninitialized variable for handle3
  22. handle4 DWORD ? ;Uninitialized variable for handle4
  23. BUFFER_SIZE = 1 ;sets buffer size to 1
  24. buffer BYTE BUFFER_SIZE DUP(0) ;Duplicates buffer to buffer size and sets to 0
  25. bytesRead DWORD ? ;Unintialized variable for bytesread
  26. bytesWritten DWORD ? ;Unintialized variable for byteswritten
  27. sourceFile BYTE 20 DUP(0),0 ;initiates the variable for the sourceFile
  28. destinationFile BYTE 20 DUP(0),0 ;initiates the variable for the destinationFile
  29. newword byte 46 DUP(?),0
  30. fresh byte 46 DUP(0),0
  31. store dword ?
  32. wordArray DWORD ?
  33. wordNum dword 1
  34.  
  35. .code
  36. main PROC ;beginning of main proc
  37. call ShowPrompt ;calls showprompt proc
  38. call checkForEmptyFile ;calls checkforemptyfile proc
  39. call getFileHandles ;calls getfilehandles proc
  40. call ReadFromFile1 ;calls read from file1 proc
  41. call closeFiles ;calls the closeFiles proc
  42. exit ;properly exits
  43. main ENDP ;end of main proc
  44.  
  45. ;--------------------------------------------------------------------------------------------------------------;
  46. showPrompt PROC ;beginning of showPrompt proc
  47. L1: ;loop one
  48. mov edx, OFFSET message4 ;moves the offset of message 4 into edx
  49. call WriteString ;displays message4
  50. call crlf ;new line
  51. call ReadChar ;reads user input of a char
  52. cmp al, "1" ;compares input to the char '1'
  53. je Compress ;if equal then jump to Compress
  54. cmp al, "2" ;compares user input to the char '2'
  55. je DeCompress ;if equal then jump to DeCompress
  56. jmp L1 ;start loop over again if neither '1' nor '2'
  57.  
  58. Compress: ;beginning of Compress label
  59. mov edx, OFFSET message1 ;moves the offset of message1 into edx
  60. call WriteString ;displays message1
  61. call crlf ;new line
  62. mov edx, OFFSET sourceFile ;moves the offset of sourceFile into edx
  63. mov ecx, SIZEOF sourceFile ;moves the sizeOf sourceFile into ecx
  64. call ReadString ;reads the user input of a string
  65. call crlf ;new line
  66. Compressb: ;destination
  67. mov edx, OFFSET message2 ;moves the offset of message2 into edx
  68. call WriteString ;displays message2
  69. call crlf ;new line
  70. mov edx, OFFSET destinationFile ;moves the offset of destinationFile into edx
  71. mov ecx, SIZEOF destinationFile ;moves the sizeOf destinationFile into ecx
  72. call ReadString ;reads the user input of a string
  73. call crlf ;new line
  74. push eax
  75. mov edi, OFFSET destinationFile
  76. mov eax, ".drl"
  77. mov ecx, SIZEOF destinationFile
  78. cld
  79. repne scasb
  80. jnz Compressb
  81. dec edi
  82. pop eax
  83. ret ;return
  84.  
  85. DeCompress: ;beginning of DeCompress Label
  86. mov edx, OFFSET message5 ;moves the offset of message5 into ex
  87. call WriteString ;displays message5
  88. call crlf ;new line
  89. mov edx, OFFSET sourceFile ;moves the offset of sourceFile into edx
  90. mov ecx, SIZEOF sourceFile ;moves the sizeOf sourceFile into ecx
  91. call ReadString ;reads the user input of a string
  92. call crlf ;new line
  93.  
  94. mov edi, OFFSET sourceFile
  95. mov eax, ".drl"
  96. mov ecx, SIZEOF sourceFile
  97. cld
  98. repne scasb
  99. jnz DeCompress
  100. dec edi
  101.  
  102. mov edx, OFFSET message6 ;moves the offset of message6 into edx
  103. call WriteString ;displays message6
  104. call crlf ;new line
  105. mov edx, OFFSET destinationFile ;moves the offset of destinationFile into edx
  106. mov ecx, SIZEOF destinationFile ;moves the sizeOf destinationFile into ecx
  107. call ReadString ;reads the user input of a string
  108. call crlf ;new line
  109. ret ;return
  110. showPrompt ENDP ;end of ShowPrompt proc
  111.  
  112. ;--------------------------------------------------------------------------------------------------------------;
  113. checkForEmptyFile PROC
  114. mov edx, OFFSET sourceFIle ; moves the offset of sourceFile into edx
  115. call OpenInputFile ; calls openinputfile proc
  116. cmp eax, INVALID_HANDLE_VALUE ;check validity of file handle
  117. je Quit2
  118. mov handle3, eax ;jumps to quit label if invalid
  119. mov edx, OFFSET buffer ;moves the offset of buffer into edx
  120. mov ecx, BUFFER_SIZE
  121. mov eax, handle3 ;moves the buffer_Size into ecx
  122. call ReadFromFile ;calls ReadFromFile
  123. mov bytesRead, eax ;move eax into bytesRead
  124. cmp eax, 0 ;compare eax to 0
  125. je QUIT ;if eax=0 then jump to quit
  126. mov eax, handle3
  127. call Closefile ;calls closeFiles proc
  128. ret ;return
  129.  
  130. QUIT: ;beginning of QUIT label
  131. mov edx, OFFSET message7 ;moves the offset of message7 into edx
  132. call WriteString ;displays message7
  133. call crlf ;new line
  134. exit ;properly exits
  135.  
  136. QUIT2:
  137. mov edx, OFFSET message6 ;moves the offset of message6 into edx
  138. call WriteString ;calls writestring
  139. call crlf ;new line
  140. exit ;exits
  141. checkForEmptyFile ENDP ;end of checkForEmptyFile proc
  142.  
  143. ;--------------------------------------------------------------------------------------------------------------;
  144. getFileHandles PROC ;beginning of getfilehandles proc
  145. mov edx, OFFSET sourceFIle ; moves the offset of sourceFile into edx
  146. call OpenInputFile ; calls openinputfile proc
  147. cmp eax, INVALID_HANDLE_VALUE ;check validity of file handle
  148. je Quit ;jumps to quit label if invalid
  149. mov handle1, eax ;moves eax into handle1
  150. mov edx, OFFSET destinationFile ;moves the offset of the destination file into edx
  151. call CreateOutputFile ;calls the CreatOutputFile proc
  152. cmp eax, INVALID_HANDLE_VALUE ;check validity of file handle
  153. je Quit ;jumps to quit label if invalid
  154. mov handle2, eax ;moves eax into handle2
  155. ret ;return
  156.  
  157. QUIT: ;beginning of quit label
  158. mov edx, OFFSET message6 ;moves the offset of message6 into edx
  159. call WriteString ;writes edx
  160. call crlf ;new line
  161. call crlf ;new line
  162. call main ;calls main proc
  163. getFileHandles ENDP ;end of getFileHandles Proc
  164.  
  165. ;--------------------------------------------------------------------------------------------------------------;
  166. readFromFile1 PROC ;begining of readFromfile1 proc
  167. mov store, OFFSET newword
  168. mov edi, OFFSET newword
  169. mov esi, OFFSET wordArray
  170. Read: ;beginning of read label
  171.  
  172. mov eax, OFFSET newword
  173. mov edx, eax ;moves the offset of message9 into edx
  174. call WriteString ;displays message9
  175.  
  176. First:
  177. mov eax, handle1 ;moves handle1 into eax
  178. mov edx, OFFSET buffer ; moves the offset of the buffer into edx
  179. mov ecx, BUFFER_SIZE ;moves the buffer size into ecx
  180.  
  181. call ReadFromFile
  182. cmp eax, 0
  183. je Quit2
  184. cmp buffer, " "
  185. je Next
  186. jmp first
  187.  
  188. NEXT:
  189. mov al, buffer
  190. mov [edi], al ;moves the data into bytesread
  191. inc edi
  192.  
  193.  
  194.  
  195. New:
  196. mov eax, handle1 ;moves handle1 into eax
  197. mov edx, OFFSET buffer ; moves the offset of the buffer into edx
  198. mov ecx, BUFFER_SIZE ;moves the buffer size into ecx
  199. call ReadFromFile ;reads data from file
  200. cmp eax, 0 ;compares eax to 0
  201. je Quit2 ;if eax = 0 then jump to Quit2
  202. add eax, bytesread
  203. mov bytesread, eax
  204. cmp buffer, " "
  205. jne NEXT
  206.  
  207. mov edi, OFFSET newword
  208. mov eax, " "
  209. mov ecx, SIZEOF newword
  210. cld
  211. repne scasb
  212. jnz noWorth
  213. dec edi
  214. cmp bytesread, 4
  215. jb NoWorth
  216. push eax
  217. mov eax, handle1
  218. mov handle4, eax
  219. ;call scanMe
  220. pop eax
  221.  
  222. Worth:
  223. mov edi, OFFSET newword
  224. mov [esi], edi
  225. add esi, 4
  226.  
  227. NoWorth:
  228. call clear
  229. mov bytesread, 0
  230.  
  231. mov edx, OFFSET newword ;moves the offset of message9 into edx
  232. call WriteString
  233. jmp first
  234.  
  235.  
  236. Quit: ;beginning of Quit label
  237. call crlf ;new line
  238. mov edx, OFFSET message8 ;moves the offset of message8 into edx
  239. call WriteString ;displays message8
  240. ret ;return
  241.  
  242.  
  243. Quit2: ;beginning of Quit2 label
  244. mov edx, OFFSET wordArray ;moves the offset of message9 into edx
  245. call WriteString ;displays message9
  246. ret ;return
  247. readFromFile1 ENDP ;end of readFromFile1 proc
  248.  
  249. ;--------------------------------------------------------------------------------------------------------------;
  250. clear PROC ;beginning of Clear proc
  251. mov ecx, SIZEOF newword ;moves the sizeOf buffer into ecx
  252. mov esi,0 ;moves 0 into esi
  253. L2: ;loop two
  254. mov newword[esi],0 ;moves 0 into buffer at esi
  255. inc esi ;increment esi
  256. loop L2 ;loop back
  257. ret ;return
  258. clear ENDP ;end of clear proc
  259.  
  260. ;--------------------------------------------------------------------------------------------------------------;
  261. closeFiles PROC ;beginning of closeFiles proc
  262. mov eax, handle1 ;moves handle1 into eax
  263. call CloseFile ;closes the file
  264. mov eax, handle2 ;moves handle2 into eax
  265. call CloseFile ;close the file
  266. ret ;return
  267. closeFiles ENDP ;end of the closeFiles proc
  268.  
  269. ;--------------------------------------------------------------------------------------------------------------;
  270. scanMe PROC
  271. mov edi, handle4
  272. NotDone:
  273. mov esi, SIZEOF handle4
  274. xor eax,eax
  275. mov eax, OFFSET newword
  276. mov ecx, lengthof handle4
  277. cld
  278. repne scasb
  279. jnz quit
  280. push eax
  281. mov eax, wordNum
  282. inc eax
  283. mov wordNum, eax
  284. pop eax
  285. mov edx, wordNum ;moves the offset of message9 into edx
  286. call Writedec ;displays message9
  287. ;cmp edi, esi
  288. ;jb NotDone
  289. quit:
  290. ret
  291. scanMe ENDP
  292.  
  293. end MAIN
Reply With Quote Quick reply to this message  
Reply

Tags
assembly, compression, file, text

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC