15.07.2014 Views

AM2: Protected-Mode Programming

AM2: Protected-Mode Programming

AM2: Protected-Mode Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ECP4166: Advanced Microprocessors<br />

<strong>AM2</strong><br />

BUFFER_SIZE = 5000<br />

.data<br />

fileHandle DWORD ?<br />

buffer BYTE BUFFER_SIZE DUP(?)<br />

.code<br />

mov eax,fileHandle<br />

mov edx,OFFSET buffer<br />

mov ecx,BUFFER_SIZE<br />

call WriteToFile<br />

The following pseudocode describes how to handle the value returned in EAX after calling<br />

WriteToFile:<br />

if EAX = 0 then<br />

error occurred when writing to file<br />

call WriteWindowsMessage to see the error<br />

else<br />

EAX = number of bytes written to the file<br />

endif<br />

Example 2<br />

The following program creates a file in output mode, asks the user to enter some text, writes<br />

the text to the output file, reports the number of bytes written, and closes the file. It checks<br />

for errors after attempting to create the file:<br />

Page 10 of 14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!