write a program that creates a new text file prompt the userfor a student identifica 4945708
Write a program that creates a new text file. Prompt the userfor a student identification number, last name, and first name.Write this information to the file. Input several more records inthe same manner and close the file. Write this information to thefile one record per line all items comma separated like thefollowing: 12345, Last: Eclipse, First: Lunar Please use Assembly Language for x86 Processors (7th Edition).Thanks! ———————————————————————————————————————— To read or write to a file you need to do things in thefollowing order: Open File
Read / Write to File
Close File To open a file you use the CreateOutputFile procedure. In orderto use this you must place the address of a string that containsthe file name into the edx register. If the file can be openedwithout error a file handle will be returned into the eax register.You will need the hand to read and write to the file. Writing To A File To write to a file you use the WriteToFile procedure. To make thiswork you place the number of bytes to write in the ecx register,the file handle into the eax register, and the address of thestring you want written to the file in the edx register. Reading From A File To read from a file you use the ReadFromFile procedure. To makethis work you place the number of byte to read into the ecxregister, the file handle into the eax register, and the offset ofthe array you want to store the read bytes to in the edxregister. Closing The File To close a file you simply call the CloseFile Procedure File Write Example: INCLUDE Irvine32.
inc .data
filename
BYTE “test.txt”, 0
fileHandle HANDLE ?
prompt
BYTE “Enter some text”, 0dh,0ah, 0
err1
BYTE “Unable to Create File”,0dh, 0ah, 0
buffer
BYTE 300 dup(?)
.code
main PROC
; ask for some text to write to the file
mov edx,
OFFSETprompt ; prompt for text
call WriteString ; Writeprompt to screen
mov edx,
OFFSETbuffer
mov ecx, SIZEOF buffer
call ReadString
;Create the new file
mov edx,
OFFSETfilename
callCreateOutputFile ; eax now has the filehandle
mov fileHandle, eax ; storeoff the file handle ; Check for errors
cmp eax,INVALID_HANDLE_VALUE ; error found?
jne FILEOK
mov edx,
OFFSETerr1 ; display error
call WriteString
jmp EXITOUT FILEOK:
; Write to the file
mov eax, fileHandle ;File handle to eax
mov edx,
OFFSETBUFFER ;pointer to string to write in edx
mov ecx, lengthof buffer ;number of bytes to write
call WriteToFile;
call CloseFile EXITOUT:
exit
main ENDP
END main File Reading Example: INCLUDE Irvine32.
inc .data
filename
BYTE “test.txt”, 0
fileHandle HANDLE ?
prompt
BYTE “Enter some text”, 0dh,0ah, 0
err1
BYTE “Unable to Create File”,0dh, 0ah, 0
buffer
BYTE 300 dup(?)
.code
main PROC
;Create the new file
mov edx,
OFFSETfilename
call OpenInputFile ;eax now has the file handle
mov fileHandle, eax ; storeoff the file handle ; Check for errors
cmp eax,INVALID_HANDLE_VALUE ; error found?
jne FILEOK
mov edx,
OFFSETerr1 ; displayerror
call WriteString
jmp EXITOUT FILEOK:
; Read from file
mov eax, fileHandle ; filehandle in eax
mov edx,
OFFSETbuffer ; addressof array to store bytes in
mov ecx, lengthofbuffer ; max number of bytes toread
call ReadFromFile ; Readfrom file
call CloseFile ; close file
mov edx,
OFFSETbuffer ; Resetaddress in edx
call WriteString ; writefile contents to the screen.
call Crlf
EXITOUT:
exit
main ENDP
END main . . .