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, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
.IF eax !=0 ; 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, GENERIC_WRITE, NULL, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
.IF eax !=0 ; 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 !=0 ; Check if file handle is valid
INVOKE CloseHandle, fHandle ; Close the file
mov fHandle, 0 ; Reset file handle
.ENDIF
pop edx
ret
closeFile ENDP
fWriteString PROC ; Writes a null-terminated string to the file
push edx
.IF fHandle ==0 ; 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 ==0 ; 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, GENERIC_WRITE, NULL, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
mov fHandle, eax
mov outChar, 'T'
INVOKE WriteFile, fHandle, ADDR outChar, 1, ADDR bytesWritten, NULL
INVOKE CloseHandle, fHandle
ret
fWriteChar ENDP
fReadChar PROC
LOCAL inChar : BYTE, bytesRead : DWORD, fHandle : DWORD
INVOKE CreateFileA, ADDR fName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
mov fHandle, eax
INVOKE ReadFile, fHandle, ADDR inChar, 1, 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 (0dh,0ah)
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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!