Assembly project problem

Reply

Join Date: Apr 2009
Posts: 2
Reputation: Matt23488 is an unknown quantity at this point 
Solved Threads: 0
Matt23488 Matt23488 is offline Offline
Newbie Poster

Assembly project problem

 
0
  #1
Apr 2nd, 2009
I am working on homework for my x86 assembly class. The purpose of the program is to open an existing file and display the first 20 lines of the file and then pause, display the next 20 lines, pause, etc. until the end of the file is reached. My professor is really terrible, he rarely ever takes us to the lab so we don't get much practice, and so it's hard to understand. The problem is that it doesn't pause after 20 lines, and once the end of the file is reached, it starts dumping register values and garbage data and then crashes. I am really stuck, can anyone help me? Here is my code:
  1. TITLE MASM Template (main.asm)
  2.  
  3. ; Description:
  4. ;
  5. ; Revision date:
  6.  
  7. INCLUDE Irvine32.inc
  8.  
  9.  
  10. .data
  11. buffer BYTE 500 dup(?)
  12. bufSize DWORD ($-buffer)-1
  13. errMsg BYTE "Cannot open file.",0dh,0ah,0
  14. fileprompt BYTE "Enter file to display",0dh,0ah,0
  15. filename BYTE 100 dup(?)
  16. fileHandle DWORD ?
  17. byteCount DWORD ?
  18. lines BYTE 0
  19. asdf BYTE ?
  20.  
  21. .code
  22. main PROC
  23. mov edx,OFFSET fileprompt
  24. call WriteString
  25. mov edx,OFFSET filename
  26. mov ecx,99
  27. call ReadString
  28. invoke CreateFile,ADDR filename,GENERIC_READ,DO_NOT_SHARE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
  29. mov fileHandle,eax
  30. cmp eax,INVALID_HANDLE_VALUE
  31. jne disploop
  32. mov edx,OFFSET errMsg
  33. call WriteString
  34. jmp QuitNow
  35. disploop:
  36. invoke ReadFile,fileHandle,ADDR buffer,bufSize,ADDR byteCount,NULL
  37. cmp byteCount,0
  38. je atEOF
  39. mov edi,0
  40. s:
  41. mov esi,byteCount
  42. mov buffer[esi],0
  43. mov al,buffer[edi]
  44. mov asdf,al
  45. mov edx,OFFSET asdf
  46. call WriteString
  47. cmp buffer[edi],13
  48. jne cm
  49. inc lines
  50. cmp lines,20
  51. je p
  52. jmp cm
  53. p:
  54. mov lines,0
  55. pause
  56. cm:
  57. cmp byteCount,0
  58. je disploop
  59. inc edi
  60. jmp s
  61. atEOF:
  62. invoke CloseHandle,fileHandle
  63. QuitNow:
  64. exit
  65. main ENDP
  66.  
  67. END main
The irvine32.inc is from our textbook, so hopefully you guys can help me. If you need to know parameters or anything from any of the procedures, just say so and I'll post them, but I'm fairly certain that the problem lies elsewhere.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,826
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 117
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: Assembly project problem

 
0
  #2
Apr 3rd, 2009
Have a counter increment it when it reaches 20 jmp to pause.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 2
Reputation: Matt23488 is an unknown quantity at this point 
Solved Threads: 0
Matt23488 Matt23488 is offline Offline
Newbie Poster

Re: Assembly project problem

 
0
  #3
Apr 3rd, 2009
Originally Posted by ithelp View Post
Have a counter increment it when it reaches 20 jmp to pause.
I have that:
  1. inc lines
  2. cmp lines,20
  3. je p
  4. jmp cm
  5. p:
  6. mov lines,0
  7. pause
but it doesn't work.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC