AM2: Protected-Mode Programming
AM2: Protected-Mode Programming
AM2: Protected-Mode Programming
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
ECP4166: Advanced Microprocessors<br />
<strong>AM2</strong><br />
Please refer to Appendix B on how to debug this program.<br />
Exercise 1.1<br />
Write a program that prompts the user for the radius of a circle. Calculate and display the<br />
circle’s circumference and area. Use the ReadFloat and WriteFloat procedures. Use the<br />
FLDPI instruction to load onto the register stack. Please refer to Appendix A on how to<br />
create, build and run your program.<br />
Exercise 1.2<br />
Write a program that asks the user to enter the X and Y coordinates of two points on a<br />
straight line. Calculate and display the gradient of the straight line. Use the ReadFloat and<br />
WriteFloat procedures in your program.<br />
2. Win32 Console <strong>Programming</strong><br />
On the surface, 32-bit console mode programs look and behave like 16-bit MS-DOS<br />
programs running in text mode. There are differences, however: The former runs in 32-bit<br />
protected mode, whereas MS-DOS programs run in real-address mode. They use different<br />
function libraries. Win32 programs call functions from the same library used by graphical<br />
Windows applications. MS-DOS programs use BIOS and MS-DOS interrupts that have<br />
existed since the introduction of the IBM-PC.<br />
2.1 Application <strong>Programming</strong> Interface<br />
An Application <strong>Programming</strong> Interface (API) is a collection of types, constants, and<br />
functions that provide a way to directly manipulate objects through programming. Therefore,<br />
the Win32 API lets you tap into the functions in the 32-bit version of MS-Windows. The<br />
Irvine32 link library used in this experiment is completely built on Win32 console functions.<br />
It is compatible with Win32 API functions and can be used for basic input output, simulations,<br />
timing, and other useful operations. Table 2.1 gives a complete list of procedures in the<br />
Irvine32 link library.<br />
Table 2.1: Procedures in the Irvine32 link library<br />
Procedure<br />
Description<br />
CloseFile<br />
Closes a disk file that was previously opened.<br />
Clrscr<br />
Clears the console window and locates the cursor at the upper left corner.<br />
CreateOutputFile Creates a new disk file for writing in output mode.<br />
Crlf<br />
Writes an end-of-line sequence to the console window.<br />
Delay<br />
Pauses the program execution for a specified n -millisecond interval.<br />
DumpMem<br />
Writes a block of memory to the console window in hexadecimal.<br />
DumpRegs<br />
Displays the EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP, EFLAGS, and EIP<br />
registers in hexadecimal. Also displays the most common CPU status flags.<br />
GetCommandTail Copies the program’s command-line arguments (called the command tail)<br />
into an array of bytes.<br />
Page 6 of 14