home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / assembly-language / x86 / general / part1 next >
Encoding:
Text File  |  2000-03-22  |  32.2 KB  |  849 lines

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!howland.erols.net!pants.skycache.com.MISMATCH!triton.skycache.com!portc01.blue.aol.com!portc.blue.aol.com!feed.newsreader.com!news!not-for-mail
  2. From: raymoon@ms1.dgsys.com (Raymond Moon)
  3. Newsgroups: alt.lang.asm,comp.lang.asm.x86,news.answers,alt.answers,comp.answers
  4. Subject: x86 Assembly Language FAQ - General Part 1/3
  5. Supersedes: <89seus$stn$1@news.dgsys.com>
  6. Followup-To: alt.lang.asm,comp.lang.asm.x86
  7. Date: 21 Mar 2000 23:02:28 GMT
  8. Organization: MoonWare
  9. Lines: 823
  10. Approved: news-answers-request@MIT.EDU
  11. Distribution: world
  12. Expires: Thu, 20 Apr 2000 23:59:59 GMT
  13. Message-ID: <8b8v24$n7i$1@news.dgsys.com>
  14. Reply-To: raymoon@moonware.dgsys.com
  15. NNTP-Posting-Host: dgs.dgsys.com
  16. X-Trace: news.dgsys.com 953679748 23794 207.154.12.1 (21 Mar 2000 23:02:28 GMT)
  17. X-Complaints-To: usenet@news.dgsys.com
  18. NNTP-Posting-Date: 21 Mar 2000 23:02:28 GMT
  19. Summary: This is the FAQ for the x86 Assembly Language programmers for
  20.  the alt.lang.asm and comp.lang.asm.x86 newsgroups.  This particular
  21.  section of the FAQ is part one of three parts that contain x86
  22.  assembly language information common to all assemblers.
  23. Keywords: x86 Assembly Language ASM FAQ General
  24. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  25. Xref: senator-bedfellow.mit.edu alt.lang.asm:25270 comp.lang.asm.x86:83703 news.answers:179899 alt.answers:47940 comp.answers:40152
  26.  
  27. Archive-Name: assembly-language/x86/general/part1
  28. Posting-Frequency: monthly (21st of every month)
  29. Last-modified: 2000/02/20
  30.  
  31. ------------------------------
  32.  
  33. Subject: 1.  Introduction and Intent
  34.  
  35. This is the x86 Assembly Language FAQ for the comp.lang.asm.x86 and
  36. alt.lang.asm newsgroups.  This FAQ is posted monthly on or about the
  37. 21st of the month to both newsgroups and news.answers, alt.answers and
  38. comp.answers.  It also is archived at the normal FAQ archival site,
  39. ftp://rtfm.mit.edu and to SimTel and its mirror sites in the msdos/info
  40. directory and Garbo and its mirrors in the pc/doc-net directory.  When
  41. uploaded to SimTel or Garbo, the filenames are asmxxyyz.zip, where xx is
  42. the two digit year, yy is the number of the month and z is t for text or
  43. h for HTML format.  Lastly, the current version is available from my web
  44. page as:
  45.     As text files:
  46.         http://www2.dgsys.com/~raymoon/faq/asmfaq.zip
  47.     As HTML documents:
  48.         http://www2.dgsys.com/~raymoon/faq/asmfaqh.zip
  49. Currently, this FAQ is broken into six sections.  The following are the
  50. section filenames and the scope of each section of the FAQ.
  51.  
  52. assembly-language/x86/general/part1 - This is the basic portion of the
  53.     FAQ that contains information of interest to all assembly language
  54.     programmers.  In general, the information contained in this portion
  55.     of the FAQ is not specific to any particular assembler.
  56. assembly-language/x86/general/part2 - This is a continuation of the
  57.     above FAQ.
  58. assembly-language/x86/general/part3 - This is a continuation of the
  59.     above FAQ.
  60. assembly-language/x86/microsoft - This portion of the FAQ contains
  61.     information specific for the Microsoft MASM.
  62. assembly-language/x86/borland - This portion of the FAQ contains
  63.     information specific for the Borland TASM.
  64. assembly-language/x86/a86 - This portion of the FAQ contains information
  65.     specific for the Shareware A86 Assembler and D86 Debugger.
  66.  
  67. The scope and content of this FAQ is to go beyond just answering the
  68. frequently asked questions.  I am including pointers to assembly
  69. language treasure troves that are hidden on the Internet.  I believe
  70. that this will enhance the FAQÆs value not only to the novices but also
  71. to the old hands.
  72.  
  73. For the ease of determining what has changed since the last FAQ, the
  74. Table of Contents will have ôREVISEDö at the end of the subject line for
  75. all revised subjects.  If more than one FAQ revision has been missed,
  76. the ôLast Changed:ö entry at the end of each subject can be used to
  77. determine which subjects have been revised during the intervening
  78. period.
  79.  
  80. The information in this FAQ is free for all to use as long as you
  81. acknowledge the source.  This FAQ can be reproduced in part or in its
  82. entirety as long as the copyright is included.  This FAQ can be made
  83. available on public servers, like ftp, gopher or WWW servers.  Please do
  84. not modify the file, such as converting it into some other format,
  85. without prior permission of the author.
  86.  
  87. All references to files and locations are in Uniform Resource Locators
  88. (URLs) format.  Some web browser will be able to use these URLs directly
  89. as hot links.  If the format is not clear to you, get RFC 1738.  It is
  90. available from:
  91.     http://info.internet.isi.edu:80/in-notes/rfc/files/rfc1738.txt
  92.  
  93. Suggestions for changes and comments are always welcome.  They can be
  94. posted to either newsgroup or e-mailed directly to me.
  95.  
  96. Author: Raymond Moon, raymoon@moonware.dgsys.com
  97. Copyright 2000 - Raymond Moon
  98. ALL RIGHTS RESERVED
  99. Last Changed: 5 Feb 2000
  100.  
  101. ------------------------------
  102.  
  103. Subject: 2. Table of Contents
  104.  
  105. Part I
  106.  
  107. 1.  Introduction and Intent
  108. 2.  Table of Contents
  109. 3.  Charters For comp.lang.asm.x86 and alt.lang.asm Newsgroups
  110. 4.  What is Assembly Language
  111. 5.  List of x86 OpCodes
  112. 6.  What is HELPPC and Where It Is Available
  113. 7.  How To Truncate a File
  114. 8.  How Can STDERR Be Redirected To a File
  115. 9.  How To Determine the CPU Type
  116. 10. IRQ Assignments
  117. 11. Ralf Brown's Interrupt List
  118. 12. Using VGA Mode 13h for Fast Graphics
  119. 13. Protected Mode Programming
  120. 14. Shareware ASM Libraries
  121.  
  122. Part II
  123.  
  124. 15. Accessing 4 Gegs of Memory in Real Mode
  125. 16. What Is Available at developer.intel.com
  126. 17. Interrupts and Exceptions
  127. 18. ASM Books Available
  128. 19. ASM Code Available on Internet
  129. 20. How To Commit a File
  130. 21. Using Extended Memory Manager
  131. 22. EXE2BIN Replacement
  132. 23. ASM Tutorials Available on the Internet
  133. 24. Shareware Assemblers
  134. 25. Undocumented OpCodes
  135.  
  136. Part III
  137.  
  138. 26. WWW Assembly HomePages
  139. 27. Common Reason Why Memory Allocation Fails
  140. 28. Volume Serial Numbers
  141. 29. .obj File Format
  142. 30. Rebooting from Software
  143. 31. Other FAQs
  144. 32. Pseudo Random Number Generator in Assembly Language
  145. 33. Command Line Arguments
  146. 34. Free 32-bit and DJGPP
  147. 35. TERSE Programming Language
  148. 36. Assembly Language IDEs
  149. 37. Disassemblers
  150. 38. How to Optimize for the Pentium
  151. 39. Assembly Language Programming Style Guidelines
  152. 40. Other Assembly-Related Newsgroups
  153. 41. ZD-86 Debugger
  154. 42. Links to x86 Processor Manufacturers
  155. 43. Linkers Available
  156. 44. ASM Mailing Lists
  157. 45. ASM Programming Journal
  158. 46. Acknowledgments
  159.  
  160. ------------------------------
  161.  
  162. Subject: 3. Charters For comp.lang.asm.x86 and alt.lang.asm Newsgroups
  163.  
  164. To know whether or not these newsgroups will meet your needs, the
  165. purpose for which they were created are given below.
  166.  
  167. 3.1  COMP.LANG.ASM.X86
  168.  
  169. comp.lang.asm.x86 was created based upon voting on a Request for
  170. Discussion (RFD).  The RFD for this newsgroup is:
  171.  
  172. The moderated newsgroup comp.lang.asm.x86 will be open to discussions on
  173. all topics related to assembly language and low-level programming on any
  174. machine using a x86 processor or its clones.  Appropriate topics would
  175. include, but not be limited to:
  176.  
  177. Assembly language code tips, tricks, and techniques.
  178. MASM, TASM, and other commercial assemblers
  179. NASM, and other non-commercial assemblers
  180. Graphics, sound, and other hardware programming
  181. Assembly language related utilities commercial/share/free-ware
  182. Linking assembly language with other languages
  183. Inline x86 programming utilizing assembly emulators in higher level
  184.     languages
  185. Propagation of non-commercial Internet x86 resources
  186. Any question/discussion of the direct programming of the x86
  187. Etc...
  188.  
  189. Topics that will be filtered are:
  190.  
  191. Flames about "{Language X} is {better/worse} than ASM"
  192. Flames like "{Assembler 1} is {better/worse} than {Assembler 2}"
  193. Flames, personal attacks, insults, etc.
  194. HLL code, except when used for low-level hardware programming.
  195. Product comparisons except when presented in an unbiased fashion.
  196. Advertisements unrelated to assembly programming or utilities.
  197. Posts in languages other than English will be examined for approval
  198.   if any of the moderators can read the language in question.  There
  199.   is no guarantee of approval for a post in any language other than
  200.   English.
  201.  
  202. Posting to comp.lang.asm.x86, a moderated newsgroup, is not any
  203. different for you as posting to an unmoderated newsgroup.  When you are
  204. finished composing your post just send it as you normally do.  Your
  205. ISPÆs news server will send the post to the moderatorÆs e-mail address.
  206. Once approved, the moderator will post it.  Therefore, you will not see
  207. your postings immediately in the newsgroup.  It should take no longer
  208. than a day or so to see it.
  209.  
  210. 3.2  ALT.LANG.ASM
  211.  
  212. Alt newsgroups are initiated with a Proposal posting to the alt.config
  213. newsgroup.  The proposal for alt.lang.asm is:
  214.  
  215. alt.lang.asm will address the problems of machine language programmers
  216. out there in Internet land.  It will be a forum for discussion of coding
  217. techniques and efficiency problems related to machine language.  The
  218. scope will be broad.  We will not discriminate by machine architecture,
  219. race or sex.
  220.  
  221. Contributors: Raymond Moon, raymoon@moonware.dgsys.com
  222. Last changed: 9 Dec 97
  223.  
  224. ------------------------------
  225.  
  226. Subject: 4. What Is Assembly Language
  227.  
  228. 4.1  WHAT IS MACHINE LANGUAGE?
  229.  
  230. Although programmers tend to use C or C++ or Pascal these days, the
  231. language closest to the PC hardware is machine language.  Not one second
  232. during a PCS powered on lifetime passes where the computer is not
  233. executing machine language.
  234.  
  235. 4.2  ASSEMBLY LANGUAGE OR MACHINE LANGUAGE
  236.  
  237. To word this simply, you can say that say that assembly language is a
  238. human-readable text, and machine language is machine-readable binary
  239. code. When you program in assembly language, you are programming on the
  240. machine language level.
  241.  
  242. To program directly in machine language is tedious, so you use assembly
  243. language instead, and use an assembler to produce the actual machine
  244. code.
  245.  
  246. 4.3  WHEN TO USE ASSEMBLY LANGUAGE
  247.  
  248. I personally think that except as a learning exercise it is a waste of
  249. time writing something in ASM that can be written acceptably fast in a
  250. high-level language.
  251.  
  252. Assembly language fits for the following:
  253.  
  254.  *  Low level control.  When you need to change the flags, or the
  255.     control registers of the processor, as when entering protected
  256.     mode.
  257.  
  258.  *  Speed.  Programs written in machine language execute fast!  It can
  259.     execute 10-100 times the speed of BASIC, and about twice as fast as
  260.     a program written in C or Pascal.
  261.  
  262.  *  Time Critical Code.  Critical sections of programs written in
  263.     higher level languages can be written in assembly to speed up
  264.     sections.
  265.  
  266.  *  Small program size.  When you write a TSR for example this is very
  267.     useful.  Writing interrupt handlers is where assembly language
  268.     shines.
  269.  
  270. Assembly language is very flexible and powerful; anything that the
  271. hardware of the computer is capable of doing can be done in assembly.
  272.  
  273. Contributor: Patrik Ohman, patrik@astrakan.hgs.se
  274. Last changed: 10 Jan 95
  275.  
  276. ------------------------------
  277.  
  278. Subject: 5.  List Of x86 OpCodes
  279.  
  280. 5.1  x86 OPCODES
  281.  
  282. The best source of OpCodes up to and including the Pentium Pro processor
  283. is in the Intel Architecture Software DeveloperÆs Manual, Volume 2:
  284. Instruction Set Reference Manual.  It is available in .pdf format from
  285. IntelÆs Web Site:
  286.  
  287.     http://developer.intel.com/design/pentiumii/manuals/243191.htm
  288.  
  289. 5.2  MMX OPCODES
  290.  
  291. Intel has a chapter covering these new OpCodes in the MMX Technology
  292. ProgrammerÆs Reference Manual.  This chapter is Chapter Five - Intel
  293. Architecture MMX Instruction Set.
  294.  
  295.     http://developer.intel.com/drg/mmx/Manuals/prm/PRM_CHP5.HTM
  296.  
  297. 5.3  OTHER SOURCES OF THESE DOCUMENTS
  298.  
  299. These manuals are available on the Intel DeveloperÆs CD-ROM, see Subject
  300. #16.  You also can find these manuals on Robert CollinsÆ Web Site:
  301.  
  302.     http://www.x86.org/intel.doc/IntelDocs.html
  303.  
  304. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  305. Last changed: 17 Oct 99
  306.  
  307. ------------------------------
  308.  
  309. Subject: 6.  What Is HELPPC and Where Is It Available
  310.  
  311. HELPPC is a Quick Reference Utility for the intermediate to advanced
  312. programmer.  It is a shareware program written by David Jurgens.  The
  313. latest version is 2.10
  314.  
  315. The topics distributed in an easy database format are:
  316.     BIOS interrupts;
  317.     DOS interrupts and DOS functions;
  318.     EMS and Mouse functions;
  319.     BIOS and DOS data structures;
  320.     diagnostic codes;
  321.     DOS commands;
  322.     80x86 assembler instructions;
  323.     standard and vendor specific C functions; and
  324.     various hardware specifications.
  325.  
  326. HELPPC is customizable by users.  The documentation describes how users
  327. can incorporate their own information into the help file format.  These
  328. user help files then can be incorporated into the database and accessed
  329. via HELPPC application.
  330.  
  331. HELPPC comes in two versions.  The first is a DOS command line program.
  332. The second is a TSR.  The TSR supports context sensitive help within
  333. many editors.  Only 32K are taken by the TSR version.
  334.  
  335. HELPPC requires:
  336.     DOS 2.0 or greater;
  337.     64K of RAM for DOS Command Line or 32K for TSR; and
  338.     Hard disk recommended.
  339.  
  340. HELPPC is available from:
  341.  
  342.     ftp://ftp.simtel.net/pub/simtelnet/msdos/info/helppc21.zip
  343.  
  344. HELPPC also is available from any site that mirrors the SimTel
  345. directory.
  346.  
  347. Contributor:  Raymond Moon, raymoon@moonware.dgsys.com
  348. Last changed: 28 Dec 94
  349.  
  350. ------------------------------
  351.  
  352. Subject: 7. How To Truncate A File
  353.  
  354. There is not any single DOS Int 21h function that performs this
  355. operation.  A file can be truncated using two functions.  The procedure
  356. is:
  357.  
  358. 1.  Use Int 21h function 42h, Move File Pointer, to move the file
  359.     pointer to the position where you want the file to be truncated.
  360. 2.  Use Int 21h function 40h, Write File or Device, to write zero bytes
  361.     to the file.
  362.  
  363. Execution of the last DOS function will update the directory to the new
  364. file length.
  365.  
  366. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  367. Last changed: 28 Dec 94
  368.  
  369. ------------------------------
  370.  
  371. Subject: 8. How Can STDERR Be Redirected To A File
  372.  
  373. I understand that 4DOS has this capability at its command line.  If you
  374. are looking in the assembly language FAQ for this information, an
  375. assembly language answer probably is desired.  Here it is.
  376.  
  377. You will need to write a short program that performs the STDERR
  378. redirection before loading and executing the desired program.  This
  379. loader program relies upon the fact that a child program inherits all
  380. open files of the parent program unless the parent program opens a file
  381. with the inheritance flag set to no.
  382.  
  383. Because the full code for such a program is too large for this FAQ, I
  384. will give the salient specifications for such a program.
  385.  
  386. 1.  The loader program accepts three command line arguments:
  387.     a.  The full path and filename of the file into which STDERR is to
  388.         be written.
  389.     b.  The full path and filename of the program to be executed.
  390.     c.  The command line for the program to be executed (should be
  391.         delimited by double quotes to allow multiple arguments).  This
  392.         argument is optional.
  393. 2.  Release all memory above the program using Int 21 function 4ah so
  394.     that there will be room enough to load and execute the designated
  395.     program.
  396. 3.  Open the file from step 1.a above into which STDERR is to be
  397.     written.
  398. 4.  Duplicate STDERR filehandle, which is 2, using Int 21h function
  399.     45h.
  400. 5.  Using Int 21h function 46h, force STDERR filehandle, again 2, to
  401.     have the filehandle of the opened file from step 2.
  402. 6.  Use Int 21h function 4b00h to load and execute the program from
  403.     step 1.a.  Use the default environment and the command line from
  404.     step 1.c above.
  405. 7.  Upon return from the function 4b00h, close the file opened in step
  406.     2.
  407. 8.  To restore STDERR, use Int 21h function 46h to force STDERR, again
  408.     2, to point to the filehandle saved from step 3 above.
  409.  
  410. This same technique can be applied to any of the standard devices.
  411.  
  412. I have written a full featured demonstration program.  I believe that
  413. asm programmers will find the source code useful even if they do not
  414. want to redirect stderr to a file.  The URL to the file is:
  415.  
  416.     ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/stderrf1.zip
  417.  
  418. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  419. Last changed: 3 Jun 95
  420.  
  421. ------------------------------
  422.  
  423. Subject: 9.  How To Determine The CPU Type
  424.  
  425. 9.1  CPUID PROGRAM
  426.  
  427. The type of processor and math coprocessor can be determined using two
  428. functions that have been provided by Intel.  The source code to these
  429. functions can be obtained from Intel by:
  430.  
  431.     ftp://ftp.intel.com/pub/IAL/tools_utils_demos/cpuid3.zip
  432.  
  433. Three source files are included in this .zip file.
  434.     cpuid3a.asm - This source code file contains two assembly language
  435.         functions.  One determines the type of cpu from 8088/8086 to
  436.         Pentium.  The second detects and identifies, if present, the
  437.         type of math coprocessor.
  438.     cpuid3b.c - a c program that calls the above two functions and
  439.         displays the results.
  440.     cpuid3c.asm - this is an assembly program equivalent to cpuid3b.c.
  441.  
  442. 9.2  AP-485 INTEL PROCESSOR IDENTIFICATION WITH THE CPUID INSTRUCTION
  443.  
  444. This Application Note explains how to use the CPUID instruction in
  445. software applications, BIOS implementations, and various processor
  446. tools.  By taking advantage of the CPUID instruction, software
  447. developers can create software applications and tools that can execute
  448. compatibly across the widest range of Intel processor generations and
  449. models, past, present, and future.
  450.  
  451.     http://developer.intel.com/design/pro/applnots/241618.htm
  452.  
  453. 9.3  Robert Collins' CPUID.ASM
  454.  
  455. Robert Collins has written two columns for Dr. DobbÆs Journal on this
  456. subject.  These articles with source code is available on his web site:
  457.  
  458.     Part 1: http://www.x86.org/ddj/Sep96/Sep96.html
  459.     Part 2: http://www.x86.org/ddj/Nov96/Nov96.html
  460.  
  461. 9.4  Grzegorz Mazur's x86 CPU Identification
  462.  
  463. Grzegorz has a series of hypertext articles that explain x86 CPU
  464. identification algorithms developed by him.  Covered are not only the
  465. Intel chips but also V20, V30 (remember them), and Cyrix.  His page is
  466. located:
  467.  
  468.     http://grafi.ii.pw.edu.pl/gbm/x86/
  469.  
  470. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  471. Last changed: 18 Mar 97
  472.  
  473. ------------------------------
  474.  
  475. Subject: 10.  IRQ Assignments
  476.  
  477. A list of IRQ assignments are available in David Jurgens' HELPPC
  478. database.  See Subject #6 for details on how to obtain this program.
  479.  
  480. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  481. Last changed: 28 Dec 94
  482.  
  483. ------------------------------
  484.  
  485. Subject: 11.  Ralf Brown's Interrupt List
  486.  
  487. 11.1  FILE AVAILABILITY
  488.  
  489. The latest version of Ralf Brown's Interrupt List is 60, dated 3 Jan 99.
  490. The files are available directly from his home page, from SimTel, or
  491. Garbo:
  492.  
  493.     http://www.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/WWW/files.html
  494.     ftp://ftp.simtel.net/pub/simtelnet/msdos/info
  495.     ftp://garbo.uwasa.fi/pc/programming
  496.  
  497. The files are:
  498. inter60a.zip    Comprehensive listing of interrupt calls, 1 of 4
  499. inter60b.zip    Comprehensive listing of interrupt calls, 2 of 4
  500. inter60c.zip    Comprehensive listing of interrupt calls, 3 of 4
  501. inter60d.zip    Comprehensive listing of interrupt calls, 4 of 4
  502. inter60e.zip    Utility programs/source code for interrupt list
  503. inter60f.zip    WinHelp conversion programs for interrupt list
  504. inter60g.zip    Hypertext conversion programs for interrupt list
  505.  
  506. 11.2  DESCRIPTION
  507.  
  508. The interrupt list is a comprehensive listing of functions available
  509. through interrupt calls and FAR calls, both documented and (officially)
  510. undocumented, plus maps of CMOS and BIOS memory, I/O ports, I2C-bus
  511. devices, and System Management Mode save areas.  This release contains
  512. more than 9500 entries and over 5300 tables.
  513.  
  514. 11.3  WHAT IS NEW
  515.  
  516. New in this release: 140k of updates, including Econet, VESA VBE/AF,
  517. Matrox VESA-OEM functions, more Soft-ICE backdoor commands, XBIOS,
  518. EZ-Drive, Adaptec AIC-7xxx and AHA-152x ports, GEM/ViewMAX, WinTel API,
  519. TrLit API, VHRBIOS.SYS, Philips SAA7110(A), Intel 82595FX, an updated
  520. OPCODES.LST.  Also includes a new version of INT2WHLP which can handle
  521. the new five-character table numbers.
  522.  
  523. 11.4  OTHER INCLUDED GEMS
  524.  
  525. OVERVIEW.LST - A brief description of each of the 256 interrupts.
  526. 86BUGS.LST - A list of undocumented and buggy instructions with
  527.     descriptions of the x86 Intel processor and compatible
  528.     processors.  And you thought that the Intel FDIV was the first
  529.     bug in a processor!
  530. CMOS.LST - a CMOS memory map.
  531. OPCODE.LST - A list of undocumented instructions and documented
  532.     instructions of any last processor.
  533. PORTS.LST - I/O port addressed for XT, AT and PS/2 computers.
  534. GLOSSARY.LST - glossary of PC terms.
  535. MEMORY.LST - The format for various memory locations, such as the
  536.     BIOS Data Segment, Interrupt Vector Table, and much, much more.
  537. INTERRUP.PRI - iAPX 86 Interrupt Primer
  538.  
  539. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  540. Last changed: 21 Feb 99
  541.  
  542. ------------------------------
  543.  
  544. Subject: 12. Using VGA Mode 13h for Fast Graphics
  545.  
  546. 12.1  INTRODUCTION AND PREPARATION
  547.  
  548. Mode 13h is so widely used for graphics applications in DOS because it
  549. is very easy to use.  The screen is constantly being redrawn by the
  550. video card.  To affect what the card draws, it is necessary to write to
  551. the screen buffer.  The screen buffer in mode 13h is always at
  552. segment:offset = A000:0000.  Thus, to set up drawing directly to the
  553. video buffer, this is what you'd most often first do:
  554.  
  555.   ;Change the video mode to 13h
  556.     xor  ah, ah         ;VIDEO Function 00h: Change screen
  557.     mov  al, 13h        ;Put the desired graphics mode into AL
  558.     int  10h            ;Call VIDEO
  559.  
  560.   ;Prepare for writing to the video buffer
  561.     mov  di, 0a000h     ;Put the video segment into DI
  562.     mov  es, di         ; so it can easily be put into ES
  563.     xor  di, di         ;Start writing at coordinates (0,0)
  564.  
  565. 12.2  WRITING PIXELS TO THE SCREEN
  566.  
  567. Why is Mode 13h so popular?  To understand, you must know a few basic
  568. facts.  In Mode 13h, the screen is 320 by 200, or 320 pixels across and
  569. 200 pixels down.  In each pixel, there's a possibility of 256 colors,
  570. which can be fit into one byte.  Thus, 320*200*1 = 64000 bytes, about
  571. the size of one segment.  Think of the screen as an array of colors.
  572. The first row takes up addresses A000:0000 to A000:013F (decimal 319),
  573. the second row takes up addresses A000:0140 to A000:027F (decimal 639),
  574. and so on.  To plot a pixel, assuming ES=A000:
  575.  
  576.   ;Plot a pixel in video mode 13h, where
  577.   ;PixelAddress = (320 * Y) + X
  578.     mov  ax, 320        ; Prepare for the multiplication
  579.     mul  [Y]            ; Assuming that Y is defined in the data segment
  580.                         ;   earlier in the program
  581.     mov  di, ax         ; Put in into the pointer to the offset of ES
  582.     add  di, [X]        ; Assuming that X is defined in the data segment
  583.                         ;   earlier in the program
  584.     mov  al, [Color]    ; Assuming that Color is defined in the data
  585.                         ;   segment earlier in the program
  586.     stosb               ; Write it to the screen!
  587.  
  588. See how easy that was?  Something to remember is that it is zero-based.
  589. The upper-left corner is (0,0), and the lower-right is (319,199).  A
  590. complete TASM Ideal mode procedure might look something like this (it
  591. assumes that the video card is already set to mode 13h):
  592.  
  593. PROC WritePixel BASIC   ; Or whatever language you might want to link
  594.                         ;  it to
  595.     USES es, di         ; It's always a good idea to preserve ES and DI
  596.     ARG  X:word, Y:word, Color:BYTE
  597.     mov  di, 0a000h     ; Put the video segment into DI
  598.     mov  es, di         ;   so it can easily be put into ES
  599.     mov  ax, 320        ; Prepare for the multiplication
  600.     mul  [Y]            ; Offset pointer by the Y value passed in
  601.     mov  di, ax         ; Put in into pointer to the offset of ES
  602.     add  di, [X]        ; Offset the pointer by the X value passed in
  603.     mov  al, [Color]    ; Put color to be written to the screen in AL
  604.     stosb               ; Write it to the screen!
  605.     ret
  606. ENDP WritePixel
  607.  
  608. To write a horizontal line, just put the length in CX, and replace the
  609. STOSB with a REP STOSB.  Writing a vertical line is only a little
  610. trickier.  Observe the following TASM Ideal mode procedure:
  611.  
  612. PROC VerticalLine BASIC ; Or whatever language you might want to link
  613.                         ;  it to
  614.     USES es, di         ; It's always a good idea to preserve ES and
  615.                         ;  DI
  616.     ARG  X:word, Y:word, Color:BYTE, Length:word
  617.     mov  di, 0a000h     ; Put the video segment into DI
  618.     mov  es, di         ; so it can easily be put into ES
  619.     mov  ax, 320        ; Prepare for the multiplication
  620.     mul  [Y]            ; Offset the pointer by the Y value passed in
  621.     mov  di, ax         ; Put in into the pointer to the offset of ES
  622.     add  di, [X]        ; Offset the pointer by the X value passed in
  623.     mov  al, [Color]    ; Put the color to be written to the screen
  624.                         ; in AL
  625.     mov  cx, [Length]   ; Prepare for the loop
  626. YLoop:
  627.     stosb               ; Write it to the screen!
  628.     add  di, 319        ; Move down one row (DI has already advanced
  629.                         ;  once because of the STOSB, thus the 319)
  630.     loop YLoop
  631.     ret
  632. ENDP VerticleLine
  633.  
  634. Observe how there is a tight loop that moves DI down one row each
  635. iteration.
  636.  
  637. In short, the easiest way to write directly to the Mode 13h video buffer
  638. is to think of the screen as just a 320 by 200 array of bytes, starting
  639. at A000:0000.
  640.  
  641. Author: Michael Averbuch (mikeaver@prairienet.org)
  642. Last Change: 29 Dec 94
  643.  
  644. ------------------------------
  645.  
  646. Subject: 13.  Protected Mode Programming
  647.  
  648. 13.1  PMODE Tutorials, FAQ, and other reference documentation
  649.  
  650. Protected Mode Basics by Robert Collins
  651.     http://x86.ddj.com/articles/pmbasics/tspec_a1_doc.htm
  652.     Excellent starting tutorial with source code.
  653.  
  654. PMODE FAQ
  655.     ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/pmtut002.zip
  656.  
  657. Protected Mode Book List
  658.     http://www.interactive.net/~viren/Janz/Books/pmode_books.htm
  659. (Broken)
  660.  
  661. Christopher GieseÆs PMODE Tutorial
  662.     http://www.execpc.com/~geezer/os/pm.htm
  663.     HTML format
  664.  
  665. pmode-l FAQs
  666.     http://www.lysator.liu.se/~redhog
  667.     http://bphantom.tripod.com/pmode-l_FAQ.html
  668.     http://pmode-l.webjump.com/  (in HTML)
  669.  
  670. 13.2  Source code Archives
  671.  
  672. Walnut Creek PMODE Archives
  673.     ftp://ftp.cdrom.com/pub/demos/code/hardware/pmode/
  674.  
  675. X2FTP.OULU.FI
  676.     ftp://x2ftp.oulu.fi/pub/msdos/programming/pmode/00index.html
  677.     Protected mode utilities and some source code
  678.  
  679. 13.3  PMODE Websites
  680.  
  681. Peter's PMODE Home Page
  682.     http://www.geocities.com/SiliconValley/Peaks/1231/
  683.     PMODE tutorials and programming related files
  684.  
  685. Niko Komin's Assembler for PCs page
  686.     http://www.inx.de/~nkomin/html/assembe.htm
  687.  
  688. Shareware, pmode, x86 mnemonics, ASM related links.
  689.     http://www.alaska.net/~zumwalt
  690.     Archives, Source Code, Technical Documentation, OS Chat Room
  691.         and much more
  692.  
  693. PASS-32, Dieter's Assembler
  694.     http://www.geocities.com/SiliconValley/Bay/3437/
  695.     Debugger and DOS extender also available
  696.  
  697. Dario Alpern's programs
  698.     http://members.tripod.com/~alpertron/ENGLISH2.HTM
  699.     PMODE examples
  700.  
  701. Christopher GieseÆs Triple Fault Club
  702.     http://www.execpc.com/~geezer/os/index.htm
  703.     NASM and DJGPP Code, Protected Mode Code, OS Code
  704.  
  705. Gaz's Little Web Programming Page
  706.     http://www.fortunecity.com/skyscraper/fatbit/427/programming.html
  707.     Protected Mode Tutorial and large library of NASM source code
  708.         written for the WDosX 32 bit DOS extender
  709.  
  710. 5.4  PMODE Mailing Lists
  711.  
  712. Protected Mode Mailing list:
  713.     To subscribe:
  714.     Send: mailto:pmode-l-request@fys.ruu.nl
  715.     subject: none
  716.     body: subscribe pmode-l email@yourisp.name (Note that is pmode-l
  717.         (ell) not pmode-1 (one)
  718.  
  719. Use pmode-l@fys.ruu.nl to send email to others in the list.
  720.  
  721. To unsubscribe:
  722.     Send: mailto:pmode-l-request@fys.ruu.nl
  723.     subject: none
  724.     body: unsubscribe pmode-l email@yourisp.name
  725.  
  726. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  727. Last changed: 20 Feb 2000
  728.  
  729. ------------------------------
  730. Subject: 14.  Shareware ASM Libraries
  731.  
  732. 14.1  ASMLIB PROGRAMMER'S TOOLKIT, VERSION 4.0
  733.  
  734. Douglas Herr's shareware assembly language library.  This library is
  735. available from SimTel.
  736.  
  737.     ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/asmlib40.zip
  738.  
  739. The zip file contains only the medium model of the library.  There are
  740. 405 assembly subroutines in a .lib file and documentation.  Source code
  741. is available with registration and extra fee.  The library covers the
  742. following areas:
  743.     string/integer data manipulation        screen mode subroutines
  744.     text-mode multi-window subroutines      disk & file subroutines
  745.     text-mode video subroutines             EMS and XMS subroutines
  746.     floating-point subroutines              graphics
  747.     keyboard input subroutines              mathematical solutions
  748.     subroutines which determine PC status
  749.  
  750. asmlib40 also comes with an editor, E16, written entirely with asmlib.
  751.  
  752. Improvements since version 3.7 is auto-sizing of the near heap in the
  753. startup code.  There have been some incremental improvements including
  754. 32k-color graphics and virtual graphics screens.
  755.  
  756. 14.2  THE ASSEMBLY WIZARD'S LIBRARY, VERSION 2.1
  757.  
  758. This is Chris WalkerÆs shareware assembly language library.  This
  759. library used to be Thomas Hanlin's.
  760.  
  761.     ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/asmwiz21.zip
  762.  
  763. This library comes with documentation and one .lib file that supports
  764. small and tiny memory models.  Source code is available with
  765. registration. The library covers the following areas:
  766.  
  767.     Base Conversions        Mouse Services
  768.     Exception Handling      Sound and Music
  769.     Delays and Countdowns   String Services
  770.     File Handling           Telecommunications
  771.     Filename Manipulation   Time and Date
  772.     Keyboard Services       Video Services
  773.     Long Integer Math       Miscellaneous Services
  774.     Memory Services
  775.  
  776. 14.3  UCR Standard Library for Assembly Language Programmers
  777.  
  778. This library is written by Randall Hyde and others.  This library is
  779. available from many sites but most of them are seriously out of date.
  780. You can get the latest version at:
  781.  
  782.     http://webster.cs.ucr.edu/Page_asm/RHUCRLib.html
  783.  
  784. Unlike the previous libraries, there are no registration fees and the
  785. included source code is released to the public domain.  The author does
  786. request that if you use the library, you contribute at least one routine
  787. to the library.
  788.  
  789.     Standard Input Routines     Character Set Routines
  790.     Standard Output Routines    Memory Management Routines
  791.     Conversion Routines         String Handling Routines
  792.     Utility Routines
  793.  
  794. 14.4  ALIB Version 4.0
  795.  
  796. ALIB is Jeff Ownens' shareware assembly language library.  This library
  797. is available from SimTel.
  798.  
  799.     ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/alib40.zip
  800.  
  801. Similar to the UCR library described above, registration fees are not
  802. requested.  The library consists of over 400 assembly source files
  803. covering the following areas:
  804.  
  805.     compress    - data compression and expansion
  806.     config      - program configuration, colors, paths, etc.
  807.     compare     - compare strings
  808.     convert     - hex/decimal/ascii conversions
  809.     database    - simple database functions
  810.     disk        - disk information, path changes, file searches
  811.     display     - fast display functions, write to display memory
  812.     error       - error handlers
  813.     float       - simple floating point math package
  814.     math        - dword math, crc, roots
  815.     memory      - memory manager, extended, xms, ems, conventional
  816.     menu        - menuing system
  817.     message     - messages in windows on screen
  818.     misc        - misc routines
  819.     mouse/key   - mouse and keyboard functions
  820.     parse       - extraction of parameters from command line
  821.     random      - random number generators
  822.     search      - search for character or string
  823.     sort        - sort buffer or file
  824.     sound       - sounds
  825.     string      - ascii string handling
  826.     stdout      - characters, strings, spaces to stdout
  827.     system      - system interrogation and setup
  828.     time        - time and date conversions
  829.  
  830. Also included are 15 sample programs.
  831.  
  832. 14.5  FREELIB, Version 3.0
  833.  
  834. Freelib v3.0 is a library of 200 routines that may be useful for
  835. assembly language programming.  Freelib includes routines that do many
  836. of the tasks that make assembly language difficult - like buffered file
  837. I/O, formatted string output, memory allocation, etc.  Also includes
  838. 16.16bit fixed point arithmetic, text screen output (EGA 80x25 or VGA
  839. 90x34), and VGA graphics in both 16 and 256 colors.  All routines are
  840. highly optimized for size and speed, and average only 60 bytes each.
  841. Full source code and documentation is included for all routines.
  842. Freelib is public domain software, free for non-commercial use.  The
  843. library is available from SimTel:
  844.  
  845.     ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/freeli30.zip
  846.  
  847. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  848. Last changed: 23 Nov 98
  849.