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
GENERIC_READ =80000000h
GENERIC_WRITE =40000000h
GENERIC_EXECUTE =20000000h
GENERIC_ALL =10000000h
CREATE_NEW =1
CREATE_ALWAYS =2
OPEN_EXISTING =3
OPEN_ALWAYS =4
TRUNCATE_EXISTING =5
FILE_ATTRIBUTE_NORMAL =80h
NULL =0
.data
fHandle DWORD ?
bytesRead DWORD 0
bytesWritten DWORD 0
.code
openInputFile PROC
push edx
INVOKE CreateFileA, edx, GENERIC_WRITE, NULL, NULL, ;Create the file for writing
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
.IF eax!=0
mov fHandle, eax
.ENDIF
pop edx
ret
openInputFile ENDP
openOutputFile PROC
push edx
INVOKE CreateFileA, edx, GENERIC_WRITE, NULL,NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL
.IF eax!=0
mov fHandle, eax
.ENDIF
pop edx
ret
openOutputFile ENDP
closeFile PROC
push edx
.IF fHandle !=0
INVOKE CloseHandle, fHandle
mov fHandle, 0
.ENDIF
pop edx
ret
closeFile ENDP
fWriteString PROC
push ebx
push edx
.IF fHandle ==0
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==0
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, 0
L1:
cmp BYTE PTR[edx],0
je EXITOUT
inc eax
inc edx
jmp L1
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",0
outBytes BYTE "This is a test offset the file io ",0
buffer BYTE 100 DUP (0)
fHandle DWORD ?
bytesRead DWORD 0
.code
main PROC
mov edx, OFFSET fName
call openInputFile
mov ecx, 100
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 (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.
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 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!