Question: In Assembly Language: I have this code: FileIO.asm: INCLUDE asmlib.inc CreateFileA Proto, fileName: PTR BYTE, accessMode: DWORD, shareMode : DWORD, securityAttrib : DWORD, creationDispo :
In Assembly Language:
I have this code:
FileIO.asm:
INCLUDE asmlib.inc
CreateFileA Proto,
fileName: PTR BYTE,
accessMode: DWORD,
shareMode : DWORD,
securityAttrib : DWORD,
creationDispo : DWORD,
flagsAndAttrib : DWORD,
hTemplateFile : DWORD
CloseHandle PROTO, hObject : DWORD
ReadFile PROTO,
hHandle:DWORD
lpBuffer:PTR BYTE,
numberOfBytesToRead: DWORD,
pNumberOfBytesRead: PTR DWORD,
lpOverlapped:PTR DWORD
WriteFile PROTO,
hHandle : DWORD,
lpBuffer : PTR BYTE,
nNumberOfBytesToWrite : DWORD,
pNumberOfBytesWritten : PTR DWORD,
lpOverlapped : PTR DWORD
GetLastError PROTO ; get most recent error return value
GENERICREAD h
GENERICWRITE h
GENERICEXECUTE h
GENERICALL h
CREATENEW
CREATEALWAYS
OPENEXISTING
OPENALWAYS
TRUNCATEEXISTING
FILEATTRIBUTENORMAL h
NULL
data
fHandle DWORD
bytesRead DWORD
bytesWritten DWORD
code
openInputFile PROC
push edx
INVOKE CreateFileA, edx, GENERICWRITE, NULL, NULL, ;Create the file for writing
OPENEXISTING, FILEATTRIBUTENORMAL, NULL
IF eax!
mov fHandle, eax
ENDIF
pop edx
ret
openInputFile ENDP
openOutputFile PROC
push edx
INVOKE CreateFileA, edx, GENERICWRITE, NULL,NULL, OPENALWAYS,
FILEATTRIBUTENORMAL, NULL
IF eax!
mov fHandle, eax
ENDIF
pop edx
ret
openOutputFile ENDP
closeFile PROC
push edx
IF fHandle
INVOKE CloseHandle, fHandle
mov fHandle,
ENDIF
pop edx
ret
closeFile ENDP
fWriteString PROC
push ebx
push edx
IF fHandle
jmp EXITOUT
ENDIF
call strLen
INVOKE WriteFile, fHandle, edx, eax, ADDR bytesWritten,NULL
EXITOUT:
pop edx
ret
fWriteString ENDP
fReadFile PROC
push ecx
IF fHandle
jmp EXITOUT
ENDIF
INVOKE ReadFile, fHandle, edx,ecx,ADDR bytesRead, NULL
mov eax, bytesRead
EXITOUT:
pop edx
pop ecx
ret
fReadFile ENDP
strLen PROC
push edx
mov eax,
L:
cmp BYTE PTRedx
je EXITOUT
inc eax
inc edx
jmp L
EXITOUT:
pop edx
ret
strLen ENDP
END
In the main file I have:
INCLUDE asmlib.inc
openInputFile PROTO
fWriteString PROTO
closeFile PROTO
fReadFile PROTO
data
fname BYTE "testA.txt
outBytes BYTE "This is a test offset the file io
buffer BYTE DUP
fHandle DWORD
bytesRead DWORD
code
main PROC
mov edx, OFFSET fName
call openInputFile
mov ecx,
mov edx, OFFSET buffer
call fReadFile
call closeFile
call writeString
exit
main ENDP
END main
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 you created from the video.
Once you have this working 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.
please inlude all code from both files
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
