Question: Can you comment these codes please? INCLUDE asmlib.inc CreateFileA Proto, fileName: PTR BYTE, accessMode: DWORD, shareMode : DWORD, securityAttrib : DWORD, creationDispo : DWORD, flagsAndAttrib

Can you comment these codes please?
INCLUDE asmlib.inc
CreateFileA Proto,
fileName: PTR BYTE,
accessMode: DWORD,
shareMode : DWORD,
securityAttrib : DWORD,
creationDispo : DWORD,
flagsAndAttrib : DWORD,
hTemplateFile : DWORD
ReadFile PROTO,
hHandle : DWORD,
lpBuffer : PTR BYTE,
nNumberOfBytesToRead : DWORD,
pNumberOfBytesRead : PTR DWORD,
lpOverlapped : PTR DWORD
CloseHandle PROTO, hObject : DWORD
WriteFile PROTO,
hHandle : DWORD,
lpBuffer : PTR BYTE,
nNumberOfBytesToWrite : DWORD,
pNumberOfBytesWritten : PTR DWORD,
lpOverlapped : PTR DWORD
GetLastError PROTO ; get most recent error return value
fWriteChar PROTO
fReadChar PROTO
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
fname BYTE "test.txt",0
buffer BYTE 0
.code
main PROC
; Test fWriteChar
mov edx, OFFSET fname ; File name
mov eax, 0
call readChar
INVOKE fWriteChar
INVOKE fReadChar
exit
main ENDP
fWriteChar PROC uses edx eax
local outChar : BYTE, bytesWritten : DWORD, fHandle : DWORD
mov outChar, al ; Store the character to be written in the local variable
mov eax, 0 ; Move the file name to eax register
; Open the file for writing
INVOKE CreateFileA, edx, GENERIC_WRITE, NULL, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
mov fHandle, eax ; Store the file handle
; Write the character to the file
INVOKE WriteFile, fHandle, ADDR outChar, 1, ADDR bytesWritten, NULL
; Close the file
INVOKE CloseHandle, fHandle
ret
fWriteChar ENDP
fReadChar PROC uses edx eax
local inChar: BYTE, bytesRead: DWORD, fHandle: DWORD
mov eax, 0 ; Move the file name to eax register
; Open the file for reading
INVOKE CreateFileA, edx, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
mov fHandle, eax ; Store the file handle
mov eax, 0
; Read a single character from the file
INVOKE ReadFile, fHandle, ADDR buffer, 1, ADDR bytesRead, NULL
mov edx, OFFSET buffer
call writeLine
; Close the file
INVOKE CloseHandle, fHandle
mov al, inChar ; Move the read character to al register for return
ret
fReadChar ENDP
END main

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!