Question: So far with the file IO we have created the following functionality: openInputFile PROC ; Opens a file for reading push edx INVOKE CreateFileA, edx,
So far with the file IO we have created the following functionality:
openInputFile PROC ; Opens a file for reading
push edx
INVOKE CreateFileA, edx, GENERICREAD, NULL, NULL, OPENEXISTING, FILEATTRIBUTENORMAL, NULL
IF eax ; Check if file handle is valid
mov fHandle, eax ; Store file handle
ENDIF
pop edx
ret
openInputFile ENDP
openOutputFile PROC ; Opens a file for writing
push edx
INVOKE CreateFileA, edx, GENERICWRITE, NULL, NULL, OPENALWAYS, FILEATTRIBUTENORMAL, NULL
IF eax ; Check if file handle is valid
mov fHandle, eax ; Store file handle
ENDIF
pop edx
ret
openOutputFile ENDP
closeFile PROC ; Closes the file
push edx
IF fHandle ; Check if file handle is valid
INVOKE CloseHandle, fHandle ; Close the file
mov fHandle, ; Reset file handle
ENDIF
pop edx
ret
closeFile ENDP
fWriteString PROC ; Writes a nullterminated string to the file
push edx
IF fHandle ; No handle to the file simply return
jmp EXITOUT
ENDIF
call strLen ; Get the length of the string for writing
INVOKE WriteFile, fHandle, edx, eax, ADDR bytesWritten, NULL
EXITOUT:
pop edx
ret
fWriteString ENDP
fReadFile PROC ; ecx will have number of bytes to read
push ecx
push edx
IF fHandle ; No handle to the file simply return
jmp EXITOUT
ENDIF
INVOKE ReadFile, fHandle, edx, ecx, ADDR bytesRead, NULL
mov eax, bytesRead ; Return bytes read in eax
EXITOUT:
pop edx
pop ecx
ret
fReadFile ENDP
fWriteChar PROC
LOCAL outChar : BYTE, bytesWritten : DWORD, fHandle : DWORD
INVOKE CreateFileA, ADDR fName, GENERICWRITE, NULL, NULL, OPENALWAYS, FILEATTRIBUTENORMAL, NULL
mov fHandle, eax
mov outChar, T
INVOKE WriteFile, fHandle, ADDR outChar, ADDR bytesWritten, NULL
INVOKE CloseHandle, fHandle
ret
fWriteChar ENDP
fReadChar PROC
LOCAL inChar : BYTE, bytesRead : DWORD, fHandle : DWORD
INVOKE CreateFileA, ADDR fName, GENERICREAD, NULL, OPENEXISTING, FILEATTRIBUTENORMAL, NULL
mov fHandle, eax
INVOKE ReadFile, fHandle, ADDR inChar, ADDR bytesRead, NULL
INVOKE CloseHandle, fHandle
mov al inChar
ret
fReadChar ENDP
main PROC
INVOKE fWriteChar
INVOKE fReadChar
openInputFile Opens file for reading
openOutputFile Opens file for writing
fWriteString Writes a null terminated string to the file. This uses a strLength procedure
fReadFile Reads a number of characters from the file
Please follow the video from the lecture material and create the file IO module shown:
Video File IO
In the latest lab you created
fReadChar Reads a single character from the file
fWriteChar Writes a single character to the file
Add this functionality to the FileIO module above.
Onceworking create the following two procedures
fReadString This procedure will read characters from the file until a space is encountered.
fReadLine The procedures will read characters from the file until the carriage return line feed pair is encountered dhah
Both of these procedures should take as an argument the offset of a string to fill in the edx, The eax should return the number of character read. all of this needs to be in assembly language
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
