------ Not really Fido now is it? But with the advent of Internet I include this text. ------ From short!circuit!express.ior.com!cnn.isc-br.com!nwfocus.wa.com!camco!poweramp!news.dsource.com!news-out.internetmci.com!peerfeed.internetmci.com!panix!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon Sat Nov 23 15:44:58 1996 Path: short!circuit!express.ior.com!cnn.isc-br.com!nwfocus.wa.com!camco!poweramp!news.dsource.com!news-out.internetmci.com!peerfeed.internetmci.com!panix!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon From: raymoon@dgsys.com (Raymond Moon) Newsgroups: alt.lang.asm,comp.lang.asm.x86,news.answers,alt.answers,comp.answers Subject: x86 Assembly Language FAQ - General Part 1/3 Date: 20 Nov 1996 18:04:05 GMT Message-ID: <56vh6l$sl@news.dgsys.com> Followup-To: alt.lang.asm,comp.lang.asm.x86 Reply-To: raymoon@moonware.dgsys.com Organization: MoonWare Expires: Fri, 20 Dec 1996 23:59:59 GMT Distribution: world Keywords: x86 Assemby Language ASM FAQ General Summary: This is the FAQ for the x86 Assembly Language programmers for the alt.lang.asm and comp.lang.asm.x86 newsgroups. This particular section of the FAQ is part one of three parts that contain x86 assembly language information common to all assemblers. Approved: news-answers-request@MIT.EDU Lines: 808 Supersedes: <54gil5$v0i@news.dgsys.com> NNTP-Posting-Host: dgs.dgsys.com X-Newsreader: TIN [version 1.2 PL2] Xref: short alt.lang.asm:5663 comp.lang.asm.x86:15751 Archive-Name: assembly-language/x86/general/part1 Posting-Frequency: monthly (21st of every month) Last-modifieuency: monthly (21st of every month) d: 1996/11/20 ------------------------------ Subject: 1. Introduction and Intent This is the x86 Assembly Language FAQ for the comp.lang.asm.x86 and alt.lang.asm newsgroups. This FAQ is posted monthly on or about the 21st of the month on both newsgroups and news.answers, alt.answers and comp.answers. It also is archived at the normal FAQ archival sites and the SimTel mirror sites in the msdos/info directory. Lastly, the current version is available from my web page as: As text files: http://www2.dgsys.com/~raymoon/faq/asmfaq.zip As html documents: http://www2.dgsys.com/~raymoon/faq/asmfaqh.zip Currently, this FAQ is broken into six sections. The following are the section filenames and the scope of each section of the FAQ. assembly-language/x86/general/part1 - This is the basic portion of the FAQ that contains information of interest to all assembly language programmers. In general, the information contained in this portion of the FAQ is not specific to any particular assembler. assembly-language/x86/general/part2 - This is a continuation of the above FAQ. assembly-language/x86/general/part3 - This is a continuation of the above FAQ. assembly-language/x86/microsoft - This portion of the FAQ contains information specific for the Microsoft MASM. assembly-language/x86/borland - This portion of the FAQ contains information specific for the Borland TASM. assembly-language/x86/a86 - This portion of the FAQ contains information specific for the Shareware A86 Assembler and D86 Debugger. The scope and content of this FAQ is to go beyond just answering the frequently asked questions. I am including pointers to assembly language treasure troves that are hidden out on the internet. I believe that this will enhance the FAQ's value not only to the novices but also to the old hands. For the ease of determining what has changed since the last FAQ, the Table of Contents will have "REVISED" at the end of the subject line for all revised subjects. If more than one FAQ revision has been missed, the "Last Changed:" entry at the end of each subject can be used to determine which subjects have been revised during the intervening time frame. The information in this FAQ is free for all to use as long as you acknowledge the source. This FAQ can be reproduced in part or in its entirety as long as the copyright is included. This FAQ can be made available on public servers, like ftp, gopher or WWW servers. Please do not modify the file, such as converting it into some other format, without prior permission of the author. All references to files and locations are in Uniform Resource Locators (URLs) format. Some web browser will be able to use these URLs directly as hot links. If the format is not clear to you, get RFC 1738. It is available from: ftp://is.internic.net/rfc/rfc1738.txt Suggestions for changes and comments are always welcome. They can be posted to either newsgroup or e-mailed directly to the me. Author: Raymond Moon, raymoon@moonware.dgsys.com Copyright 1996 - Raymond Moon ALL RIGHTS RESERVED Last Changed: 13 Oct 96 ------------------------------ Subject: 2. Table of Contents Part I 1. Introduction and Intent 2. Table of Contents REVISED 3. Charters For comp.lang.asm.x86 and alt.lang.asm Newsgroups 4. What is Assembly Language 5. List of x86 OpCodes 6. What is HELPPC and Where It Is Available 7. How To Truncate a File 8. How Can STDERR Be Redirected To a File 9. How To Determine the CPU Type 10. IRQ Assignments 11. Ralf Brown's Interrupt List REVISED 12. Using VGA Mode 13h for Fast Graphics 13. Real Mode/Protected Mode 14. Shareware ASM Libraries REVISED Part II 15. How To Determine If a Problem Pentium Is Present DELETED 16. Accessing 4 Gegs of Memory in Real Mode 17. What Is Available at ftp.intel.com 18. Interrupts and Exceptions 19. ASM Books Available 20. ASM Code Available on Internet REVISED 21. How To Commit a File 22. Using Extended Memory Manager 23. EXE2BIN Replacement 24. ASM Tutorials Available 25. Shareware Assemblers Part III 26. WWW Assembly HomePages REVISED 27. Undocumented OpCodes 28. Common Reason Why Memory Allocation Fails 29. Volume Serial Numbers 30. .obj File Format 31. Rebooting from Software 32. Other FAQs 33. Pseudo Random Number Generator in Assembly Language 34. Command Line Arguments 35. Free 32-bit and DJGPP 36. TERSE Programming Language 37. Assembly Language IDEs REVISED 38. Disassemblers 39. How to Optimize for the Pentium 39. Acknowledgments ------------------------------ Subject: 3. Charters For comp.lang.asm.x86 and alt.lang.asm Newsgroups To know whether or not these newsgroups will meet your needs, the purpose for which they were created are given below. 3.1 COMP.LANG.ASM.X86 comp.lang.asm.x86 was created based upon voting on a Request for Discussion (RFD). The RFD for this newsgroup is: The unmoderated newsgroup comp.lang.asm.x86 is open to discussions on all topics related to assembly language and low-level programming on IBM machines with '86 processors. Appropriate topics would include, but not be limited to: Assembly language tips and tricks (code techniques) MASM, TASM, and other commercial assemblers Graphics, sound, and other hardware programming Assembly language code Assembly language related share/freeware Linking assembly language with other languages Etc... Topics that are discouraged are: Flames about "{Language X} is {better/worse} than ASM" Flames like "{Assembler 1} is {better/worse} than {Assembler 2}" High-level language code, except when used for hardware programming 3.2 ALT.LANG.ASM Alt newsgroups are initiated with a Proposal posting to the alt.config newsgroup. The proposal for alt.lang.asm is: alt.lang.asm will address the problems of machine language programmers out there in InterNet land. It will be a forum for discussion of coding techniques and efficiency problems related to machine language. The scope will be broad. We will not discriminate by machine architecture, race or sex. Contributors: Michael Averbuch, mikeaver@firefly.prairienet.org Raymond Moon, raymoon@moonware.dgsys.com Last changed: 28 Dec 94 ------------------------------ Subject: 4. What Is Assembly Language 4.1 WHAT IS MACHINE LANGUAGE? Although programmers tend to use C or C++ or Pascal these days, the language closest to the PC hardware is machine language. Not one second during a PCs powered on lifetime passes where the computer is not executing machine language. 4.2 ASSEMBLY LANGUAGE OR MACHINE LANGUAGE To word this simply, you can say that say that assembly language is a human-readable text, and machine language is machine-readable binary code. When you program in assembly language, you are programming on the machine language level. To program directly in machine language is teadious, so you use assembly language instead, and use an assembler to produce the actual machine code. 4.3 WHEN TO USE ASSEMBLY LANGUAGE I personally think that except as a learning exercise it's a waste of time writing something in asm that can be written acceptably fast in a high-level language. Assembly language fits for the following: * Low level control. When you need to change the flags, or the control registers of the processor, as when entering protected mode. * Speed. Programs written in machine language execute fast! It can execute 10-100 times the speed of BASIC, and about twice as fast as a program written in C or Pascal. * Time Critical Code. Critical sections of programs written in higher level languages, can be written in assembly to speed up sections. * Small program size. When you write a TSR for example this is very useful. Writing interrupt handlers is where assembly language shines. Assembly language is very flexible and powerful, anything that the hardware of the computer is capable of doing can be done in assembly. Contributor: Patrik Ohman, patrik@astrakan.hgs.se Last changed: 10 Jan 95 ------------------------------ Subject: 5. List Of x86 OpCodes To obtain a full listing of the instruction set, opcodes and instruction timing of the Intel processors, the book Pentium Family, User's Manual Volume 3: Architecture and Programming Manual ISBN 1-55512-227-12 is the best source of information. This book is available directly from Intel by calling or writing: Intel Literature Sales P.O. Box 7641 Mt. Prospect, IL 60056-7641 (800) 548-4725 Another source of information on the instruction set is the program HelpPC, see obtaining HELPPC elsewhere in this document. Contributor: Patrik Ohman, patrik@astrakan.hgs.se Last changed: 10 Jan 95 This information is available for instructions and opcodes up to 686 including FPU and MMX in the help from the IDE ASMEDIT found at: http://www.inf.tu-dresden.de/~ok3/asmedit.html You also can get the Intel book Pentium Pro Family, Developer's Manuals part #242691 and #242692 Last changed: 20 Sep 96 ------------------------------ Subject: 6. What Is HELPPC and Where Is It Available HELPPC is a Quick Reference Utility for the intermediate to advanced programmer. It is a shareware program written by David Jurgens. The latest version is 2.10 The topics distributed in an easy database format are: BIOS interrupts; DOS interrupts and DOS functions; EMS and Mouse functions; BIOS and DOS data structures; diagnostic codes; DOS commands; 80x86 assembler instructions; standard and vendor specific C functions; and various hardware specifications. HELPPC is customizable by users. The documentation describes how users can incorporate their own information into the help file format. These user help files then can be incorporated into the database and accessed via HELPPC application. HELPPC comes in two versions. The first is a DOS command line program. The second is a TSR. The TSR supports context sensitive help within many editors. Only 32K is taken by the TSR version. HELPPC requires: DOS 2.0 or greater; 64K of RAM for DOS Command Line or 32K for TSR; and hard disk recommended. HELPPC is available specifically from: ftp://www.cdrom.com/pub/simtelnet/msdos/asmutil/helppc21.zip HELPPC also is available from any site that mirrors the SimTel directory. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 28 Dec 94 ------------------------------ Subject: 7. How To Truncate A File There is not any single DOS Int 21h function that performs this operation. A file can be truncated using two functions. The procedure is: 1. Use Int 21h function 42h, Move File Pointer, to move the file pointer to the position where you want the file to be truncated. 2. Use Int 21h function 40h, Write File or Device, to write zero bytes to the file. Execution of the last DOS function will update the directory to the new file length. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 28 Dec 94 ------------------------------ Subject: 8. How Can STDERR Be Redirected To A File I understand that 4DOS has this capability at its command line. If you are looking in the assembly language FAQ for this information, an assembly language answer probably is desired. Here it is. You will need to write a short program that performs the STDERR redirection before loading and executing the desired program. This loader program relies upon the fact that a child program inherits all open files of the parent program unless the parent program opens a file with the inheritance flag set to no. Because the full code for such a program is too large for this FAQ, I will give the salient specifications for such a program. 1. The loader program accepts three command line arguments: a. The full path and filename of the file into which STDERR is to be written. b. The full path and filename of the program to be executed. c. The command line for the program to be executed (should be delimited by double quotes to allow multiple arguments). This argument is optional. 2. Release all memory above the program using Int 21 function 4ah so that there will be room enough to load and execute the designated program. 3. Open the file from step 1.a above into which STDERR is to be written. 4. Duplicate STDERR filehandle, which is 2, using Int 21h function 45h. 5. Using Int 21h function 46h, force STDERR filehandle, again 2, to have the filehandle of the opened file from step 2. 6. Use Int 21h function 4b00h to load and execute the program from step 1.a. Use the default environment and the command line from step 1.c above. 7. Upon return from the function 4b00h, close the file opened in step 2. 8. To restore STDERR, use Int 21h function 46h to force STDERR, again 2, to point to the filehandle saved from step 3 above. This same technique can be applied to any of the standard devices. I have written a full featured demonstration program. I believe that asm programmers will find the source code useful even if they do not want to redirect stderr to a file. The URL to the file is: ftp://www.cdrom.com/pub/simtelnet/msdos/asmutil/stderrf.zip Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 3 Jun 95 ------------------------------ Subject: 9. How To Determine The CPU Type 9.1 CPUID PROGRAM The type of processor and math coprocessor can be determined using two functions that have been provided by Intel. The source code to these functions can be obtained from Intel by: ftp://ftp.intel.com/pub/IAL/tools_utils_demos/cpuid3.zip Three source files are included in this .zip file. cpuid3a.asm - This source code file contains two assembly language functions. One determines the type of cpu from 8088/8086 to Pentium. The second detects and identifies, if present, the type of math coprocessor. cpuid3b.c - a c program that calls the above two functions and displays the results. cpuid3c.asm - this is an assembly program equivalent to cpuid3b.c. 9.2 CPUID INSTRUCTION On some 486 and all Pentium processors, Intel has included an undocumented CPUID instruction. More information on this instruction and how to tell if a processor supports this instruction, see Ralf Brown's OPCODE.LST, Subject #11). You also can get the word directly from Intel ftp://ftp.intel.com/pub/IAL/Software_specs/cpuap.zip The file in the .zip file describes the CPUID instruction, explains the evolution of CPU detections strategies and includes the source code for the CPUID program. UNFORTUNATELY, the format for the file is a postscript print file. To get a human readable copy, it must be sent to a postscript viewer or printer! 9.3 Robert Collins' CPUID.ASM This code was a beta test that was inadvertently made available. It no longer is available. 9.4 Grzegorz Mazur's x86 CPU Identification Grzegorz has a series of hypertext articles that explain x86 CPU identification algorithms developed by himself. Covered are not only the Intel chips but also V20, V30 (remember them), and Cyrix and alikes. His page is located: http://grafi.ii.pw.edu.pl/gbm/x86/index.html Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 19 Apr 96 ------------------------------ Subject: 10. IRQ Assignments A list of IRQ assignments are available in David Jurgens' HELPPC database. See Subject #6 for details on how to obtain this program. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 28 Dec 94 ------------------------------ Subject: 11. Ralf Brown's Interrupt List REVISED 11.1 FILE AVAILABILITY The latest version of Ralf Brown's Interrupt List is 5.1, dated 28 Jul 96. The files are available directly from his home page, from SimTel, or Garbo: http://www.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/WWW/files.html ftp://ftp.coast.net/SimTel/msdos/info ftp://garbo.uwasa.fi/pc/programming The files are: inter52a.zip Comprehensive listing of interrupt calls, 1of4 inter52b.zip Comprehensive listing of interrupt calls, 2of4 inter52c.zip Comprehensive listing of interrupt calls, 3of4 inter52d.zip Comprehensive listing of interrupt calls, 4of4 inter52e.zip Utility progs/source code for interrupt list inter52f.zip WinHelp conversion programs for interrupt list inter52g.zip Hypertext conversion progs. for interrupt list Above available from all sites. Below files are available from SimTel inter52z.zip HC31/HCP phrases file for interrupt list intwin52.zip WINHELP hypertext 11.2 DESCRIPTION The interrupt list is a comprehensive listing of functions available through interrupt calls and FAR calls, both documented and (officially) undocumented, plus maps of CMOS and BIOS memory and I/O ports. This release contains more than 8100 entries and nearly 3300 tables. 11.3 WHAT IS NEW Version 5.0: Windows95 long-filename functions, Windows95 new IOCTL functions, Tandy 2000 BIOS, .CPI-file format, AWARD/Asustek/AMI Flash BIOS interfaces, Cyrix 5x86 configuration registers, DOS32 v3.2, NOISE.SYS v0.53 API, AMIS v3.6, and more. Version 5.1 COMBINE.BAT has been replaced by COMBINE.COM. New info includes PCMCIA v2, Player's Tool, ShowGFX, Iomega, additional virus checks, OS/2 INT 21h, and various miscellaneous updates. Version 5.2 Three new hypertext conversion programs (for WinHelp, ASMEdit, and Turbo Pascal) and a new text file MSR.LST. INTLIST.E has been enhanced, a repeated error in Novell NetWare multiplexor functions has been corrected, and a variety of incorrect cross-references has been fixed. New info includes APM v1.2, TI Professional PC BIOS, Cherry keyboard chipcard reader, KeyRus, Volkov Commander, and XPACK. 11.4 INTWIN.HLP INTWIN.HLP was compiled from Ralf Brown's Interrupt List with Christian Mueller Planitz's and Bent Lynggaard's INT2WHLP program to a hypertext format of the List. Most of the supplementary *.LST files in the Interrupt List are included in INTWIN.HLP. INTWIN displays table references in a secondary window to ease the reference between the source and the referenced text. The package includes an editor to edit the secondary window size as appropriate for the graphics platform used. INTWIN has extensive search facilities with almost 30,000 keywords (below WinHelp 4.00's keyword limit) for search on interrupt numbers, register contents, interrupt categories, and topic headings. The package includes also a full text search facility. 11.5 INTWIN.PH INTWIN.PH is a phrases (Windows help file compression information) file compiled from Ralf Brown's Interrupt List with Christian Mueller Planitz's and Bent Lynggaard's INT2WHLP program. Most of the supplementary *.LST files in the Interrupt List were included in the compilation. The phrases file is used by the HC31 and HCP help file compiles when compiling in high compression mode. The compilation of this phrases file requires more DOS memory and disk space than is easily available on many computers (630-730 kb and 38-52 Mb). 11.6 OTHER INCLUDED GEMS OVERVIEW.LST - A brief description of each of the 256 interrupts. 86BUGS.LST - A list of undocumented and buggy instructions with descriptions of the x86 Intel processor and compatible processors. And you thought that the Intel FDIV was the first bug in a processor! CMOS.LST - a CMOS memory map. OPCODE.LST - A list of undocumented instructions and documented instructions of any last processor. PORTS.LST - I/O port addressed for XT, AT and PS/2 computers. GLOSSARY.LST - glossary of PC terms. MEMORY.LST - The format for various memory locations, such as the BIOS Data Segment, Interrupt Vector Table, and much, much more. INTERRUP.PRI - iAPX 86 Interrupt Primer Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 21 Oct 96 ------------------------------ Subject: 12. Using VGA Mode 13h for Fast Graphics 12.1 INTRODUCTION AND PREPARATION Mode 13h is so widely used for graphics applications in DOS because it is very easy to use. The screen is constantly being redrawn by the video card. To affect what the card draws, it is necessary to write to the screen buffer. The screen buffer in mode 13h is always at segment:offset = A000:0000. Thus, to set up drawing directly to the video buffer, this is what you'd most often first do: ;Change the video mode to 13h xor ah, ah ;VIDEO Function 00h: Change screen mov al, 13h ;Put the desired graphics mode into AL int 10h ;Call VIDEO ;Prepare for writing to the video buffer mov di, 0a000h ;Put the video segment into DI mov es, di ; so it can easily be put into ES xor di, di ;Start writing at coordinates (0,0) 12.2 WRITING PIXELS TO THE SCREEN Why is Mode 13h so popular? To understand, you must know a few basic facts. In Mode 13h, the screen is 320 by 200, or 320 pixels across and 200 pixels down. In each pixel, there's a possibility of 256 colors, which can be fit into one byte. Thus, 320*200*1 = 64000 bytes, about the size of one segment. Think of the screen as an array of colors. The first row takes up addresses A000:0000 to A000:013F (decimal 319), the second row takes up addresses A000:0140 to A000:027F (decimal 639), and so on. To plot a pixel, assuming ES=A000: ;Plot a pixel in video mode 13h, where ;PixelAddress = (320 * Y) + X mov ax, 320 ; Prepare for the multiplication mul [Y] ; Assuming that Y is defined in the data segment ; earlier in the program mov di, ax ; Put in into the pointer to the offset of ES add di, [X] ; Assuming that X is defined in the data segment ; earlier in the program mov al, [Color] ; Assuming that Color is defined in the data ; segment earlier in the program stosb ; Write it to the screen! See how easy that was? Something to remember is that it is zero-based. The upper-left corner is (0,0), and the lower-right is (319,199). A complete TASM Ideal mode procedure might look something like this (it assumes that the video card is already set to mode 13h): PROC WritePixel BASIC ; Or whatever language you might want to link ; it to USES es, di ; It's always a good idea to preserve ES and DI ARG X:word, Y:word, Color:BYTE mov di, 0a000h ; Put the video segment into DI mov es, di ; so it can easily be put into ES mov ax, 320 ; Prepare for the multiplication mul [Y] ; Offset pointer by the Y value passed in mov di, ax ; Put in into pointer to the offset of ES add di, [X] ; Offset the pointer by the X value passed in mov al, [Color] ; Put color to be written to the screen in AL stosb ; Write it to the screen! ret ENDP WritePixel To write a horizontal line, just put the length in CX, and replace the STOSB with a REP STOSB. Writing a vertical line is only a little more tricky. Observe the following TASM Ideal mode procedure: PROC VerticalLine BASIC ; Or whatever language you might want to link ; it to USES es, di ; It's always a good idea to preserve ES and ; DI ARG X:word, Y:word, Color:BYTE, Length:word mov di, 0a000h ; Put the video segment into DI mov es, di ; so it can easily be put into ES mov ax, 320 ; Prepare for the multiplication mul [Y] ; Offset the pointer by the Y value passed in mov di, ax ; Put in into the pointer to the offset of ES add di, [X] ; Offset the pointer by the X value passed in mov al, [Color] ; Put the color to be written to the screen ; in AL mov cx, [Length] ; Prepare for the loop YLoop: stosb ; Write it to the screen! add di, 319 ; Move down one row (DI has already advanced ; once because of the STOSB, thus the 319) loop YLoop ret ENDP VerticleLine Observe how there is a tight loop that moves DI down one row each iteration. In short, the easiest way to write directly to the Mode 13h video buffer is to think of the screen as just a 320 by 200 array of bytes, starting at A000:0000. Author: Michael Averbuch (mikeaver@prairienet.org) Last Change: 29 Dec 94 ------------------------------ Subject: 13. Real Mode/Protected Mode 13.1 AVAILABILITY [Note: because of a crash at zfja-gate, the below information of files on zfja-gate may not be accurate.] All the files below are available from: ftp://zfja-gate.fuw.edu.pl/user/net/ka9q/guest/cpu/protect.mod The authors e-mail addresses are given below. These files can be received by e-mail. Send e-mail to: listserv@zfja-gate.fuw.edu.pl with GET CPU/PROTECT.MOD/PMFAQ/* in the text. A .zip file with all the latest files described below has been uploaded to SimTel but as of 19 Dec has not been made available for download. The URL to this file when available should be: ftp://ftp.coast.net/SimTel/msdos/info/pmtut0002.zip Watch this site or for the upload announcement in the newsgroups. 13.2 FAQ - PMFAQ.ZIP This file contains a preliminary protected mode FAQ by Jerzy Tarasiuk. 13.3 TUTORIAL - PMTUT002.ZIP Till Gerken has written a Protected Mode Tutorial. This tutorial contains code and applicable function calls that comprise the Virtual Control Program Interface (VCPI). Till Gerken's tutorial is available: ftp://x2ftp.oulu.fi/pub/msdos/programming/pmode/pmtut002.zip 13.4 SAMPLE ASM CODE - SIMPL_PM.ASM Jerzy Tarasiuk has posted an example program switching to Protected Mode and back to again to Real Mode. 13.5 REAL MODE IDT SWITCHING - CHANGIDT.FAQ Lastly Jerzy Tarasiuk has included some of his e-mail that covers real mode IDT switching. Contributors: Till Gerken and Jerzy Tarasiuk Last changed: 19 Dec 95 ------------------------------ Subject: 14. Shareware ASM Libraries 14.1 ASMLIB PROGRAMMER'S TOOLKIT, VERSION 4.0 Douglas Herr's shareware assembly language library. This library is available from SimTel. ftp://www.cdrom.com/pub/simtelnet/msdos/asmutil/asmlib40.zip The zip file contains only the medium model of the library. There are 405 assembly subroutines in a .lib file and documentation. Source code is available with registration and extra fee. The library covers the following areas: string/integer data manipulation screen mode subroutines text-mode multi-window subroutines disk & file subroutines text-mode video subroutines EMS and XMS subroutines floating-point subroutines graphics keyboard input subroutines mathematical solutions subroutines which determine PC status asmlib40 also comes with an editor, E16, written entirely with asmlib. Improvements since version 3.7 is auto-sizing of the near heap in the startup code. There have been some incremental improvements including 32k-color graphics and virtual graphics screens. 14.2 THE ASSEMBLY WIZARD'S LIBRARY, VERSION 2.1 REVISED This is Chris Walker's shareware assembly language library. This library used to be Thomas Hanlin's. ftp://www.cdrom.com/pub/simtelnet/msdos/asmutil/asmwiz21.zip This library comes with documentation and one .lib file that supports small and tiny memory models. Source code is available with registration. The library covers the following areas: Base Conversions Mouse Services Exception Handling Sound and Music Delays and Countdowns String Services File Handling Telecommunications Filename Manipulation Time and Date Keyboard Services Video Services Long Integer Math Miscellaneous Services Memory Services 14.3 UCR Standard Library for Assembly Language Programmers REVISED This library is written by Randall Hyde and others. This library is available from many sites but most of them are seriously out of date. You can get the latest version at: http://webster.ucr.edu/ (Server currently down - will revise for next FAQ.) Unlike the previous libraries, there are no registrations fees and the included source code is released to the public domain. The author does request that if you use the library, you contribute at least one routine to the library. Standard Input Routines Character Set Routines Standard Output Routines Memory Management Routines Conversion Routines String Handling Routines Utility Routines 14.4 ALIB Version 3.0 ALIB is Jeff Ownens' shareware assembly language library. This library is available from SimTel. ftp://ftp.coast.net/SimTel/msdos/asmutil/alib30.zip Like the UCR library described above, registration fees are not requested. The library consists of 179 assembly source files covering the following areas: compress - data compression and expansion config - program configuration, colors, paths, etc. compare - compare strings convert - hex/decimal/ascii conversions database - simple database functions disk - disk information, path changes, file searches display - fast display functions, write to display memory error - error handlers float - simple floating point math package math - dword math, crc, roots memory - memory manager, extended, xms, ems, conventional menu - menuing system message - messages in windows on screen misc - misc routines mouse/key - mouse and keyboard functions parse - extraction of parameters from command line random - random number generators search - search for character or string sort - sort buffer or file sound - sounds string - ascii string handling stdout - characters, strings, spaces to stdout system - system interrogation and setup time - time and date conversions 14.5 FREELIB, Version 2.2 FREELIB is a library of 170 assembly language procedures written by Tenie Remmel. Full source code is available and is written for the 80186 processor using the TASM ideal mode. Lastly, the procedures use the Pascal calling protocol. As the name implies, the author place the library into the public domain, completely free for all non-commercial use. If you find this library useful, users are strongly encouraged to contribute some of your own routines for possible addition to FREELIB. The library is available from SimTel: ftp://www.cdrom.com/pub/simtelnet/msdos/asmutil/freeli22.zip Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 20 Nov 96 From short!circuit!express.ior.com!cnn.isc-br.com!nwfocus.wa.com!camco!poweramp!news.dsource.com!news-out.internetmci.com!peerfeed.internetmci.com!howland.erols.net!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon Sat Nov 23 15:45:18 1996 Path: short!circuit!express.ior.com!cnn.isc-br.com!nwfocus.wa.com!camco!poweramp!news.dsource.com!news-out.internetmci.com!peerfeed.internetmci.com!howland.erols.net!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon From: raymoon@dgsys.com (Raymond Moon) Newsgroups: alt.lang.asm,comp.lang.asm.x86,news.answers,alt.answers,comp.answers Subject: x86 Assembly Language FAQ - General Part 2/3 Date: 20 Nov 1996 18:04:58 GMT Message-ID: <56vh8a$sl@news.dgsys.com> Followup-To: alt.lang.asm,comp.lang.asm.x86 Reply-To: raymoon@moonware.dgsys.com Organization: MoonWare Expires: Fri, 20 Dec 1996 23:59:59 GMT Distribution: world Keywords: x86 Assemby Language ASM FAQ General Summary: This is the FAQ for the x86 Assembly Language programmers for the alt.lang.asm and comp.lang.asm.x86 newsgroups. This particular section of the FAQ is part two of three parts that contain x86 assembly language information common to all assemblers. Approved: news-answers-request@MIT.EDU Lines: 833 Supersedes: <54gimb$v0i@news.dgsys.com> NNTP-Posting-Host: dgs.dgsys.com X-Newsreader: TIN [version 1.2 PL2] Xref: short alt.lang.asm:5665 comp.lang.asm.x86:15753 Archive-Name: assembly-language/x86/general/part2 Posting-Frequency: monthly (21st of every month) Last-modified: 1996/11/20 ------------------------------ Subject: 15. How To Determine If A Pentium With The FDIV Problem Is Present As this subject is dated and to conserve space, this subject has been removed. This announcement will be kept in the FAQ through the December FAQ. The program will be available at my shareware web site: http://www2.dgsys.com/~raymoon/files/penerr.zip Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 13 Oct 96 ------------------------------ Subject: 16. Accessing 4 Gigs of Memory in Real Mode Flat real mode is a popular name for a technique used to access up to 4 GB of memory, while remaining in real mode. This technique requires a 80386 or higher processor. The address space really is not flat, actually, this technique allows you treat one or more segments as large (32-bit) segments, thereby accessing memory above 1 MB. When the CPU accesses memory, the base address of the segment used is not described by the value currently in the appropriate register. The value is stored internally in a structure known as the descriptor cache. Changing the value of a segment register results in that segment's entry in the descriptor cache being recalculated according to the rules of the current mode. In real mode, the value of the segment register is shifted left four bits to find the base address of the segment, and the size of the segment is always 64k. In protected mode, the value in the segment register is used as an index into a descriptor table located in memory, and the base address and size (which may be as small as 4 KB, or as large as 4 GB) from the descriptor table are loaded into the descriptor cache. When the processor changes modes, the contents of the processor's internal descriptor cache are not changed. The reason is because changing them would result in (at the very least) the code segment being recalculated according to the new mode's rules, most likely causing your program to crash. Thus the program must load the segment registers with sensible values after the mode switch occurs. Consider an example where real mode code is located in segment 1000h. If switching modes caused an immediate recalculation of the descriptor cache, the processor would attempt to read entry 1000h of the descriptor table immediately upon switching to protected mode. Even if this were a valid descriptor (unlikely), it would have to have a base address identical to real mode segment 1000h (i.e., 10000h), and a size limit of 64 KB to prevent a probable crash. An invalid descriptor would cause an immediate processor exception. Normally, aside from preventing situations like that in the above example, there is little to be said about this feature. After all, as soon as you reload new values into the segment register, the descriptor cache entry for that segment will be reset according to the rules of the current mode. After switching from protected mode to real mode, however, when you load the segment registers with their new values, the segment's base address is recalculated according to real mode rules, but the size limit is not changed. After setting the 4 GB limit (which must be done in protected mode), it will stay in place until changed by another protected mode program, regardless of what values are loaded in the segment register in real mode. So, the steps to using this technique are as follows: 1. Set up a bare bones global descriptor table, with a null entry, and a single entry for a 4 GB segment. The base address of this segment is not important. 2. If you don't wish to define an interrupt descriptor table (IDT), you must disable interrupts before switching to protected mode. You do not need a full-fledged protected mode environment for this, so it is easiest just to disable interrupts and not worry about the IDT. 3. Switch to protected mode. 4. Load the segment registers you wish to change with the selector for the 4 GB segment. I recommend using FS and/or GS for this purpose, for reasons I'll describe below. 5. Return to real mode. 6. Re-enable interrupts. After these steps, you can then load your segment registers with any value you wish. Keep in mind that the base address will be calculated according to real mode rules. Loading a value of 0 into a segment register will result in a 4 GB segment beginning at physical address 0. You can use any of the usual 32-bit registers to generate offsets into this segment. Some points to keep in mind: 1. Some software depends on 64 KB segment wrap-around. While rare, it is possible that you will encounter software that crashes if the older segments (DS or ES) are 4 GB in size. For that reason, I recommend only using FS and/or GS for this purpose, as they are not used as widely as the others. 2. You should never change the limit of the code segment. The processor uses IP (not EIP) to generate offsets into the code segment in real mode; any code beyond the 64 KB mark would be inaccessible, regardless of the segment size. 3. You should never change the limit of the stack segment. This is similar to the above; the processor uses SP in real mode, rather than ESP. 4. Because of the necessity of switching to protected mode, this technique will not work in a virtual 8086 mode "DOS box" from Windows, OS/2, or any other protected mode environment. It only works when you start from plain, real mode DOS. Many memory managers also run DOS in V86 mode, and prevent the switch to protected mode. It is possible to use VCPI to work around this, but if you go to that length you will probably find that you have implemented a complete protected mode environment, and would not need to return to real mode anyway. 5. This technique will not work in the presence of any protected mode software that changes segment size limits. When that software returns control to your real mode program, the limits will be the values to which the protected mode code set them. If these limits are different that what your program used, problems can result. At the very least, your program will return incorrect results when accessing data stored in extended memory. At worst, your program will crash and burn. The benefits of this technique are many. Most importantly, you can access extended memory without resorting to slow BIOS calls or having to implement a complete DOS extender. If your program uses interrupts extensively (timer interrupts for animation or sound, for example), real mode is a better choice because protected mode handles interrupts slower. DOS itself uses this technique in HIMEM.SYS as a fast, practical method of providing access to extended memory. Code demonstrating this technique is available in the file, realmem.zip. This file is available using anonymous ftp from x2ftp.oulu.fi in the directory, pub/msdos/programming/memory. For further reading on this topic, I suggest "DOS Internals," by Geoff Chappell. It is published by Addison-Wesley as part of the Andrew Schulman Programming Series. The ISBN number is 0-201-60835-9. Contributor: Sherm Pendley, grinch@access.mountain.net Last changed: 15 Jan 95 ------------------------------ Subject: 17. What Is Available at ftp.intel.com To obtain a description of the files available at Intel: ftp://ftp.intel.com/pub/IAL get libdir.txt Most of the files are press releases, but there are some hidden jewels. Search for and read the files under the Intel386, Intel486 and Pentium subdirectories. Here are a sample of files that may be of interest (path from IAL subdirectory is given): Pentium/opt32.doc - Optimizations for Intel's 32-bit processors in MS Word format. Pentium/pairng.txt - Instruction pairing optimization for Pentium processor - text format. Pentium/p5cpui.txt - new official CPU identification scheme - text format. Pentium/p5masm.mac - MASM macros for instructions new with Pentium Tools_Utils_Demos/prot.txt - MASM code for entering protected mode - text format. Intel486/2asm10.zip - C source for 8086-80486 16/32 bit disassembler - pkzip format. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 8 Jan 95 ------------------------------ Subject: 18. Interrupts and Exceptions "(with interrupts) the processor doesn't waste its time looking for work - when there is something to be done, the work comes looking for the processor." - Peter Norton INTERRUPTS AND EXCEPTIONS Interrupts and exceptions both alter the program flow. The difference between the two is that interrupts are used to handle external events (serial ports, keyboard ) and exceptions are used to handle instruction faults, (division by zero, undefined opcode). Interrupts are handled by the processor after finishing the current instruction. If it finds a signal on its interrupt pin, it will look up the address of the interrupt handler in the interrupt table and pass that routine control. After returning from the interrupt handler routine it will resume program execution at the instruction after the interrupted instruction. Exceptions on the other hand are divided into three kinds. These are Faults, Traps and Aborts. Faults are detected and serviced by the processor before the faulting instructions. Traps are serviced after the instruction causing the trap. User defined interrupts go into this category and can be said to be traps, this includes the MS-DOS INT 21h software interrupt, for example. Aborts are used only to signal severe system problems, when operation is no longer possible. See the below table for information on interrupt assignments in the Intel 386, 486 SX/DX processors, and the Pentium processor. Type specifies the type of exception. _____________________________________________________________________ Vector number Description _____________________________________________________________________ 0 Divide Error (Division by zero) 1 Debug Interrupt (Single step) 2 NMI Interrupt 3 Breakpoint 4 Interrupt on overflow 5 BOUND range exceeded 6 Invalid Opcode 7 Device not available (1) 8 Double fault 9 Not used in DX models and Pentium (2) 10 Invalid TSS 11 Segment not present 12 Stack exception 13 General protection fault 14 Page fault 15 Reserved 16 Floating point exception (3) 17 Alignment check (4) 18 - 31 Reserved on 3/486, See (5) for Pentium 32 - 255 Maskable, user defined interrupts _____________________________________________________________________ (1) Exception 7 is used to signal that a floating point processor is not present in the SX model. Exception 7 is used for programs and OSes that have floating point emulation. Also the DX chips can be set to trap floating point instructions by setting bit 2 of CR0. (2) Exception 9 is Reserved in the DX models and the Pentium, and is only used in the 3/486 SX models to signal Coprocessor segment overrun. This will cause an Abort type exception on the SX. (3) In the SX models this exception is called 'Coprocessor error'. (4) Alignment check is only defined in 486 and Pentiums. Reserved on any other Intel processor. (5) For Pentiums Exception 18 is used to signal what is called an 'Machine check exception'. The other interrupts, (32-255) are user defined. They differ in use from one OS to another. For a list of MS-DOS interrupts, see 'Obtaining HELPPC' (Subject #6) or Ralf Browns Interrupt List (Subject #11) Contributor: Patrik Ohman, patrik@astrakan.hgs.se Last changed: 10 Jan 95 ------------------------------ Subject: 19. ASM Books Available The format is Author, Title, Level, and short description Ray Duncan Advanced MSDOS Programming Advanced Both a tutorial and a reference for MS-DOS capabilities and services, including reference sections on DOS function calls, IBM ROM BIOS, mouse driver and LAM. expanded memory. Excellent quality example programs throughout. By Peter Norton and John Socha Peter Norton's Assembly Language Book For the IBM PC Novice Good for an introduction to Assembly Language. Plenty of programming examples. Older versions of this book used to have a sample disk. As you read the book, you slowly add on code to what eventually is Disk Patch - the book's version of Norton's commercially available Disk Edit program. Great for complete beginners seeking novice rank. Maljugin, Izrailevich, Sopin, and Lavin The Revolutionary Guide to Assembly Language Novice This is one of the best introductory texts I've ever seen There are so many authors that the topic is broken down into specific categories: video, BIOS, keyboard, etc.. Most intro texts force you to follow a set plan of learning assembly, but in this book you can turn to a specific topic almost immediately. It's so-so as a reference book, however - a few tables of interrupts in the back. Maljugin, Izrailevich, Sopin, and Lavin Master Class Assembly Language Advanced Review: This is the sequel to The Revolutionary Guide To Assembly Language. Equally thick and massive, it covers many of the topics we see today - hardware interfaces, sound cards, data compression, even protected mode programming. Brief review of assembly at the beginning, but moves very quickly. Read this if you're intermediate seeking expert status. Definitely not recommended for beginners. If you are a beginner and you think you like the topics covered in this book, buy the one before it too. Also comes with a disk of source code examples from the book (MASM highly recommended, not TASM). Alan Wyatt Advanced Assembly Language Advanced This book's best feature is its comprehensive guide on device drivers. There are good chapters on controlling the mouse, file access, using memory, etc. Ralf Brown and Jim Kyle PC Interrupts - 2nd Edition Intermediate/Advanced The definitive book on interrupt programming for PCs and compatibles. Based on the freeware Interrupt List by Ralf Brown For an extensive book list without descriptions, point your web browser to http://alaska.net/~rrose/assembly.htm Sites with more books but no reviews are: http://www.fys.ruu.nl/~faber/Amain.html http://www.cet.com/~jvahn/80xbook.html (short descriptions) Contributors: Antonio Alonso, Solomon Chang, Paul Gilbert, Dave Navarro, Mike Schmit and James Vahn. Last changed: 19 Dec 95 ------------------------------ Subject: 20. ASM Code Available On The Internet 20.1 SIMTEL SITES The SimTel has a directory devoted to assembly language. ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutil or http://simtel.coast.net/SimTel/ 20.2 80xxx Snippets REVISED Fidonet's echo for 80xxx programming has a collection of code that is maintained by Jim Vahn, jvahn@short.circuit.com. The collection is available via mail based archive server or Fidonet file requests to 1:346/15. To get a list of files available via e-mail, send an empty message to files@circuit.com. The server will return a list of all files available and instruction on how to retrieve them. The assembly language snippets dated before Mar 93 are available in one zip file at the above SimTel sites under the filename 80XXX393.ZIP. The Snippets are now on the web. In addition to downloading the snippets there is an assembly language related book list. The URL is: http://www.cet.com/~jvahn 20.3 X2FTP.OULU.FI This ftp site, x2ftp.oulu.fi, has some asm source code not available at the SIMTEL sites. The following describes some directories and the type of information that is available in them. /pub/msdos/programming/pmode - protected mode utilities and some source code. /pub/msdos/programming/source - some asm code /pub/msdos/programming/prgsrc - some asm code 20.4 FTP.X86.ORG This ftp site contains much of the code and information available from Robert Collins' web site. ftp://ftp.x86.org/x86 20.5 OMEN.COM Omen has assembly language source available from its web site. The address is: http://www.omen.com.au/Files/hdisk/asm.html Much of the code is archived in the .arj format. You will need the appropriate expansion program. One is available: ftp://ftp.coast.net/SimTel/msdos/archiver/arj242b.exe 20.6 JUMBO JUMBO is the Official Web Shareware Site. It has a directory devoted to assembly language source code, libraries and utilities: http://www.jumbo.com/prog/dos/asmutil 20.7 THE REEF This FTP site has source code and information that I have not found elsewhere. Unfortunately, many of the files are compressed using arj and lzh. ftp://future.dreamscape.com/pub/thereef/asm I received a reply and the service provider does not know where it went. Does anyone know? 20.8 PC GAMES PROGRAMMER ENCYCLOPEDIA This encyclopedia is a collection of files related to game programming. Many of these files contain programming examples. Topics included are ASM tutorial, VGA and SVGA programming information, graphic algorithms, graphic file formats, soundcard and other PC hardware programming information. This encyclopedia is available online at the PC-GPE web page: http://www.qzx.com/pc-gpe/ 20.9 PROGRAMMERS DISTRIBUTION NETWORK ASSEMBLY LANGUAGE FILES These files appear to be a mirror of the assembly-related files distributed on FidoNet by PDN. There is one there that is a must if you want to write asm winNT and win95 applications. It is walk32_1.zip. Walk32 is a complete app and dll development kit with linker and includes files, libraries, tools, and lots of samples. MASM 6.x required. http://www.thepoint.net/~jkracht/pdnasm.htm 20.10 NEW ASSEMBLY SNIPPETS COLLECTION, Version 1.1 This is a large collection of assembly language code and documentation. There are many useful programs and routines, and much information on various subjects related to assembly language. The collection is available from: ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutil/asnip11.zip 20.11 PROGRAMMING - ASSEMBLY/BASM/TASM This site consist of 59 pages of assembly language related files. Many files I have not seen any where else. The only problem is that there are only five to eight files described per page. The URL to the first page is: http://www.aquila.com/menu2/area02/dr1-1.htm Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 2 Nov 96 ------------------------------ Subject: 21. How To Commit A File The easiest solution is to open or create the file to be committed using Int 21h function 6ch, extended open/create. The BX register contains the desired Open Mode. One option that can be or'ed into this register is what Microsoft calls, OPEN_FLAGS_COMMIT, that has the value of 4000h. Using this option caused DOS to commit the file after each write. This function has been available (documented) since DOS 4.0. If you do not want to commit the file at each write but only when certain conditions are met, use Int 21h function 68h, commit file. The functions has been available (documented) since DOS 3.3. If you need to support versions of DOS before 3.3, the following technique will flush the all stored data without closing and opening the file. It is the opening of the file that is time consuming. 1. Use 21h function 45h to create a duplicate file handle to the file to be flushed. 2. Close that duplicate file handle. This technique will work all the way back to DOS 2.0. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 30 Jan 95 ------------------------------ Subject: 22. Using Extended Memory Manager 22.1 HOW TO USE XMS XMS usage - short recipe: 1. Verify have at least 286 (pushf; pop AX; test AX,AX; js error). 2. Verify vector 2Fh set (DOS 3+ sets it during boot). 3. AX=4300h, int 2Fh, verify AL=80h (means XMS installed). 4. AX=4310h, int 2Fh, save ES:BX as dword XmsDriverAddr. 5. AH=8, call [XmsDriverAddr] - returns ax=largest free XMS memory block size in kB (0 if error). 6. AH=9, DX=required size in kB, call [XmsDriverAddr] - allocates memory (returns handle in DX - save it). 7. AH=0Bh, DS:SI->structure { dword size (in bytes and must be even), word source_handle, dword source_offset, word destination_handle, dword destination_offset } (if any handle is 0, the "offset" is Real Mode segment:offset) 8. AH=0Fh, BX=new size in kB, DX=handle, call [XmsDriverAddr] - changes memory block size (without losing previous data). 9. AH=0Ah, DX=handle, call [XmsDriverAddr] - free handle and memory. Initially, should process #1-#6, then can use #7 to put data in/get data from XMS memory, or #8 to change XMS memory block size. On exit use #9 to free allocated memory and handle. Hint: handle cannot be 0, since zero is used as "no handle allocated" value. Errors for XMS calls (except AH=7 - Query A20) are signaled by AX=0. Error code returned in BL, few codes can check for are: 80h - not implemented, 81h - VDISK detected (and it leaves no memory for XMS), 82h - A20 error (e.g. fail to enable address line A20), A0h - all allocated, A1h - all handles used, A2h - invalid handle, A3h/A4h - bad source handle/offset, A5h/A6h - bad destination handle/offset, A7h - bad length, A8h - overlap (of source and destination areas on copy), A9h - parity error (hardware error in memory), ABh - block is locked, 00h - OK For more info read INT 2Fh, AH=43h in Ralf Brown interrupt list. 22.2 WHAT IS THE 'LINEAR BLOCK ADDRESS' RETURNED BY LOCK MEM BLOCK? When you lock mem block, XMS driver arranges memory governed by it in a way the locked block forms one contiguous area in linear address space and returns you starting address of the memory. Linear address is base address of segment + offset in segment, in Real Mode it is segment*16+offset, in Protected Mode the base address is kept in LDT or GDT; note offset can be 32-bit on 386+. If paging isn't enabled, linear address = physical address. You don't need the linear address unless you use 32-bit offsets in Real Mode or you use Protected Mode (see previous answer for explanation of how you can access XMS memory). Contributor: Jerzy Tarasiuk, JT@zfja-gate.fuw.edu.pl Last Changed: 30 Jan 95 ------------------------------ Subject: 23. EXE2BIN Replacement A utility, EXE2BIN, used to be included in DOS. This utility was needed to convert the output of the linker from .EXE to .COM format because the linkers could not do this directly. As linkers became more capable, the need for this utility vanished, so EXE2BIN was dropped from DOS. If you still are using an older assembler and linker, you now have been left out in the cold. Well, not quite, as there are three shareware equivalent programs. 23.1 EXECOM14.ZIP EXECOM was written by Chris Dunford in C. The .zip file contains the executable, documentation and the .c source that Chris Dunford has released into the public domain. The current version is 1.04 with a 2 Mar 88 date. 23.2 BIN.ZIP This replacement version was written by Bob Tevithick. It is based upon versions 1.00 of Chris Dunford's program. The .zip file contains only the executable and documentation. No source is included. 23.3 X2B11.ZIP X2B is written in 100% assembly language by Henry Nettles. Again it is based upon Chris Dunford's program. The zip file contains the executable and .asm source. The documentation is in the source code. 23.4 AVAILABILITY All these .zip files are available at any SimTel Mirror site. They are found in the SimTel/msdos/asmutil directory. 23.5 THE REAL THING, EXE2BIN.EXE If you need the real thing, EXE2BIN.EXE is available on the DOS Supplemental Diskettes. This disks can be downloaded from Microsoft. ftp://ftp.microsoft.com/peropsys/msdos/public/supplmnt DOS62SP.EXE for MS DOS 6.2 DOS6SUPP.EXE for MS DOS 6.0 SUP621.EXE for MS DOS 6.21 SUP622.EXE for MS DOS 6.22 Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 8 Jan 96 ------------------------------ Subject: 24. ASM Tutorials Available REVISED There are several assembly language tutorials available on the internet. 24.1 FROM SIMTEL MIRRORS From the SimTel Mirrors, e.g., oak.oakland.edu, there are two tutorials available in the simtel/msdos/asmutil directory. asmtutor.zip The tutorial is by Joshua Averbach. It is old, as it is dated Jun 1988. It is designed for the 8088 processor. primer2.zip This tutorial is designed specifically for the cheap assembler (CHASM) also available in this directory. 24.2 GAVIN ESTEY'S TUTORIAL A new tutorial has been written by Gavin Estey. He has provided his tutorial in ascii text and in Microsoft Word format. They are available using anonymous ftp from: ftp://x2ftp.oulu.fi/pub/msdos/programming/docs get asmtutx.zip For ascii text get asmtutwp.zip For MS Word document Estey has converted his tutorial to an on-line tutorial. Its URL is: http://www.strangecreations.com/strange/library/assembly/tutor/asm1.htm 24.3 VLA's Assembly Language Tutorial This tutorial is available directly or as part of the PC Games Encyclopedia. This file is available from: http://www.mds.mdh.se/~dat94avi/asmvla.zip or as part of the PC Games Encyclopedia: ftp://teeri.oulu.fi/pub/msdos/programming/gpe/pcgpe10.zip 24.4 ASM Tutorial on University of Guadalajara Web Site The on-line tutorial descibed below also is available as an ascii text. http://udqftp.cencar.mx/ingles/tutor/assem.zip There now is an ASCII version of this tutorial. Its URL is: http://udqftp.cencar.udg.mx/ingles/tutor/edition96/download.html 24.5 RANDALL HYDE'S ART OF ASSEMBLY LANGUAGE REVISED Randall Hyde has published on the Internet his textbook on machine organization and assemly language programming developed for his class. It is called, "The Art of Assembly Language," and is available: http://webster.ucr.edu/Page_asm/index.html 24.6 PATRICK STUDDARD'S ASSEMBLY CLASS NOTES Patrick Studdard has a very extensive library of supplementary class notes for assembly language. These are available for all and not just those who are taking the class. They are available: http://cage.cas.american.edu/~studdard/classes/fall1995/4028201/notes/index.html 24.7 WEB SITES REVISED Assembly Language Tutorials http://udgftp.cencar.udg.mx/ingles/tutor/Assembler.html ASM Tutorial on University of Guadalajara Web Site http://www.cit.ac.nz/smac/csware.htm Version 2.6 of on-line 386 assembly languager course. Self tests, assignments, course notes, and software are included. http://www.feldspar.com/~mbabcock/Programming/asmtut1.htm Mike Babcock's ASM Tutorial http://www.mds.mdh.se/~dat94avi/demoschool.htm Tutorial emphasises video and gaming techniques and C and assembly interface. http://webster.ucr.edu/Page_asm/index.html Randall Hyde's Assembly Language Course Material - Art of Assembly Language Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 20 Nov 96 ------------------------------ Subject: 25. Shareware Assemblers 25.1 AVAILABILITY All assemblers, unless otherwise noted, listed here are available from SimTel in the SimTel/msdos/asmutil directory. Specifically: ftp://www.cdrom.com/pub/simtelnet/msdos/asmutil/ 25.2 A86 This assembler is a very capable assembler for 80286 and earlier processors. Registration will get you a version capable of handling 80386 processor. For more details, see the A86 section of this FAQ. 25.3 CHASM, CHASM4.ZIP This assembler was the first shareware assembler available. CHASM was written Mr. David Whitman. The current version available is version 4 and dated in 1983. This version supports only 8088 processor, and the output only is: .COM file (.EXE is not supported) BLOADable - format for interpreted BASIC to load and execute External procedure for TurboPascal - TurboPascal version not given The version available on the internet is annoyware and crippleware. For $40 registration fee, you will get the complete version without the annoying banner page. This version supports macros, conditional assembly, include files, operand expressions and structures. I do not recommend this assembler because of it limited capability and it is very out of date. 25.4 THE ARROWSOFT ASSEMBLER, VALARROW.ZIP This assembler is the public domain version of the Professional Arrowsoft Assembler by Arrowsoft Systems, Inc. The version is 1.00d and is dated in 1986. This assembler is a MASM 3.0 compatible assembler and supports up to 80286 processor. Compared to the Professional version, the public domain version has one major limitation. The file input size is limited to 64K bytes. The file also includes a public domain linker, full screen editor and an EXE2BIN clone program. The above version 1.00d is available from SimTel. Version 2.00c which has only the assembler and documentation is available: http://sunsite.unc.edu/pub/micro/pc-stuff/freedos/microc/arrowasm.zip and the linker separately: http://sunsite.unc.edu/pub/micro/pc-stuff/freedos/microc/vallink.zip These are used in the freeDOS project. 25.5 WOLFWARE ASSEMBLER, WASM223.ZIP This assembler was written by Mr. Eric Tauck. The latest version is 2.23 and dates from 1991. This assembler supports up to the 8028 processor. It will assemble directly into a .COM file or .obj file. It supports a simplified syntax and program structure so programs written for this assembler may not be compatible with other assemblers. Several source files for programs are included with the .zip file. It is available from the author at: http://ourworld.compuserve.com/homepages/warp/ 25.6 MAGIC ASSEMBLER, ASM110.ZIP This assembler is very new. The version is 1.10 and dates from March 1995. This assembler was written by Mr. Bert Greevenbosch. The output is either a .COM file or a boot sector program. The assembly commands are standard except for the jump and call commands. Again, the source code will not be compatible with other assemblers. Beware of version 1.04. That version had a bug that when executed without the print command, the assembler terminated with a runtime error. This is corrected in subsequent versions. Changes made in version 1.10 are: CALLF [] added, CALL [] corrected Boot Indicator (55aa) added [BX][SI] now recognized as [BX+SI] Calculations (*, /, -, +) added XCHG added Assembling Report added EQU bug corrected IN/OUT command improved 25.7 GEMA, GEMA.ZIP This assembler revision is 2.6a with a date, 7 Jan 96. It is different from all other x86 assemblers I have seen. This assembler is based upon Motorola's 68k mnemonics and logical structure. All instuctions, Pentium Pro and known undocumented are supported. GEMA was designed especially for 32-bit porcessing. The assembler will take only one source code file and will output an .COM or .EXE file. No linker is required. DESA.EXE, a beta GEMA disassembler is available in the GEMA package. ASM2GEMA.EXE, a TASM to GEMA translator is no longer availabLe as part of the GEMA package. An interactive real and protected-mode debugger is in progress. This assembler is available from: ftp://ftp.nether.net/pub/gema/gema.zip (symbolic link to latest version) 25.8 NASM 0.90, NASM.ZIP The birth of this assembler started out of a thread that started on comp.lang.asm.x86. When you download this assembler, you get the source code in ANSI C. The web page devoted to this assembler is: http://www.dcs.warwick.ac.uk/~jules/nasm1.html http://www.dcs.warwick.ac.uk/~jules/nasm.zip NASM is an 80x86 assembler designed for portability and modularity. It supports a range of object file formats including Linux a.out and ELF, COFF, Microsoft 16-bit .obj and Win32. It will also output plain binary files. Its syntax is designed to be simple and easy to understand, similar to Intel's but less complex. It supports Pentium and P6 opcodes. It includes a disassembler as well. The assembler also is available from: ftp://ftp.coast.net/coast/msdos/asmutil/nasmb090.zip ftp://ftp.coast.net/coast/msdos/asmutil/nasms090.zip (the latter version includes sources; the former is binaries-only). It has been reported that nasm090.zip or nasm090s.zip from Simtel mirrors contain a disabling bug. 25.9 GAS, GNU Assembler This assembler with many object-file utilities will run on 386 systems running the following operating systems: AIX 386BSD, NetBSD, BSDI/386, Linux, SCO, Unixware, DOS/DJGPP. The below file is a gzipped tar file. You will need gzip and tar programs to uncompress and extract the files. The assembler and utilities are part of the GNU binutils file. This file, a 3.86 Mbyte file, is available from: ftp://prep.ai.mit.edu/pub/gnu/binutils-2.6.tar.gz 25.10 REAL TOOLS 1.0 (BETA), RTOOLS.ZIP This assembler is dated in Dec 93 and is a beta test. The nice thing about this assembler is that it comes with its own DOS-windowing IDE. This assembler was written by International Systems development. The instruction set supported is 486 including protected mode instructions, but some holes do exist. This assembler has a unique way of supporting macros. 32-bit supported. On line help and debugger are available with registered product. 25.11 ENHANCED ASSEMBLER, EASM.ZIP This is version 1.0a of the above assembler. This assembler supports all standard commands (there is a small and not inclusive list of standard commands in the documentation), as well as an enhanced command set - Very non standard. This assembler is available from: http://pwp.usa.pipeline.com/~spyder_x/easm.zip (No longer valid) http://www.dlc.fi/~arzie/programming/easm.zip The home page: http://pwp.usa.pipeline.com/~spyder_x/easm.htm (No longer valid) Homepage should be back up soon. 25.12 GENERAL ASSEMBLER, GASM01G.ZIP This is a new assembler written by Jim Gage. This version outputs .COM files and can be used to write device drivers. Another version supporting up to the 486 instruction set and .obj output is in the works. This assembler is available: http://www.engr.uark.edu/~jrg/gasm/gasm01f.zip Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 19 Oct 96 From short!circuit!express.ior.com!news.sprintlink.net!news-chi-8.sprintlink.net!news.sprintlink.net!news-hub.sprintlink.net!news.sprintlink.net!news-peer.sprintlink.net!howland.erols.net!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon Sat Nov 23 15:45:29 1996 Path: short!circuit!express.ior.com!news.sprintlink.net!news-chi-8.sprintlink.net!news.sprintlink.net!news-hub.sprintlink.net!news.sprintlink.net!news-peer.sprintlink.net!howland.erols.net!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon From: raymoon@dgsys.com (Raymond Moon) Newsgroups: alt.lang.asm,comp.lang.asm.x86,news.answers,alt.answers,comp.answers Subject: x86 Assembly Language FAQ - General Part 3/3 Date: 20 Nov 1996 18:06:19 GMT Message-ID: <56vhar$sl@news.dgsys.com> Followup-To: alt.lang.asm,comp.lang.asm.x86 Reply-To: raymoon@moonware.dgsys.com Organization: MoonWare Expires: Fri, 20 Dec 1996 23:59:59 GMT Distribution: world Keywords: x86 Assemby Language ASM FAQ General Summary: This is the FAQ for the x86 Assembly Language programmers for the alt.lang.asm and comp.lang.asm.x86 newsgroups. This particular section of the FAQ is part three of three parts that contain x86 assembly language information common to all assemblers. Approved: news-answers-request@MIT.EDU Lines: 785 Supersedes: <54gimb$v0i@news.dgsys.com> NNTP-Posting-Host: dgs.dgsys.com X-Newsreader: TIN [version 1.2 PL2] Xref: short alt.lang.asm:5634 comp.lang.asm.x86:15387 Archive-Name: assembly-language/x86/general/part3 Posting-Frequency: monthly (21st of every month) Last-modified: 1996/11/20 ------------------------------ Subject: 26. WWW Assembly HomePages 26.1 CAUTION All of the web sites listed here are maintained by individuals. I will strive to maintain this list current but do not be surprised if the addresses no longer are current. 26.2 ASSEMBLY LANGUAGE RELATED HOME PAGES CERA Research Assembly Language Hot Lists and Major Resources http://www.cera.com/assembly.htm http://www.cera2.com/assembly.htm Links to FAQs and other web sites Assembly Language Tutorial http://udgftp.cencar.udg.mx/ingles/tutor/Assembler.html http://www.cit.ac.nz/smac/csware.htm Version 2.6 of on-line 386 assembly languager course. Self tests, assignments, course notes, and software are included. http://www.cyberbeach.net/~mbabcock/Programming/asmtut1.htm Mike Babcock's ASM Tutorial Brian Brown's Introduction to Hardware Systems http://www.cit.ac.nz/smac/cbt/hwsys/default.htm Good links to general asm information. Links to iAPX386 information. Robert Collins' home pages http://www.x86.org/ Intel Secrets - undocumented OpCodes, links to Intel's on-line documentation, the infamous Appendix H, P6 OpCodes, and much, much more Shareware BIOS Growing list of on-line Intel documentation and magazine articles by Robert Collins and Ralf Brown Pentium Pro Information including New Opcodes, Paging Extension, CPUID and manuals. Protected Mode Basic - a tutorial on PM with souce code. Jannes Faber's Assembly home page http://www.fys.ruu.nl/~faber/Amain.html List of ASM Books with short reviews A few hints and tricks Complete source code to some of his programs A listing of EMS Professional Shareware products Ray Rose's Html For Assembler home page http://www.alaska.net/~rrose/assembly.htm An extensive list of ASM books without descriptions Links to alt.lang.asm, comp.lang.asm.x86, and alt.msdos.programmer newsgroups. Link to the Yahoo/Computers and Internet/Languages/Assembly page (see below) NASM: The Netwide Assembler Project http://www.dcs.warwick.ac.uk/~jules/nasm1.html A group of programmers are writing a new assembler. This home page describes the project and where to download the latest version. Michael Babcock's 3/4/586 ASM Programming Home Page http://www.cyberbeach.net/~nbabcock/Prg.welcome.html This home page has links to: Optimizing 803/4/586 ASM Programming http:///www.cyberbeach.net/~mbabcock/Programming/Optimize.html ASM Tutorial http://www.cyberbeach.net/~mbabcock/Programming/asmtut1.htm Utilities http:///www.cyberbeach.net/~mbabcock/Programming/Utils.html The Official Web Shareware Site http://www.jumbo.com/prog/dos/asmutil This site appears to have a few asm files not on SimTel. Hamarsoft 86BUGS list Online http://www.xs4all.nl/~feldmann/ List contains many documented and undocumented errors in Intel microprocessors, as well as undocumented instructions. Joe's Assembly Language Page http://jasper.idbsu.edu:8000/ Links to his own and other asm code. His own Assembly Language Search Engine Bill Stapleton's Assembly Language Reference Page http://www.carl.ua.edu/~wstablet/ee384.html A collection of 80x86 assembly language references generating from teaching EE383 and EE384 courses at The University of Alabama. Dr. ASM's Assembly Home Page http://web.syr.edu/~dbgrandi/assembly.htm Some answered questions and links to other assembly related sites. James Vahn's 80xxx Snippets - 80x86 Assembly Language Enthusiasts http://www.cet.com/~jvahn Download snippets & Booklist Arzie's Home Page http://www.dlc.fi/~arzie/programming.html Many links to programming related pages Kip Irvine's Assembly Language Sources http://netrunner.net/~irvinek/asm.htm Gavin Estey's Home http://www.strangecreations.com/library/assembly/index.htm His ASM tutorial and other ASM Links and FAQs Grzegorz Mazur's x86 CPU Stuff http://grafi.ii.pw.edu.pl/gbm/x86/index.html x86 CPU identification algorithms Cyrix/IBM5x86/6x86 (and 486) control program Links to other information on x86 family CPUs Heath Holcomb's x86 Assembly Page http://www.wfu.edu/~holcojh5/asm/x86asm.html Some pointers on what is assembly language, what is assembly good for, and what do you need to get started. Pointers to ASM Tutorial, this FAQ, other ASM web pages Eric Isaacson's A86 Assembler and D86 Debugger Page http://eji.com/a86/index.htm Overviews of a86 and a386 assemblers, d86 and d386 debuggers, download and purchase of a86 and d86. Eg3 Communications' Assembly Language Hot Lists and Major Resources http://www.eg3.com/assembly.htm Tore Nilsson's Assembly Tutorial Page http://www.geocities.com/SiliconValley/2704/tutorial.html VLA's Assembly and DMA programming tutorials, Asphyxia's VGA tutorials, and some graphics and sound programming information. Ard Oerlemans Assembly Programming on the Intel Chips Page http://www.wi.leidenuniv.nl/~aoerlema/assembly.html Information on programming sound cards, audio file format, compression techniques, video card programming, graphic file formats, Asphyxia VGA tutorial. Gerd Kortemeyer's 387/486DX/Pentium/Floating Point Processor Stuff http://www.nscl.msu.edu/~kortemey/copro.html A collection of assembler routines written for Turbo Pascal and C++. Most of the comments are in German after an English introduction. Cameron's 386+ Programming Page http://hudson.idt.net/~c027319/ 32 bit DOS extender/Utilities/pmode extender File formats and specifications/Game programming Knowledge Base with ASM tutorials, Denthor's VGA Trainer and Univ. of Guadalajara ASM tutorial Peter's PMODE Home Page http://www.globalserve.on.ca/~subdeath/ Pmode tutorials and programming related files Niko Komin's Assembler for PCs page http://www.inx.de/~nkomin/html/assembe.htm Shareware, pmode, x86 mnemonics, ASM related links. Alexandre Zvenigorosky III's Programs for PC 386+ NEW http://cpodlcom/monoweb/zveni/prg.html Zvenigorosky's assembler and debugger, currently documentation only in French. Rich Elber's ValArrow (286 Assembler) Page NEW http://www.geocities.com/SiliconValley/Heights/7052/valarr.html Links to Arrowsoft Assembler, ZD86 debugger, discussion of Arrowsoft's Assemblers deviations from MASM. Kurt I. Groenbech's Alab Homepage NEW http://www.idb.hist.no/kurtg/ Home page for the Assembler Laboratory that is an IDE for assemblers Christian Kurzke's Advanced x86 Assembly Programming NEW http://wwwcip.informatik.uni-erlangen.de/user/cnkurzke/hwkmcs/index.html Excerpts from lessons given at Adalbert Stifter Gymnasium in 1989 Bob Richardson's PC Assembly Language Page NEW http://lexitech.com/bobrich/ Eighteen topics taken from his SELFIN PC Assembly Language Group. Jesper Pedersen's Processor Information Page NEW http://www.imada.ou.dk/~jews/PInfo/intel.html List of instructions and opcodes used by Intel, AMD, Cyrix and Nexgen. Quantasm's x86 and Pentium Programming Tips and Info NEW http://www.quantasm.com/freeinfo.html Steve Kemp's Assembly Language Programming Index NEW http://www.dcs.ed.ac.uk/home/skx/asm/index.html Assembly Language Newbie information. A86 Source Code Phil Toland's Assembly Language Page NEW http://www.epix.net/~toland/asm/index.html URLs to Win32 Assembly Lanugage Kit. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 18 Nov 96 ------------------------------ Subject: 27. Undocumented OpCodes 27.1 WHAT AND WHERE Robert Collins has make available an excellent article on Intel Undocumented OpCodes. Just set your web browser to: http://www.x86.org/secrets/OpCodes.html 27.2 EXTENDED FORMS OF AAM AND AAD INSTRUCTIONS Mr. Collins describes extended forms these two instructions. AAM is ASCII Adjust after Multiplication, and ADD is ASCII Adjust before Division. These instructions are known as quick ways to divide and multiply by ten, as these instructions normally assemble with 10 as the default operand. Using macros provided, any value from 0h to 0ffh can be substituted. These instructions are available on all x86 Intel processors. 27.3 SALC - SET AL ON CARRY Mr. Collins describes this instruction a C programmers dream instruction for interfacing to assembly language procedures. This instruction will set the AL register to 00h or 0ffh depending on whether the carry flag is clear or set, respectively. This instruction is available on all x86 Intel processors. 27.4 ICE RELATED OPCODES Mr. Collins describes several instructions that appear whose existence makes debugging run-time code easier on the ICE debugger. There are: ICEBP - ICE Break Point UMOV - User Move Data LOADALL - Loads the Entire CPU State Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 4 Nov 95 ------------------------------ Subject: 28. Common Reason Why Memory Allocation Fails 28.1 BACKGROUND A common error received when first learning to use Int 21h Function 48h, allocate memory, is error code 8, insufficient memory available. Usually, the programmer then writes a small program that only allocates memory, and the program still fails. This situation is quite puzzling because there should be hundreds of kilobytes of memory available but this function reports that there is insufficient memory for a few hundred bytes. The reason is that DOS generally allocates all available memory above the loaded program to that program. Therefore, there is no more memory to allocate, so the request fails. 28.2 .COM FILES Since a .COM file does not contain any header information, the DOS loader has no way of determining how much memory is required for a program beyond the physical size of the program. Even this number is deceptive because it does not include a stack. Therefore, DOS always allocates all available memory above the program to the program. To use the allocate memory function, the programmer must release that extra memory using Int 21h Function 4ah, Set Memory Block Size. Given that generally there is more that 64 Kbytes of memory, the DOS sets Stack Top to just under that value, it is generally safe to release all memory above 64 Kbytes. 28.3 .EXE FILES The amount of memory the DOS allocates to the loaded program depends upon a value in the .EXE header. This value is called Maximum Allocation and is a word starting at offset 12. This value specifies the number of 16-byte paragraphs beyond the image size wanted by the program to execute. This value must be equal or greater than the Minimum Allocation, which is the number of 16-byte paragraphs beyond the image size required by the program to execute. This space generally contains uninitialized variables and the stack. The value of Maximum Allocation is set by the /CPARM Option for the Microsoft Linker. By default, the linker sets this value to 0ffffh which will causes DOS to allocate the largest block of available memory. This memory can be used as a heap, print buffer, etc. 28.4 DETERMINING HOW MUCH MEMORY IS AVAILABLE TO A PROGRAM In the PSP, at offset 02h, DOS loads a word which is the segment address of the next Memory Control Block or Arena. Subtracting the PSP from that value at offset 02h will be the number of memory paragraphs allocated to the program. The number of bytes can be calculated by shifting that number to the left by 4 bits, multiplying by 16, the size of a memory paragraph. 28.5 HOW TO DEALLOCATE MEMORY AT THE START OF A PROGRAM If you want to load and execute another program, you must release memory to make room for the program. Also, since the largest chunk of memory is allocated already to the program, all requests to allocate memory generally fail. Again, to use the allocate memory function, the programmer must release the extra memory above the program use as for a .COM file above. The problem here is where is the end of the program. The answer is not as simple as with the .COM file. There are two basic solutions. 1. If you use the .dosseg option, the Microsoft Linker will define a label, _end, at the end of the DGROUP. Since the .dosseg option also places any FAR data segments between the code and DGROUP segments, you can release all memory above that label. 2. If you do not want or are unable to use the first option, use an include file which declares all segments used by your program. Define a label in the last segment and use it as the _end label in the first example. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 26 Dec 95 ------------------------------ Subject: 29. Volume Serial Numbers 29.1 VOLUME SERIAL NUMBER FORMAT The volume serial number was introduced with DOS 4.0 as part of an extended boot record and is created through you either FORMAT a disk or use DISKCOPY to create another disk. The serial number is a function of the time/date of the formatting or the diskcopying. Note that DISCOPY generates a new volume serial number so a DISKCOPY is not an exact image of the source diskette. 29.2 CALCULATING THE VOLUME SERIAL NUMBER For example, say a disk was formatted on 26 Dec 95 at 9:55 PM and 41.94 seconds. DOS takes the date and time just before it writes it to the disk. Low order word is calculated: Volume Serial Number is: Month & Day 12/26 0c1ah Sec & Hundrenths 41:94 295eh 3578:1d02 ----- 3578h High order word is calculated: Hours & Minutes 21:55 1537h Year 1995 07cbh ----- 1d02h Note that DOS interrupt 21h Functions 2ah, Get DOS Date, and 2ch, Get DOS Time, are particularily suited to getting the date and time for calculating the Volume Serial Number. 29.3 READING AND SETTING THE VOLUME SERIAL NUMBER To read the Volume Serial Number, use the IOCTL call, int 21h function 440dh Minor Code 66h, Get Media ID. To write the Volume Serial Number, use the IOCTL call, int 21h function 440dh Minor Code 46h, Set Media ID. WARNING! These IOCTL calls use a structure that also contain the volume label and file system type. So that you do not create errors with these values, I recommend that you always Minor Code 66h to initialize the structure before setting the Volume Serial Number to a new value and writing it back to the disk. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 17 Feb 96 ------------------------------ Subject: 30. .obj File Format 30.1 INTEL There are two sources for this information. The first is available from Intel. The Tools Interface Standards Committe has prepared the following documents: ftp://ftp.intel.com/pub/IAL/TIS/omf11g.zip and ftp://ftp.intel.com/pub/IAL/TIS/omf11h.zip The readme file in each .zip file states that the document is the Relocatable Object Module Format Specification, V1.1. Unfortunately, both files unzip into documents formatted for Postscript printers. Adobe's Acrobat can not display them, but Ghostscript can. If you need GhostScript, you can get it from the following site. Read the ftp://ftp.cs.wisc.edu/pub/ghost/aladdin (keep trying as I found it difficult connecting to this site) 30.2 MICROSOFT The second is from Microsoft. This file is located at: ftp://ftp.microsoft.com/Softlib/MSLFILES/ss0288.exe This file expands into ascii text files that are the Microsoft Product Support Services Application Note: Relocatable Object Module Format. These files date from 1992. Also included is the .lib file format and the CodeView extensions. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 9 Jan 96 ------------------------------ Subject: 31. Rebooting from Software 31.1 WARM AND COLD REBOOT Within DOS, there are two types of rebooting. There is the warm reboot that is evoked by pressing the "Ctrl-Alt-Del" key combination. During this reboot, all Power On System Tests, POSTs, are performed with the exception of the memory tests. In addition to the POSTs, interrupt vectors are reinitialized and system timers reinitialized. In other words, the BIOS code initializes the computer system to such a state that the computer system is ready for loading the operating system. The loading of the operating system is done by issuing an interrupt 19h. The second type of rebooting is a cold reboot that occurs when the system is turned on. The only difference between a cold reboot and a warm reboot is the performing of the memory tests. 31.2 PERFORMING A REBOOT FROM SOFTWARE Whether a cold or warm reboot is performed depends upon the value if the the reset flag in the ROM BIOS data area. If this flag is set to 1234h, a warm reset is performed. An any other value results in a cold reboot. Usually a zero is loaded for the cold reboot. Code snippets to do this are: ROMBIOS_DATA segment at 0400h org 72h ResetFlag dw ? ROMBIOS_DATA ends ROMBIOS segment at 0f000h org 0fff0h Reset label far ROMBIOS ends In your code: mov ax, seg ROMBIOS_DATA mov ds, ax ASSUME ds:ROMBIOS_DATA mov ResetFlag, 1234h ; or 0 if cold reset is desired jmp Reset 31.3 WARNINGS! Neither the warm nor the cold boot flushes buffers, system, smartdrv, and EMM386, or notifies TSRs. This can lead to lost of data. 31.4 JUST USING INT 19H Using this interrupt alone will only reload the operating system onto a computer system that may not be properly initialized for it. The interrupt vectors are not reset but the TSRs that have hooks into the interrupt table may be overwritten. Obviously, this can lead to the system hanging if one of these hooked and overwritten interrupts is called. Other problems can be timers not reset or add-on cards not reinitialized properly. So, do NOT use int 19h to reboot the computer. 31.5 USING F000:E05B INSTEAD OF F000:FFF0 AS THE JUMP ADDRESS In the original IBM ROM BIOS, the instruction at f000:fff0 was a long jump to f000:e05b. Some programs skipped the jump at f000:fff0 and went directly to the second address which is the start of the reset procedure in ROM BIOS. I checked my 386 with non IBM BIOS, and the start of the reset procedure is at the same address. I believe that using the second address is dangerous because there is not any guarantee that it will stay the same. Also, if you are rebooting the computer what is the reason in saving a few cycles! Stay with the address f000:fff0 as the jump there always will take the execution path to the correct code. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 8 Jan 96 ------------------------------ Subject: 32. Other FAQs 32.1 COMP.OS.MSDOS.PROGRAMMER This excellent FAQ is posted every 20 days to comp.os.msdos.programmer, comp.answers and news.answers newsgroup. It is available from ftp://rtfm.mit.edu/pub/usenet-by-group/comp.os.msdos.programmer/dos-faq 32.2 COMMUNICATIONS FAQS The following websites contains many links to communication and hardware related FAQs, e.g., serial port, game port, keyboard, modem, and LANs. Most of these FAQs are not approved FAQs so are not found at rtfm.mit.edu but that is not to say that these are not quality FAQs. There is much good information. http://www.webcom.com/~llarrow/comfaqs.html http://www.paranoia.com/~filipg/HTML/LINK/PORTS/F_Parallel.html http://www2.psyber.com/~tcj/resource.html Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 17 Feb 96 ------------------------------ Subject: 33. Pseudo Random Number Generator in Assembly Language Mark Adler wrote a set or pseudo random number generators based upon algorithms from Knuth's "Art of Computer Programming", vol 2, 2nd ed. The file comes with full assembly source and .obj files for all major memory models. While written to link with Turbo C, the .obj files when linked with Microsoft C worked well, except for the procedure that return a double random number. The reason was because the return protocol is different between Borland C and Microsoft C. Once the code was modified to work with Microsoft C, the code worked well. To test the algorithms, I created an array of 100 random numbers and then generated random numbers and tried to determine if the original pattern was ever repeated. My program kept the length of the longest matching series. For real or double, the longest matching series was one after more that a billion random numbers. For ints, 0 and 1 as the only selections produced the longest matching series of 31 matches after more than a billion random numbers. Increasing the range of acceptable numbers quickly reduced the longest matching series to 2 in over 250 million random numbers. My short testing revealed that the longest matching series seldom increased after this number. Lastly, to test the distribution, I counted the number of hits for each number between 0 and 100. I collected about 100,000 hits for each number. The standard deviation was only 319 or less than 0.33%. While my testing was not a rigorous mathematical testing of the algrorithm and its implementation, I believe for most uses, these procedures are adequate. The file is available: ftp://www.cdrom.com/pub/simtelnet/msdos/turbo_c/tcrnd11.zip Note that the description of this file is inaccurate. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 4 May 96 ------------------------------ Subject: 34. Command Line Arguments 34.1 WHERE IS THE COMMAND LINE DOS loads the command line into the PSP. The length of the command line is stored in a byte at offset 80h. The command line is stored in the next 127 bytes starting at 81h. As, generally, there is a space between the filename and the start of the command line argument, a space usually is the first character in this string. The string is terminated with a carriage return character, 0dh. At startup for both .COM and .EXE format programs, DS and ES point to the PSP. 34.2 HOW TO ACCESS THE COMMAND LINE ARGUMENTS See Subject #8, How to Redirect Stderr to a File. I have written a demonstration program that contains assembly language startup code that parses the command line arguments onto the stack and provides them as argc and *argv[] to the main procedure. Anyone interested in accessing command line arguments should look at this code. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 15 Jun 96 ------------------------------ Subject: 35. Free 32 bit and DJGPP Assemblers 35.1 Brennan Underwood's Guide to Inline Assembly under DJGPP. This is an introduction to inline assembly under DJGPP and is based upon GCC. The AT&T/UNIX syntax is explained. The URL is: http://www.rt66.com/~brennan/djgpp/bgtia.html 35.2 DJGPP QUICK ASM PROGRAMMING GUIDE Andrew Ly has a web page covering: URLs to FAQs AT&T x86 ASM Syntax Some inline ASM information converting .obj/.lib files The URL to this page is: http://remus.rutgers.edu/~avly/djasm.html 35.3 FREE 32-BIT X86 ASSEMBLER FAQ/LINUX X86 ASSEMBLY HOWTO Francois-Rene Rideau has authored a FAQ on free 32-bit assemblers or Linus x86 Assembly HowTo. It is available: http://www.eleves.ens.fr:8080/home/rideau/Assembly Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 19 Jun 96 ------------------------------ Subject: 36. TERSE Programming Language Jim Neil has just announced his TERSE Programming Language. TERSE gives all of the control available in assembly language with the look-and-feel and ease-of-use found in high-level languages. It is available: http://www.terse.com Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 19 Aug 96 ------------------------------ Subject: 37. Assembly Language IDEs REVISED 37.1 ASMEDIT ASMEDIT is an Integrated Development Environment (IDE) for Assembly Language programmers. This IDE has a build in editor that provides syntax coloring, editing of files up to 256 Mbytes, dissammembly of shourt code pieces, and shelling to run external assemblers, linkers, debuggers and make programs. The real benefit of ASMEDIT is its extensive help. This help covers: 80x86 ASM mnemonics up to 686 including FPU and MMX; Complete Opcode Tables; BIOS Interrupts; DOS Interrupts and DOS Functions; EMS and Mouse Functions; BIOS and DOS Data Structures; Diagnostic Codes; and VGA programming information. ASMEDIT is available from simtel or any of its mirrors: ftp://www.cdrom.com/pub/simtelnet/msdos/asmutil/aedt182.zip or directly from the authors at: http://www.inf.tu-dresden.de/~ok3/asmedit.html 37.2 ALAB Assembler Laboratory is an assembler IDE, packed with nice features such as: syntax and error highlighting proc,macro and data browsers tasm,masm, a86 and dlink support. heuristic scan opcode help, extended ascii chart, scan codes, calculator much more! The latest version is available from the author's homepage: http://www.idb.hist.no/~kurtg/ 37.3 ASMIDE The latest version of ASMIDE, 4.01, has the following features: contains all the features of a conventional editor, such as Finding, Replacing, Cutting, Copying, Pasting. has the ability to open multiple files, allowing you to transfer text between the files. Multiple windows can be Tiled or Cascaded, and features Scroll bars. has mouse support. features a simple, 4 function, 3 mode calculator, and an Ascii Chart. has menu systems allowing you to assemble, link, run and debug your program. Short cut keys are also provided. allows you to specify your own assembler, linker and debugger in the configuration file. features setup dialogs that provide support for TASM, TLINK, MASM and LINK. ASMIDE is available from the author: http://pc-ec102.ee.und.ac.za/kurien/asmid401.arj Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last Changed: 20 Nov 96 ----------------------------- Subject 38. Dissassemblers 38.1 Review of Disassemblers Jerzy Tarasiuk has reviewed some commercial and shareware disassemblers. The shareware assemblers are available in this directory. The review is available: ftp://www.cdrom.com/pub/simtelnet/msdos/disasm/aabstrct.txt Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last Changed: 13 Oct 96 ----------------------------- Subject: 39. How to Optimize for the Pentium REVISED 39.1 PENTIUM OPTIMIZATION SITE The below site is updated as new information becomes available and contains information not found elsewhere. http://announce.com/agner/assem 39.2 LITERATURE AVAILABLE FROM INTEL Much useful literature can be downloaded for free from Intel's www site: http://www.intel.com You can find the documents you need by using the search facilities at: http://www-cs.intel.com/search2.htm and: http://www-cs.intel.com/search.htm The documents are in various different file formats. If a particular document is in a format not supported by your word processing software then you may seek an appropriate file viewer somewhere on the Internet. Many software companies are offering such file viewers for free to support their file formats. The most useful document is Intel's application note, "AP-526 Optimizations for Intel's 32-bit Processors" that can be downloaded from: http://www.intel.com/design/pro/applnots/ap526.htm A fancy tutorial named "Optimizing Applications for the Pentium Processor" can be downloaded from: http://www.intel.com/ial/processr/cbt.htm Manuals for the Pentium and PentiumPro processors can be downloaded from: http://www.intel.com/design/pentium/MANUALS/index.htm http://www.intel.com/design/pro/MANUALS/index.htm Detailed information on the MMX processors can be found in the documents: "Intel architecture MMX technology developer's manual", and "Intel architecture MMX technology programmers reference manual", both of which are available from: http://www.intel.com/pc-supp/multimed/mmx/ Many other sources other than Intel also have useful information. I would particularly recommend: http://www.x86.org. The shareware editor ASMEDIT has an online help which covers all instruction codes etc. It is available from: http://www.inf.tu-dresden.de/~ok3/asmedit.html Contributor: Agner Fog, Agner@login.dknet.dk Last Changed: 14 Oct 96 ----------------------------- Subject: 40. Acknowledgments I would like to acknowledge all the people who have assisted me or any of the contributors. For their time and effort, this FAQ is a better product. Barry Brey, Giuseppe De Marco, Morten Elling, Kris Heidenstrom, Alan Illeman, Don Krull, Chabad Lubavitch, Thanh Ma, Jeff Owens, Ed Parry, Michael Roberts, Russell Schulz, Rocky Seelbach, Janos Szamosfalvi and Cedric Ware From short!circuit!express.ior.com!news.sprintlink.net!news-chi-8.sprintlink.net!news.sprintlink.net!news-pull.sprintlink.net!news.sprintlink.net!news-stk-3.sprintlink.net!www.nntp.primenet.com!nntp.primenet.com!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon Sat Nov 23 15:45:38 1996 Path: short!circuit!express.ior.com!news.sprintlink.net!news-chi-8.sprintlink.net!news.sprintlink.net!news-pull.sprintlink.net!news.sprintlink.net!news-stk-3.sprintlink.net!www.nntp.primenet.com!nntp.primenet.com!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon From: raymoon@dgsys.com (Raymond Moon) Newsgroups: alt.lang.asm,comp.lang.asm.x86,news.answers,alt.answers,comp.answers Subject: x86 Assembly Language FAQ - Microsoft MASM Date: 20 Nov 1996 18:06:58 GMT Message-ID: <56vhc2$sl@news.dgsys.com> Followup-To: alt.lang.asm,comp.lang.asm.x86 Reply-To: raymoon@moonware.dgsys.com Organization: MoonWare Expires: Fri, 20 Dec 1996 23:59:59 GMT Distribution: world Keywords: x86 Assemby Language ASM FAQ Microsoft MASM Summary: This is the FAQ for the x86 Assembly Language programmers for the alt.lang.asm and comp.lang.asm.x86 newsgroups. This particular section of the FAQ contains x86 assembly information specific to the Microsoft MASM assembler. Approved: news-answers-request@MIT.EDU Lines: 222 Supersedes: <54gipv$v0i@news.dgsys.com> NNTP-Posting-Host: dgs.dgsys.com X-Newsreader: TIN [version 1.2 PL2] Xref: short alt.lang.asm:5640 comp.lang.asm.x86:15448 Archive-Name: assembly-language/x86/microsoft Posting-Frequency: monthly (21st of every month) Last-modified: 1996/11/09 ------------------------------ Subject: 1. Introduction and Intent This is the x86 Assembly Language FAQ for the comp.lang.asm.x86 and alt.lang.asm newsgroups. This FAQ is posted monthly on or about the 21st of the month on both newsgroups and news.answers, alt.answers and comp.answers. It also is archived at the normal FAQ archival sites and the SimTel mirror sites in the msdos/info directory. Lastly, the current version is available from my web page as: As text files: http://www2.dgsys.com/~raymoon/faq/asmfaq.zip As html documents: http://www2.dgsys.com/~raymoon/faq/asmfaqh.zip Currently, this FAQ is broken into six sections. The following are the section filenames and the scope of each section of the FAQ. assembly-language/x86/general/part1 - This is the basic portion of the FAQ that contains information of interest to all assembly language programmers. In general, the information contained in this portion of the FAQ is not specific to any particular assembler. assembly-language/x86/general/part2 - This is a continuation of the above FAQ. assembly-language/x86/general/part3 - This is a continuation of the above FAQ. assembly-language/x86/microsoft - This portion of the FAQ contains information specific for the Microsoft MASM. assembly-language/x86/borland - This portion of the FAQ contains information specific for the Borland TASM. assembly-language/x86/a86 - This portion of the FAQ contains information specific for the Shareware A86 Assembler and D86 Debugger. The scope and content of this FAQ is to go beyond just answering the frequently asked questions. I am including pointers to assembly language treasure troves that are hidden out on the internet. I believe that this will enhance the FAQ's value not only to the novices but also to the old hands. For the ease of determining what has changed since the last FAQ, the Table of Contents will have "REVISED" at the end of the subject line for all revised subjects. If more than one FAQ revision has been missed, the "Last Changed:" entry at the end of each subject can be used to determine which subjects have been revised during the intervening time frame. The information in this FAQ is free for all to use as long as you acknowledge the source. This FAQ can be reproduced in part or in its entirety as long as the copyright is included. This FAQ can be made available on public servers, like ftp, gopher or WWW servers. Please do not modify the file, such as converting it into some other format, without prior permission of the author. All references to files and locations are in Uniform Resource Locators (URLs) format. Some web browser will be able to use these URLs directly as hot links. If the format is not clear to you, get RFC 1738. It is available from: ftp://is.internic.net/rfc/rfc1738.txt Suggestions for changes and comments are always welcome. They can be posted to either newsgroup or e-mailed directly to the me. Author: Raymond Moon, raymoon@moonware.dgsys.com Copyright 1996 - Raymond Moon ALL RIGHTS RESERVED Last Changed: 13 Oct 96 ------------------------------ Subject: 2. Table Of Contents 1. Introduction And Intent 2. Table Of Contents REVISED 3. How To Get The Patch For MASM 6.11 4. What Is And How To Access The Microsoft Knowledge Base REVISED 5. Pentium Instruction Macros 6. Acknowledgments ------------------------------ Subject: 3. How To Get The Patch For MASM 6.11 There is a patch available from Microsoft for MASM 6.11. This patch converts MASM 6.11 or 6.11a into the latest version MASM 6.11d. To obtain this patch: ftp://ftp.microsoft.com/softlib/mslfiles/ML611D.EXE ML611D.EXE is a self-extracting file which when executed will create the following files: ERRMSG.TXT PATCH.RTP H2INC.EXE PATCH.RTD H2INC.ERR README.TXT ML611D.TXT SUPPORT.TXT PATCH.EXE All the instructions for installing the patch are contained in ML611D.TXT. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last Changed: 2 Dec 95 ------------------------------ Subject: 4. What Is and How to Access the Microsoft Knowledge Base REVISED 4.1 WHAT IS THE MICROSOFT KNOWLEDGE BASE The Microsoft Knowledge Base (KB) is a collection of articles that is maintained and used by the Microsoft Support personnel to answer customer questions. Included in the Knowledge Base are detailed how-to articles, answers to technical support questions, bug lists, fix lists, and documentation errors. This Knowledge Base is available to all on Microsoft's Internet Node. An index of all the articles is available in a file, index.txt. 4.2 HOW TO OBTAIN INDEX.TXT ftp://ftp.microsoft.com/developr/masm/kb/index.txt This index still is available with the last entry dated Aug 96. 4.3 FILE FORMAT OF INDEX.TXT The format of this file consists of three columns. Column One is the file type with the following meanings: FIX - Bug Fix DOCERR - Documentation Error INF - Information PRB - Problem BUG - Bug Column Two is the path and file name in the following format: Qxxxyzz where the part, Qxxx', is Q followed by two or three numbers and represents the first subdirectory under the kb subdirectory, the part, y', is the next subdirectory under Qxxx, and The part, zz', when combined with .txt' is the filename. ****WARNING**** Some of the Qs are uppercase and some are lower case. Unlike DOS, the filenames and directory names are case sensitive. Column Three is a short description of the file. 4.4 GETTING FILES You can get all the files from the /developr/masm/kb directory without transversing this very strange directory structure by using the path in the get command. As an example, let's say you want Q106399, a very useful file if you use Visual C++ (see below). Using the parsing rules above, you can use the following get command: get q106/3/99.txt 4.5 HOW TO ACCESS THE KNOWLEDGE BASE USING GOPHER There no longer is gopher access to microsoft.com 4.6 HOW TO ACCESS USING WWW Microsoft has removed the MASM option from the their www KB search. Another www site for this knowledge base also is available. It is: http://emwac.ed.ac.uk/html/kb/masm.html To use this site, you must know the Q number. 4.7 SOME EXAMPLE FILES FROM THE MICROSOFT KNOWLEDGE BASE Q86815 Mixed C and MASM with MASM Main Language, No C Run-Time Q86816 Mixed C and MASM with MASM Main Language, C Run-Time Q101264 Assembling Code Developed for MASM 5.x with MASM 6.x Q106399 Using the Visual Workbench with MASM Q110598 Spontaneous Assembly and MASM 6.11 Errors Q123729 Accessing Command Line Arguments I have found Q106399 particularly helpful since I am really upset that Microsoft did not include direct support of MASM from within the Visual Workbench. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last Changed: 9 Nov 96 ------------------------------ Subject 5. Pentium Instruction Macros Macros that implement the new instructions available with the Pentium processor is available from Intel. ftp://ftp.intel.com/pub/IAL/pentium/p5masm.mac The new macros are: CMPXCHG8B - Compare and exchange eight bytes CPUID - CPU Identification RDTSC - Read Time Stamp Counter MOVTOCR4 - Move reg to CR4 MOVFROMCR4 - Move CR4 to reg RDMSR - Read Model Specific Register WRMSR - Write Model Specific Register RSM - Resume from SMM Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last Changed: 8 Jan 95 ------------------------------ Subject: 6. Acknowledgments I would like to acknowledge all the people who have assisted me or any of the contributors. For their time and effort, this FAQ is a better product. Barry Brey, Daniel Cardenas and Kevin Weinrich From short!circuit!express.ior.com!cnn.isc-br.com!nwfocus.wa.com!camco!poweramp!news.dsource.com!news-out.internetmci.com!peerfeed.internetmci.com!howland.erols.net!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon Sat Nov 23 15:45:46 1996 Path: short!circuit!express.ior.com!cnn.isc-br.com!nwfocus.wa.com!camco!poweramp!news.dsource.com!news-out.internetmci.com!peerfeed.internetmci.com!howland.erols.net!feed1.news.erols.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon From: raymoon@dgsys.com (Raymond Moon) Newsgroups: alt.lang.asm,comp.lang.asm.x86,news.answers,alt.answers,comp.answers Subject: x86 Assembly Language FAQ - Borland TASM Date: 20 Nov 1996 18:07:41 GMT Message-ID: <56vhdd$sl@news.dgsys.com> Followup-To: alt.lang.asm,comp.lang.asm.x86 Reply-To: raymoon@moonware.dgsys.com Organization: MoonWare Expires: Fri, 20 Dec 1996 23:59:59 GMT Distribution: world Keywords: x86 Assemby Language ASM FAQ Borland TASM Summary: This is the FAQ for the x86 Assembly Language programmers for the alt.lang.asm and comp.lang.asm.x86 newsgroups. This particular section of the FAQ contains x86 assembly information specific to the Borland TASM assembler. Approved: news-answers-request@MIT.EDU Lines: 342 Supersedes: <54gir3$v0i@news.dgsys.com> NNTP-Posting-Host: dgs.dgsys.com X-Newsreader: TIN [version 1.2 PL2] Xref: short alt.lang.asm:5664 comp.lang.asm.x86:15752 Archive-Name: assembly-language/x86/borland Posting-Frequency: monthly (21st of every month) Last-modified: 1996/10/13 ------------------------------ Subject: 1. Introduction and Intent This is the x86 Assembly Language FAQ for the comp.lang.asm.x86 and alt.lang.asm newsgroups. This FAQ is posted monthly on or about the 21st of the month on both newsgroups and news.answers, alt.answers and comp.answers. It also is archived at the normal FAQ archival sites and the SimTel mirror sites in the msdos/info directory. Lastly, the current version is available from my web page as: As text files: http://www2.dgsys.com/~raymoon/faq/asmfaq.zip As html documents: http://www2.dgsys.com/~raymoon/faq/asmfaqh.zip Currently, this FAQ is broken into six sections. The following are the section filenames and the scope of each section of the FAQ. assembly-language/x86/general/part1 - This is the basic portion of the FAQ that contains information of interest to all assembly language programmers. In general, the information contained in this portion of the FAQ is not specific to any particular assembler. assembly-language/x86/general/part2 - This is a continuation of the above FAQ. assembly-language/x86/general/part3 - This is a continuation of the above FAQ. assembly-language/x86/microsoft - This portion of the FAQ contains information specific for the Microsoft MASM. assembly-language/x86/borland - This portion of the FAQ contains information specific for the Borland TASM. assembly-language/x86/a86 - This portion of the FAQ contains information specific for the Shareware A86 Assembler and D86 Debugger. The scope and content of this FAQ is to go beyond just answering the frequently asked questions. I am including pointers to assembly language treasure troves that are hidden out on the internet. I believe that this will enhance the FAQ's value not only to the novices but also to the old hands. For the ease of determining what has changed since the last FAQ, the Table of Contents will have "REVISED" at the end of the subject line for all revised subjects. If more than one FAQ revision has been missed, the "Last Changed:" entry at the end of each subject can be used to determine which subjects have been revised during the intervening time frame. The information in this FAQ is free for all to use as long as you acknowledge the source. This FAQ can be reproduced in part or in its entirety as long as the copyright is included. This FAQ can be made available on public servers, like ftp, gopher or WWW servers. Please do not modify the file, such as converting it into some other format, without prior permission of the author. All references to files and locations are in Uniform Resource Locators (URLs) format. Some web browser will be able to use these URLs directly as hot links. If the format is not clear to you, get RFC 1738. It is available from: ftp://is.internic.net/rfc/rfc1738.txt Suggestions for changes and comments are always welcome. They can be posted to either newsgroup or e-mailed directly to the me. Author: Raymond Moon, raymoon@moonware.dgsys.com Copyright 1996 - Raymond Moon ALL RIGHTS RESERVED Last Changed: 13 Oct 96 ------------------------------ Subject: 2. Table of Contents 1. Introduction And Intent 2. Table Of Contents 3. TASM Ideal Mode 4. Borland TASM Information 5. Borland tools/Windows 95 Interworking Patches Available 6. Borland TASM List Server 7. FREELIB, Version 2.2 ------------------------------ Subject: 3. TASM Ideal Mode 3.1 SUMMARY TASM, Borland's assembler, supports an alternative to MASM emulation. This is known as Ideal mode and provides several advantages over MASM. The key (questionable) disadvantage, of course, is that MASM style assemblers cannot assemble Ideal mode programs. 3.2 MEMORY CONTENTS Square brackets are used consistently to refer to memory contents. Notice that size qualifiers are not necessary when TASM has enough information by context to figure out the data size involved. Here are some examples without segment details: ByteVal db ? ; "ByteVal" is name of byte variable mov ax, bx ; OK: Move value of BX to AX mov ax, [bx] ; OK: Move word at address BX to AX. Size of ; destination is used to generate proper object ; code mov ax, [word bx] ; OK: Same as above with unnecessary size ; qualifier mov ax, [word ptr bx] ; OK: Same as above with unnecessary size ; qualifier and redundant pointer prefix mov al, [bx] ; OK: Move byte at address BX to AL. Size of ; destination is used to generate proper object ; code mov [bx], al ; OK: Move AL to location BX mov ByteVal, al ; Warning: "ByteVal" needs brackets mov [ByteVal], al ; OK: Move AL to memory location named "ByteVal" mov [ByteVal], ax ; Error: unmatched operands mov al, [bx + 2] ; OK: Move byte from memory location BX + 2 to ; AL mov al, bx[2] ; Error: indexes must occur with "+" as above mov bx, Offset ByteVal ; OK: Offset statement does not use brackets mov bx, Offset [ByteVal] ; Error: offset cannot be taken of the contents ; of memory lea bx, [ByteVal] ; OK: Load effective address of "ByteVal" lea bx, ByteVal ; Error: brackets required mov ax, 01234h ; OK: Move constant word to AX mov [bx], 012h ; Warning: size qualifier needed to determine ; whether to populate byte or word mov [byte bx], 012h ; OK: constant 012h is moved to byte at address ; BX mov [word bx], 012h ; OK: constant 012h is moved to word at address ; BX STRUCTURE REFERENCES Ideal mode handles structured records beautifully. When referring to structure members the dot operator is used. The name to the left of the dot is always the address of a structure and the name to right is always a structure member. Ideal mode permits member names to be duplicated in different structures. Here is a simple example, again without segment details: Struc PosType Row dw ? Col dw ? Ends PosType Union PosValType Pos PosType ? Val dd ? Ends PosValType Point PosValType ? mov [Point.Pos.Row], bx ; OK: Move BX to Row component of Point mov [Point.Pos.Row], bl ; Error: mismatched operands INDIRECTION Ideal mode enforces type-size checking even with indirected references. Using the above structure, here is how indirection is handled. BX is assumed to point to an instance of PosValType in memory. Indirection is used frequently when pointers are passed to procedures. mov [(PosValType bx).Pos.Row], ax ; OK: Move AX to Row component of PosValType instance ; pointed to by BX mov [bx + PosValType.Pos.Row], ax ; OK: same as above mov [bx + PosValType.Pos.Row], al ; Error: mismatched operands SEGMENT GROUPS The Offset operator always evaluates the offset of a data instance relative to its group, not its segment. This allows Offset to be used without qualifying each reference with the appropriate group name. Labels in a segment could be used to determine segment offsets if needed. RESOURCES Books and files which will be of interest to programmers wishing to know more about the Ideal mode of Borland's TASM assembler include the following: Turbo Assembler User's Guide / Borland International. ------------------------------------------------------------------ Naturally, this is the definitive text on Ideal mode. Its focus is strictly on using TASM; it does not cover assembly language or the x86 instruction set. Exasperatingly, the examples in the book all use MASM emulation mode, and only one of the four complete program examples included with TASM (at least version 3.1) uses Ideal mode. The example that does use Ideal mode is a very flexible WHEREIS program. Studying this 13 file example should be sufficient for anyone wishing to understand Ideal mode. Mastering Turbo Assembler / Tom Swan. Indianapolis, IN: Hayden Books, c 1989. ----------------------------------------------------------------------- This book is not just another Microsoft Assembler book reprinted with a Turbo Assembler cover. Swan uses and promotes Ideal mode throughout. This is a great beginning text for programmers who are still hassling with the ubiquitous non-reentrant interrupt handler known as DOS. It includes an overview of the x86 instruction set. SKEL32.ZIP / Bill Magaletta. Obtainable by ftp at hobbes.nmsu.edu:/os2/32bit/program as well as ftp-os2.cdrom.com and CompuServe ----------------------------------------------------------------------- This is a standalone 32 bit OS/2 Ideal mode program, the simplicity of which will make converts of DOS programmers dealing with interrupts and segments. It includes an overview of the initial register states of DOS and OS/2 programs. This example illustrates the fact that TASM for DOS can be used to produce object files for OS/2. Contributor: Kurt Jung, kwjung@vela.acs.oakland.edu Last changed: 17 Jan 95 ------------------------------ Subject: 4. Borland TASM Information 4.1 Borland FTP Site Borland maintains a ftp site which has a directory dedicated to TASM. Most entries are patches and HOW-TOs, but there is a shell for TSRs that will load and unload either high or low. ftp://ftp.borland.com/pub/techinfo/techdocs/language/tools/turboasm 4.2 Borland Web Site At Borland's Web Site, I only could find product and ordering information on TASM. The only reference to technical information was a pointer to Borland's ftp site. Contributor: Ray Moon, raymoon@moonware.dgsys.com Last changed: 11 Nov 95 ------------------------------ Subject: 5. Borland tools/Windows 95 Interworking Patches Available 5.1 TASM32/H2ASM/H2ASM32 FAIL UNDER WINDOWS95 Using the 32bit tools from Borland C++ 4.5 / TASM 4.0 under Windows 95 can fail when the DOS based tools tools are called from the Windows IDE. The nature of the problem is that any attempt to specify a commands file using the @ style argument will fail due to an incompatability between Windows 95 long filenames, and the TASM32.EXE file-open code. Note that by default the Borland C++ 4.5 IDE uses the @ directive for launching TASM32.EXE if 32bit instructions (which are not handled by the inline C++ assembler) are encountered in a user's source. Although the Borland tools reportedly use the PowerPack DPMI extensions for their 32bit operation, user applications which use the Powerpack libraries do not seem to be affected by this problem. A patch is available to correct this issue from location: ftp://ftp.borland.com/pub/techinfo/techdocs/language/tools/turboasm/ta4p01.zip This should be applied using the patcher executable from location: ftp://ftp.borland.com/pub/techinfo/techdocs/language/cpp/bcpp/patch/patch.zip Contributor: Iain Barker, ibarker@bnr.ca Last changed: 19 Feb 96 ------------------------------ Subject: 6. Borland TASM List Server 6.1 DESCRIPTION There is a list server available that is devoted to Borland's TASM Assembler. 6.2 JOINING To join send e-mail to: listserv%brufpb.bitnet@listserv.net with the phrase subscribe TASM-L your name in the text. 6.3 SENDING E-MAIL TO ALL MEMBERS To send e-mail to all members, send the e-mail to: tasm-l%brufpb.bitnet@listserv.net Contributor: Ray Moon, raymoon@moonware.dgsys.com Last changed: 17 Feb 96 ------------------------------ Subject: 7. FREELIB, Version 2.2 FREELIB is a library of 170 assembly language procedures written by Tenie Remmel. Full source code is available and is written for the 80186 processor using the TASM ideal mode. Lastly, the procedures use the Pascal calling protocol. As the name implies, the author place the library into the public domain, completely free for all non-commercial use. If you find this library useful, users are strongly encouraged to contribute some of your own routines for possible addition to FREELIB. The library is available from SimTel: ftp://www.cdrom.com/pub/simtelnet/msdos/asmutil/freeli22.zip Contributor: Ray Moon, raymoon@moonware.dgsys.com Last changed: 14 Sep 96 From short!circuit!express.ior.com!news.sprintlink.net!news-chi-8.sprintlink.net!news.sprintlink.net!news-hub.sprintlink.net!news.sprintlink.net!news-peer.sprintlink.net!www.nntp.primenet.com!nntp.primenet.com!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon Sat Nov 23 15:45:57 1996 Path: short!circuit!express.ior.com!news.sprintlink.net!news-chi-8.sprintlink.net!news.sprintlink.net!news-hub.sprintlink.net!news.sprintlink.net!news-peer.sprintlink.net!www.nntp.primenet.com!nntp.primenet.com!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!uunet!in1.uu.net!en.com!news.dgsys.com!DGS.dgsys.com!raymoon From: raymoon@dgsys.com (Raymond Moon) Newsgroups: alt.lang.asm,comp.lang.asm.x86,news.answers,alt.answers,comp.answers Subject: x86 Assembly Language FAQ - A86 and D86 Date: 20 Nov 1996 18:08:17 GMT Message-ID: <56vheh$sl@news.dgsys.com> Followup-To: alt.lang.asm,comp.lang.asm.x86 Reply-To: raymoon@moonware.dgsys.com Organization: MoonWare Expires: Fri, 20 Dec 1996 23:59:59 GMT Distribution: world Keywords: x86 Assemby Language ASM FAQ A86 D86 Summary: This is the FAQ for the x86 Assembly Language programmers for the alt.lang.asm and comp.lang.asm.x86 newsgroups. This particular section of the FAQ contains x86 assembly information specific to the Eric Isaacson's shareware A86 assembler and D86 debugger. Approved: news-answers-request@MIT.EDU Lines: 261 Supersedes: <54git5$v0i@news.dgsys.com> NNTP-Posting-Host: dgs.dgsys.com X-Newsreader: TIN [version 1.2 PL2] Xref: short alt.lang.asm:5632 comp.lang.asm.x86:15379 Archive-Name: assembly-language/x86/a86 Posting-Frequency: monthly (21st of every month) Last-modified: 1996/10/13 ------------------------------ Subject: 1. Introduction and Intent This is the x86 Assembly Language FAQ for the comp.lang.asm.x86 and alt.lang.asm newsgroups. This FAQ is posted monthly on or about the 21st of the month on both newsgroups and news.answers, alt.answers and comp.answers. It also is archived at the normal FAQ archival sites and the SimTel mirror sites in the msdos/info directory. Lastly, the current version is available from my web page as: As text files: http://www2.dgsys.com/~raymoon/faq/asmfaq.zip As html documents: http://www2.dgsys.com/~raymoon/faq/asmfaqh.zip Currently, this FAQ is broken into six sections. The following are the section filenames and the scope of each section of the FAQ. assembly-language/x86/general/part1 - This is the basic portion of the FAQ that contains information of interest to all assembly language programmers. In general, the information contained in this portion of the FAQ is not specific to any particular assembler. assembly-language/x86/general/part2 - This is a continuation of the above FAQ. assembly-language/x86/general/part3 - This is a continuation of the above FAQ. assembly-language/x86/microsoft - This portion of the FAQ contains information specific for the Microsoft MASM. assembly-language/x86/borland - This portion of the FAQ contains information specific for the Borland TASM. assembly-language/x86/a86 - This portion of the FAQ contains information specific for the Shareware A86 Assembler and D86 Debugger. The scope and content of this FAQ is to go beyond just answering the frequently asked questions. I am including pointers to assembly language treasure troves that are hidden out on the internet. I believe that this will enhance the FAQ's value not only to the novices but also to the old hands. For the ease of determining what has changed since the last FAQ, the Table of Contents will have "REVISED" at the end of the subject line for all revised subjects. If more than one FAQ revision has been missed, the "Last Changed:" entry at the end of each subject can be used to determine which subjects have been revised during the intervening time frame. The information in this FAQ is free for all to use as long as you acknowledge the source. This FAQ can be reproduced in part or in its entirety as long as the copyright is included. This FAQ can be made available on public servers, like ftp, gopher or WWW servers. Please do not modify the file, such as converting it into some other format, without prior permission of the author. All references to files and locations are in Uniform Resource Locators (URLs) format. Some web browser will be able to use these URLs directly as hot links. If the format is not clear to you, get RFC 1738. It is available from: ftp://is.internic.net/rfc/rfc1738.txt Suggestions for changes and comments are always welcome. They can be posted to either newsgroup or e-mailed directly to the me. Author: Raymond Moon, raymoon@moonware.dgsys.com Copyright 1996 - Raymond Moon ALL RIGHTS RESERVED Last Changed: 13 Oct 96 ------------------------------ Subject: 2. Table of Contents 1. Introduction And Intent 2. Table Of Contents 3. What is A86 Assembler and Where Can I Get It 4. Structuring Assembly Language in A86 5. A386/D386 Availability 6. A86 Source Code Site 7. Eric Isaacson's A86 Assembler and D86 Debugger Web Page 8. Acknowledgments ------------------------------ Subject: 3. What is A86 Assembler and Where Can I Get It 3.1 A86 ASSEMBLER - A86V402.ZIP The A86 is Eric Isaacson's shareware assembler. The latest version is 4.02 and support up to the 286 instruction set. This assembler does not support the extended registers and instructions introduced with the 386 processor. This assembler accepts assembly language source files, and transforms them directly into either: (1) .COM files executable under MS-DOS, starting at offset 0100 within a code segment; (2) .OBJ files suitable for feeding to a linker; or (3) object files starting at offset 0, suitable for copying to ROMs. A86 is a full featured program designed to be as closely compatible to the standard Intel/IBM assembly language as possible. Some of A86's features are: * Assembly speed * Ease of use * Support modular programming even in .COM files * Support very large programming projects * Full featured macro capability * Support for math coprocessor instructions * Supported by its own debugger, D86 New features of version 4.02 are: * INCLUDE file support * listings * no limit on size of sourse files * forward references in complex expressions * END operand * default ORG END in DATA SEGMENT 3.2 D86 DEBUGGER - D86V402.ZIP The D86 is Eric Isaacson's shareware debugger. The latest version is 4.02. D86 is a screen-oriented debugger that facilitates the troubleshooting of faulty computer programs written for the IBM-PC and all compatibles. D86 can freeze the state of a program so that the values of registers, flags, and memory can be investigated. The program's execution can be monitored by stepping it one instruction or procedure at a time; or starting the program running, telling D86 to stop it when it reaches certain locations. D86 recognizes the symbol-table output of the A86 assembler, creating a symbolic disassembly of a A86 program, and allowing referenced to locations and variables by name. Some of D86's features are: * Values of registers, flags and stack top are displayed at a fixed location on the screen. * Support for viewing memory contents in a variety of types including complicated structures. * Support for displaying math coprocessor registers New features of version 4.02 are: * Keystroke scripts * macro keys * Undo command * file copy and delete 3.3 OTHER FILES A86CNVRT.ZIP This file contains information on converting MASM files into A86 files. The information is dated and a better source is Chapter 12 of the A86 documentation. D86BIOS4.ZIP If your computer does not have an IBM-compatible BIOS, this file will help getting D86, the debugger, to work with your BIOS. 3.4 FILE AVAILABILITY All files are available from SimTel ftp://ftp.coast.net/SimTel/msdos/asmutil mget ?86* For all files or mget ?86v402.zip or the basic A86 and D86 files Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 4 Nov 95 ------------------------------ Subject: 4. Structuring Assembly Language in A86 John Barnes has converted the macros from Kurt Schindler's "Structure: The Complete Toolkit for Structuring Assembly Language Programs." John Barnes warns that the every macro has not been proofed and tested completely. These macros are available from SimTel. ftp://ftp.coast.net/SimTel/msdos/asmutil/struca86.zip Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 8 Jan 95 ------------------------------ Subject: 5. A386/D386 Availability I have received the following information about A386/D386 availability from the author, Mr.Eric Isaacson: A preliminary version of A386+D386 currently is shipping on the registered A86+D86 disk. The A386 implements the entire 386/486/Pentium instruction set, including 32-bit registers, 32-bit expression arithmetic, and 32-bit memory indexing. The only major feature not yet implemented is segments of type USE32 (i.e., flat mode). There is not any schedule date for completing that last feature. Note that the A86-only registered disk does not have A386. the A386 disk is available for $80 to get A386 ($82 overseas, $84 in Indiana). The printed manual that covers everything is an additional $10 ($15 overseas, $10.50 in Indiana). If you already have registered A86+D86, the A386 disk is available for the normal update service fee of $10 ($12 overseas, $10.50 in Indiana). If A86 but not D86 is registered, the A386 disk is available for $40 ($42 overseas or Indiana). Again, the printed manual is extra. Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 20 May 95 ------------------------------ Subject: 6. A86 Source Code Site Jim Tucker has informed me that the site where his a86 files were kept has crashed. If and when these files become available again, I will reinstate this section. Contributor: Ray Moon, raymoon@moonware.dgsys.com Last changed: 13 Oct 96 ------------------------------ Subject: 7. Eric Isaacson's A86 Assembler and D86 Debugger Web Page 7.1 A86/D86 WEB PAGE Eric Isaacson has his own web page for the A86 Assembler and the D86 Debugger. The URL is: http://eji.com/a86/index.htm The topics of this page are: Overview of A86 Overview of D86 A86 and D86 Features A386 and D386 Status Downloading A86 and D86 7.2 GETTING A86 AND D86 STRAIGHT FROM THE HORSES MOUTH As indicated above, you can get the A86 assembler and D86 Debugger right from the author's web site. The URLs are: For A86: http://eji.com/a86.zip For D86: http://eji.com/d86.zip Contributor: Raymond Moon, raymoon@moonware.dgsys.com Last changed: 16 Apr 96 ------------------------------ Subject: 8. Acknowledgments I would like to acknowledge all the people who have assisted me or any of the contributors. For their time and effort, this FAQ is a better product. John Krueger and Gary Smith