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:
TITLE MASM Template (main.asm) ; Description: ; ; Revision date: INCLUDE Irvine32.inc .data buffer BYTE 500 dup(?) bufSize DWORD ($-buffer)-1 errMsg BYTE "Cannot open file.",0dh,0ah,0 fileprompt BYTE "Enter file to display",0dh,0ah,0 filename BYTE 100 dup(?) fileHandle DWORD ? byteCount DWORD ? lines BYTE 0 asdf BYTE ? .code main PROC mov edx,OFFSET fileprompt call WriteString mov edx,OFFSET filename mov ecx,99 call ReadString invoke CreateFile,ADDR filename,GENERIC_READ,DO_NOT_SHARE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 mov fileHandle,eax cmp eax,INVALID_HANDLE_VALUE jne disploop mov edx,OFFSET errMsg call WriteString jmp QuitNow disploop: invoke ReadFile,fileHandle,ADDR buffer,bufSize,ADDR byteCount,NULL cmp byteCount,0 je atEOF mov edi,0 s: mov esi,byteCount mov buffer[esi],0 mov al,buffer[edi] mov asdf,al mov edx,OFFSET asdf call WriteString cmp buffer[edi],13 jne cm inc lines cmp lines,20 je p jmp cm p: mov lines,0 pause cm: cmp byteCount,0 je disploop inc edi jmp s atEOF: invoke CloseHandle,fileHandle QuitNow: exit main ENDP 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.