• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Assembly Class Help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Xtreme Barton

Member
Joined
Jan 17, 2004
this involves homework so I do not want the answer just posted up .. defeats the purpose of me learning

GOAL:

I need to read from a file into a buffer and display that buffer to the screen .. adjusting the buffer size to 1024 and use a loop to continue reading and writing till the file contains no more data..

the book gives me a program to start with and I need to modify it to the requirements ..

ORIGINAL
Code:
TITLE Reading a File                      (ReadFile.asm)

; Opens, reads, and displays a text file using
; procedures from Irvine32.lib. 

INCLUDE Irvine32.inc
INCLUDE macros.inc

BUFFER_SIZE = 50

.data
buffer BYTE BUFFER_SIZE DUP(?)
filename    BYTE 80 DUP(0)
fileHandle  HANDLE ?

.code
main PROC

; Let user input a filename.
    mWrite "Enter an input filename: "
    mov    edx,OFFSET filename
    mov    ecx,SIZEOF filename
    call    ReadString

; Open the file for input.
    mov    edx,OFFSET filename
    call    OpenInputFile
    mov    fileHandle,eax

; Check for errors.
    cmp    eax,INVALID_HANDLE_VALUE        ; error opening file?
    jne    file_ok                    ; no: skip
    mWrite <"Cannot open file",0dh,0ah>
    jmp    quit                        ; and quit
file_ok:

; Read the file into a buffer.
    mov    edx,OFFSET buffer
    mov    ecx,BUFFER_SIZE
    call    ReadFromFile
    jnc    check_buffer_size            ; error reading?
    mWrite "Error reading file. "        ; yes: show error message
    call    WriteWindowsMsg
    jmp    close_file
    
check_buffer_size:
    cmp    eax,BUFFER_SIZE            ; buffer large enough?
    jb    buf_size_ok                ; yes
    mWrite <"Error: Buffer too small for the file",0dh,0ah>
    jmp    quit                        ; and quit
    
buf_size_ok:    
    mov    buffer[eax],0        ; insert null terminator
    mWrite "File size: "
    call    WriteDec            ; display file size
    call    Crlf

; Display the buffer.
    mWrite <"Buffer:",0dh,0ah,0dh,0ah>
    mov    edx,OFFSET buffer    ; display the buffer
    call    WriteString
    call    Crlf

close_file:
    mov    eax,fileHandle
    call    CloseFile


quit:
    exit
main ENDP

END main
 
so modifying the buffer seems ok step to take care of .. I guess now Im having an issue of how to call that while passing it the correct arguments ..

prototype is as follows ..

ReadFile Function Prototype


Code:
ReadFile Proto,
        hFile:HANDLE,                                          ; input handle
        lpBuffer:PTR BYTE,                                   ; ptr to buffer
        nNumberOfBytesToRead:DWORD               ; num bytes to read
        lpNumberOfBytesread:PTR DWORD,           ; byes actually read
        lpOverlapped:PTR DWORD                        ; ptr to asynch info


now why Im having a huge brain fart and dont know how to properly calll this is beyond me .. but I do know you call it multiple times and ReadFile will remember where it left off if say you chose to only use a very small "bytes to read argument" (nNumberOfBytesToRead)....


:bang head :cry:
 
Back