Subject: x86 Assembly Language FAQ - General Part 3/3
Supersedes: <4bacdv$ol3@news.dgsys.com>
Date: 24 Jan 1996 01:06:14 GMT
Expires: Tue, 20 Feb 1996 23:59:59 GMT
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.
X-Newsreader: TIN [version 1.2 PL2]

Archive-name: assembly-language/x86/general/part3
Posting-Frequency: monthly (21st of every month)
Last-modified: 1996/01/17

------------------------------

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://ftp.coast.net/SimTel/msdos/asmutil

25.2  A86

This assembler is a very capable assembler for 89286 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.

25.5  WOLFWARE ASSEMBLER, WASM202.ZIP

This assembler was written by Mr. Eric Tauck.  The latest version is 2.02
and dates from 1987.  This assembler supports only the 8088 processor and
assembles directly into a .com 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.

25.6 MAGIC ASSEMBLER, ASM106.ZIP

This assembler is the very new.  The version is 1.06 and dates from
September 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.06 are:
    LEA command added               Binary and decimal numbers recognized
    Example programs added          Remark bug fixed
    EQU command improved

25.7 GEMA, GEMA.ZIP

This assembler revision is 2.6a with a date, 4 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 availabe 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.1, NASM.ZIP

The birth of this assembler started out of a thead 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 under construction
is:

    http://www.dcs.warwick.ac.uk/~jules/nasm1.html (new address)

The source code for the assembler is available (anonymous logons no longer
accepted.  I am trying to find out why or from where else the source can be
obtained):

    ftp://frmap711.mathp7.jussieu.fr/pub/scratch/rideau/nasm/nasm.zip
    ftp://callisto.girton.cam.ac.uk/pub/sgt20/nasm.zip
        This is an experimental FTP site.  If you do not get through, keep
        trying.

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 not 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 Internationa 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. 

Contributor:  Raymond Moon, raymoon@moonware.dgsys.com
Last changed: 17 Jan 96

------------------------------

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

Assembly Language Resources
    http://www.cera.com/assembly.htm

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.feldspar.com/~mbabcock/Programming/asmtut1.htm
        Mike Babcock's ASM Tutorial

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 (all of these are in the process of moving. 
These are then new addresses.  Everything may not be working yet.)
    http://www.x86.org/
        Collins' home page
    http://www.x86.org/undoc
        Intel Secrets - undocumented OpCodes, links to Intel's on-line
            documentation, the infamous Appendix H, P6 OpCodes, and much,
            much more  
    http://www.x86.org/mrbios/mrbios.html
        Shareware BIOS
    http://www.x86.org/articles/articles.html
        Growing list of on-line Intel documentation and magazine articles
            by Robert Collins and Ralf Brown
    http://www.x86.org/P6/P6.html
        Pentium Pro Information including New Opcodes, Paging Extension,
            CPUID and manuals.
    http://www.x86.org/articles/pmbasics
        Protected Mode Basic - a tutorial on PM with souce code.

Christian Ludloff's 80x86.CPU home page
    http://www.x86.org/4p/
        This home page includes new information about many Intel processors
            and their clones.  This information is of interest to system
            software authors.

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.feldspar.com/~nbabcock/Programming/pIndex.html
        This home page has links to:
            Optimizing 803/4/586 ASM Programming
                http://www.feldspar.com/~mbabcock/Programming/Optimize.html
            ASM Tutorial
                http://www.feldspar.com/~mbabcock/Programming/asmtut1.htm
            Utilities
                http://www.feldspar.com/~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.

Yahoo/Computers and Internet/Languages/Assembly page
    http://www.yahoo.com/Computers/Languages/Assembly
        Link to ASM Language Tutorial (see above)
        Link to alt.lang.asm newsgroup
        Link to Intel 80x86 page which has a link to comp.lang.asm.x86
            newsgroup
        Link to the Professional Programmers' Page

Lycos Search: Assembly Language
    http://lycos-tmp1.psc.edu/cgi-bin/pursuit?query=assembly+language
        Preset search of the Lycos database for assembly language related
        sites.

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://hamton.eng.ua.edu:80/college/people/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.

80xxx Snippets - A file site for 80x86 Assembly Language enthusiasts
    http://www.poweramp.net/~jvahn/
        Download snippets & Booklist

Contributor:  Raymond Moon, raymoon@moonware.dgsys.com
Last changed: 15 Dec 95

------------------------------

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 knows 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 that 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 calculate 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 in
the last segment, a label 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   0c19h
    Sec & Hundrenths    41:94   2956h               3556: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: 26 Dec 95

------------------------------

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 the the document is the
Relocatable Object Module Format Specification, V1.1.  

Unfortunately, both files unzip into documents formated 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 include 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 flat 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 or 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 check 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

Contributor:  Raymond Moon, raymoon@moonware.dgsys.com
Last changed: 8 Jan 96

------------------------------

Subject: 33. 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, Kris Heidenstrom, Alan Illeman, Chabad Lubavitch, Jeff Owens,
Russell Schulz, Rocky Seelbach, Janos Szamosfalvi and Cedric Ware 


