MICROSOFT`S MASM 6.0/6.1 ASSEMBLERS

Using Microsoft`s excellent MASM 6.0/6.1 Assemblers to teach a newcomer assembly language is much like trying to solo a new student pilot in a Concorde SST or Boeing 747. This is why so many experienced assembly language teachers prefer starting 1st semester assembly language courses using Eric Isaacson`s shareware A86 Macro Assembler since it will handle the Intel instruction set up through the 80286.

A86.COM is an outstanding primary trainer. Starting a new student on the MASM 6.1 assembler is like turning the AT-6 training aircraft upside down on the 1st dual instruction flight and telling him "you`ve got it." The student will never come back again.

Do we use MASM 6.1? Sure we do whenever the program requires an .EXE file larger than 65,535 bytes. My "Protected Mode" program that WAS downloadable from this homepage's list was written using the Microsoft Macro Assembler. It is really an excellent assembler once one learns all its foibles and crazy bananas options.

Using assembly language versus high level languages such as Fortran, Cobol, Ada, Pascal, C++ or Basic you will be amazed to discover that the assembly language version is about 1/3rd the size of the identical program written in a high level language and will run 3 to 10 times FASTER.

What follows is part of the documentation for my protected mode protek.exe program that was assembled with Microsoft's excellent MASM 6.1 assembler. EN32.DOC: version 2.2

ONLY FOR HIGHLY ADVANCED ASSEMBLY LANGUAGE PROGRAMMERS

PROTECTED 32 BIT MODE READ/WRITE 4 GIGABYTES EXTENDED MEMORY
PROTECTED 32 BIT MODE EXIT TO REAL MODE EDMOD.OBJ AND RETURN
PROTECTED 32 BIT MODE SEARCH 4 GIGABYTES FOR STRING UP TO 30
PROTECTED 32 BIT MODE SAVE 64K BLOCK OF MEM 0 TO 4 GIGABYTES
PROTECTED 32 BIT MODE DISPLAY DATE/TIME WITHOUT GO REAL MODE
PROTECTED 32 BIT MODE DISPLAY VGA PAGE BY GOING TO REAL MODE
DETAILS TO WRITE YOUR OWN 32 BIT PROTECTED MODE DOS EXTENDER

EN32.EXE is a fascinating FREEWARE program that illustrates: how to enter 32
bit protected mode, EDIT MODE (read) up to 4 Gigabytes of memory, MODIFY MODE
(write) any byte/bytes in up to 4 Gigabytes of memory, exit to real mode's
EDMOD.OBJ which has a KISS mini-disassembler, and return to protected mode.
The assembly language source code is included in the files EN32.ASM,
DATASEG.ASM (data segment source code which is common to both Code16 and
Code32 functions), GRAPHICS.ASM (source code to display 7 VGA .PCX format
graphics pages) and DIZDOC.ASM (display EN32.DOC documentation). It may be
assembled using Microsoft's Macro Assembler version 6.1 with the command line:
ML /Zm EN32.ASM.

DOS version 6.2 is recommended when running EN32.EXE from C:\PROTEK. If you
have run WINDOWS 3.1 with your own CONFIG.SYS and AUTOEXEC.BAT file on C:'s
root directory, and then run EN32.EXE, it will report an error when you run it
as TWO protected mode initializations are a NO NO. Nevertheless, you may
run WINDOWS 3.1 under the new CONFIG.SYS and AUTOEXEC.BAT files as long as
your C:\WINDOWS\SYSTEM subdirectory contains the file: VTDAPI.SYS and you have
at least 1 megabyte of extended memory. Be sure your computer boots on the
CONFIG.SYS and AUTOEXEC.BAT files provided here, otherwise Windows is a NO GO.

The modestly commented source code files, EN32.ASM, DATASEG.ASM, GRAPHICS.ASM,
and DIZDOC.ASM, written in 80386 assembly language are included which will
serve as a tutorial on 32 bit protected mode programming for newcomers to
protected mode assembly language programming. Were they written in C++ using
a DOS Extender (see below), EN32.EXE would be much larger and much slower.
Tiny Tim says, 'real men write in assembler, but nevertheless lots of luck to
all C++ programmers.'

The program requires an 80386, 80386SX, 80486, 80486SX or Pentium
microprocessor. Two megabytes or more extended memory would be helpful in
exploring protected 32 bit mode's extensive memory capabilities. The F4 key
when pressed, displays standard VGA graphics pages. It obviously requires that
a VGA adaptor be installed in your computer. If not, do not use it.

NOTE:
None of the familiar DOS software interrupts are available in protected mode.
All the multitudinous DOS extenders, Phar Lap, etc., do when a DOS interrupt
is encountered, is to switch back to real mode, perform the the interrupt
function(s), and then switch back to protected mode. EN32.EXE does the same
thing using bp as a pointer to which routine/interrupt(s) to use, and then
switches back to 32 bit protected mode. See SWITCHING TIMES below.

Many ports are unchanged in protected mode though and still active. EN32.EXE
uses many port functions up through port 71h.

EN32.DOC is most easily read with BROWSE.COM which is included on the demo
disk. Type in BROWSE A:\EN32.DOC or BROWSE C:\PROTEK\EN32.DOC and press
enter. PgUp, PgDn, down arrow and up arrow are active. Use Esc key to exit.

F1 Up 1024 bytes Up 64k bytes 0008
Down 1024 bytes Up 1 megabyte 03FF
HELP Toggle modify mode Up 16 megabyte
F2 No memory there Start over SP

FS segment is set to a full 4 Gigabyte size = 0 to FFFFFFFF hexadecimal = 0 to
4,294,967,295 decimal.

When a memory location is described in real mode as 8000:0000h, in 32 bit
protected mode mode it is described at 00080000h as illustrated above. The
double memory locations illustrated above (one below another) are sequential
to allow all 1024 bytes to fit in each page's rectangle, above.

Taking each heading from top left to the bottom and right from the top right
to the bottom are:

BEGIN:

The memory location in the FS segment from 0 to FFFFFFFF hexadecimal. First
4 bytes displayed followed by second 4 bytes below.

MEMORY:

In EDIT MODE it displays the second 4 bytes of BEGIN. In MODIFY MODE it
displays the cursor (blinking byte) location on the page. In MODIFY MODE the
cursor may be moved with the keypad arrow keys and enter key. The Ins key
toggles MODIFY MODE on - EDIT MODE off, EDIT MODE on - MODIFY MODE off.

VALUE:

Hexadecimal of value of the byte beneath the cursor at MEMORY location on the
displayed page only when in MODIFY MODE. In EDIT MODE it displays the byte
value at the memory location displayed in BEGIN.

EDIT MODE:

Switch (toggle) between EDIT MODE and MODIFY MODE with the Ins key.

HEX INPUT:

When in either in SEARCH MODE (press the S key in EDIT MODE to switch to
SEARCH MODE), or any time in MODIFY MODE pressing the F3 key will change INPUT
beneath HEX to four blinking ????. Now press the 0 to 9 or A to F keys
'twice' to input the hexadecimal value from 00 to FF. Upon the second key
press the 4 blinking question marks if in MODIFY MODE will switch back to
INPUT and the value you input will be inserted into memory beneath the cursor.

HELP F1:

Pressing the F1 key displays the window below. Pressing any key erases it.

º PROTECTED USE32 MODE HELP 1 º
º BEGIN and END are the hex locations of º
º the 1024 byte page displayed. FS seg- º
º ment covers 0 to 4,294,967,295 decimal.º
º º
º move down 64k bytes º
º move down 1 megabyte º
º move down 16 megabytes º
º º
º MODIFY MODE: most keys replace memory º
º beneath cursor. Do NOT modify the BIOS,º
º EN32.EXE, or EDMOD.OBJ. ! Beware ! º
º º
º Ctrl key go to EDMOD in real mode º
º Del key EDMOD return protected º
º º
º 'S' key EDIT MODE will search 16 megs. º
º Use F3 for hex input in MODIFY MODE. º
º º
º Use the F10 key for Print Screen º
º Press F4 displays 7 VGA graphics pages.º
º Please read EN32.DOC. º

Pressing the F2 key displays the window below. Pressing any key erases it.

º PROTECTED USE32 MODE HELP 2 º
º EDIT MODE: º
º The 'f' key will save the current mem- º
º ory +64k on A. Any mem 0 to FFFF0000h º
º ok. The file name will be CODEx.MEM. º
º The 'S' key will go to search mode. º
º Input the search string and . º
º Press F3 to input hexadecimal. º
º º
º MODIFY MODE: º
º Press F3 to input hexadecimal. º
º º
º ALL MODES: º
º Press F10 for Print Screen. º
º Esc key exits all functions. º
º º
º REMEMBER: the DEL key º
º returns to protected mode from EDMOD. º
º F3 displays Pentium exception summary. º
º F7 displays EN32.DOC documentation. º

Pressing the F3 key displays the window below. Pressing any key erases it.

º PENTIUM EXCEPTION SUMMARY HELP 3 º
º divide error 0 º
º debug exception 1 º
º none 2 º
º breakpoint 3 º
º overflow 4 º
º bounds check 5 º
º invalid opcode 6 º
º device not available 7 º
º double fault 8 º
º coprocessor segment overrun (80386) 9 º
º invalid Task State Segment 0AH 10 º
º segment not present 0BH 11 º
º stack exception 0CH 12 º
º general protection (catch all) 0DH 13 º
º page fault 0EH 14 º
º none 0FH 15 º
º floating-point error 10H 16 º
º alignment check 11H 17 º
º machine check 12H 18 º
º software interrupt 0 to 255 º

These are the values displayed on exception exits to DOS>. An exception is an
error generated by protected mode. The normal exit from protected mode
displays INTERRUPT 14H = no error.

RIGHT HAND COLUMN DISPLAYS:

The CS, DS, ES, GS segment start locations in memory. The start locations of
the CS and DS segments will vary depending the number and size of the TSR
programs you may have installed. A mouse driver TSR is NOT recommended as
real mode interrupts are not valid in protected mode. NO TSR's are
recommended.

END displays the memory location of the end of the 1024 byte page that is
displayed.

SP displays the stack pointer that may be helpful should you chose to modify
the program yourself.

SAVE 64K FILE OF PROTECTED MODE MEMORY - ANY LOCATION:

In EDIT MODE pressing the f or shift f key will display:

º SAVE 64K SORT OF EXPANDED MEM MANAGER º

º All the exotic QEMM, et al expanded mem º
º managers fundamentally do is to move º
º a 64k block of extended memory into an º
º unused upper mem block usually between º
º segment C000H and F000h. º
º º
º Our KISS expanded mem manager will do º
º a similar fancy footwork trick (if you º
º choose to save extended mem) by moving º
º the 64k extended mem block into normal º
º memory, then exiting protected mode to º
º real mode, then saving the file on A:\, º
º and finally returning to protected mode.º
º º
º The saved files will be named CODE1.MEM º
º sequentially up to CODE9.MEM. º
º º
º Press Enter to continue or Esc to exit. º

This function will save the current BEGIN memory location plus 64k on A:.

ANY memory location from 0 to FFFF0000h may be saved. The screen will
temporarily blank, the floppy motor spun up, and the file saved. If the
floppy door is open or a non-formatted disk is in A:, you will be reminded
to fix it, and then the program will return to protected mode. Try again.

Each successive 'f' key press in EDIT mode will increment the file name up to
CODE9.MEM. On A:\ drive you may read each saved file by typing in:
TYPE CODEx.MEM and press enter. x is the number 1 to 9.

The program does more fancy footwork to allow you to read the saved file with
the simple TYPE command from the command line; i.e., the following values are
changed to ASCII 30H = the zero character:

1AH end of file (EOF) -> '0'
0DH carriage return -> '0'
0AH line feed -> '0'
09H horizontal tab -> '0'
08H backspace -> '0'
07H annoying BELL -> '0'
00H (blank) -> '0'

At the DOS> prompt on A: drive, type TYPE CODE1.MEM.

Should you wish to override this 'behind your back' fix up and save the file
'raw' where is/as is, press SHIFT f instead of f.

SEARCH FIRST 16 MEGABYTES OF PROTECTED MODE MEMORY:

Pressing the s or shift s key in EDIT MODE will switch to SEARCH MODE. The
screen will clear and display on the top line

'Input search & press enter. F3 for hex. 00000000'

The search string may be ASCII and/or hex up to 30 characters in length. The
found locations will be displayed in columns of 8 bytes top to bottom and then
if more found, additional top to bottom columns, left to right.

The upper right corner of the screen will display the memory location being
searched in increments of 64k in hexadecimal.

Pressing the Esc key before the full 16 megabytes has been searched will beep
and await another key press. Press the F10 key to Print Screen. Any other
key will return to normal EDIT MODE.

The full 16 megabyte search with a 16 MHz 80386 takes approximately 2+ minutes
= about 8 1/2 seconds per megabyte which illustrates the rather fast searching
algorithm. If you are using an 80486DX/2 at 66 MHz it goes supersonic.

If your search finds more than a full pages of matches, it will pause between
pages and await an (any key) key press.

Since the EN32.ASM source is provided you may modify the search routine to
cover the full 4 Gigabytes if you wish. Just change EN32.ASM's cmp_big:
from cmp edi,1000000h to cmp edi,10000000h.

IN EDIT MODE PRESSING F4 KEY DISPLAYS A 640x480 16 COLOR VGA GRAPHICS PAGE:

In real mode it requires the following interrupts to display a VGA graphics
file when starting from text mode:

AH,3Dh INT 21h ;open file
AX,4202h INT 21h :determine length of file
AX,4200h INT 21h :move to file beginning
AH,3Fh INT 21h :read file
AH,3Eh INT 21h :close file
AX,12h INT 10h :set VGA 640x480 16 color graphics mode
AX,1013h INT 10h :set attribute controller color select state
AX,1012h INT 10h :update 16 each video DAC color registers
AX,3h INT 10h :return to 80x25 16 color text mode

Anyone that would enjoy disassembling these real mode interrupts and rewriting
them for protected mode is a glutton for cruel and unusual punishment.

EN32.EXE avoids this punishment by near instantly switching to real mode,
loading the VGA graphics file in C:\PROTECT\VGA1.PCX to real mode's segments
6000h (and 7000h if necessary), and unpacking it to real mode's video segment
A000h where it is displayed.

There are 7 each VGA graphics demo pages. After pressing the F4 key to display
the first VGA graphics page, pressing the Esc key will return to protected 32
bit mode. Any other key will display the next VGA demo graphics page in the
circular queue.

The 3k byte fully commented GRAPHICS.ASM source code file in C:\PROTEK, loads
and displays the .PCX format VGA graphics files. It is only 200+ lines of
source code in length. Note that the GRAPHICS.ASM returns are retn (return
near) instead of ret. Ret (return) by itself works fine once in 32 bit
protected mode.

The first 6 graphics pages are standard VGA 640x480x16 color .PCX format
pages. The 7th is a 320x200x256 color .PCX format page. GRAPHICS.ASM can
unpack and display either variety automatically.

DISPLAYING DATE AND TIME IN PROTECTED MODE:

EN32.EXE's second line displays the date and time on the right. Month-day-
year followed by hour-minutes-seconds. The video page displayed earlier shows
New Year Eve's date at 1 minute before midnight.

Most text books on using extended memory will tell you it is impossible to get
date and time in protected mode without going to Virtual 8086 mode or
reverting to real mode 18.2 times per second with an interrupt handler, if you
need that accuracy. This is not true.

Most all 80386, 80486 and Pentium microcomputers utilize the Motorola
MC146818A Real Time Clock chip, or equivalent. This chip uses a small lithium
battery backup to keep the date and time updated while the computer is turned
OFF.

What the textbook experts overlooked was the fact that you may read the date
and time off this chip in protected mode via ports 70h and 71h, and completely
disregard the Intel 8254 or equivalent timer chip and its associated real mode
interrupts 08h and 1Ah which utilize real mode memory for updating.

The only 'gotcha' with this scenario is that on exiting 32 bit protected mode
to real mode, the program must update real mode's 8254 timer, plus date and
time memory locations which is easily done with ah,2bh and ah,2dh using
interrupt 21h. This is done in EN32.ASM right after the comment 'terminate
this process,' if bp,0. If bp is not zero, the 8254 is not updated. Thus,
if you exit to DOS via EDMOD.OBJ the 8254 will not be updated, so expect a
time error.

EN32.EXE's date and time routine has been tested for a 12 hour period against
an accurate quartz clock and found to be within plus or minus 1 second
accuracy.

SWITCHING TIMES - TO REAL MODE - TO PROTECTED MODE:
--------------------------------------------------

The 32 bit EBP register (base pointer) is used as a pointer when switching
from 32 bit protected mode to to real mode. Approximate switching times are
illustrated below. Times are very conservative.

clock: switch to real mode: switch to protected mode:

16 MHz 360 microseconds 480 microseconds
25 MHz 230 microseconds 308 microseconds
33 MHz 175 microseconds 233 microseconds
66 MHz 88 microseconds 117 microseconds

EN32.EXE uses BP pointers when returning to (Use16) real mode.

BP,1 : save 64K file on A:\drive from current mem location on up.
BP,2 : load EDMOD.OBJ only during initialization.
BP,3 : go to EDMOD.OBJ in real mode.
BP,4 : display 7 VGA graphics pages (Esc key) returns protected mode.
BP,16h ; interrupt 16h DOS extender demo." " " " "
BP,21h ; interrupt 21h DOS extender demo." " " " "

HOW TO WRITE YOUR OWN 32 BIT PROTECTED MODE DOS EXTENDER:

A DOS Extender is an expensive program you purchase from Phar Lap Software,
Ergo Computing, I.G.C., Rational Systems, et al, that allows you to write
programs in C++ that behind your back uses 16 or 32 bit protected mode.
Programs with huge data bases, huge integrated circuit design layouts, etc.,
run faster and more efficiently in protected mode than in real mode using bank
switching memory swapping schemes (LIM 4.0, QEMM386, etc.). For more info
on DOS Extenders, read 'Extending DOS' (see recommended reading below).

EN32.EXE's DS (data segment) includes these variables: saval, savah, savbl
savbh, savcl, savch, savdl, savdh, savax, savbx, savcx and savdx. This data
segment and these variables are common to both (Use16) real mode and 32 bit
protected mode.

All one needs to do is load BP with the real mode interrupt you wish performed
while in 32 bit protected mode, plus the 8 bit [sav] or 16 bit [sav] variables
listed above with the values required, and jump to yt2: (see EXIT PROTECTED
MODE below), which begins the exit to real mode.

In EN32.ASM's Use16 code segment source code, set up an interrupt lookup table
or tests, that for instance that will test bp,16h, if nz ignore, or if not
bp,21h ignore. Interrupts 16h and 21h are the ones we want performed in real
mode. Actually, the tests in this illustration will only recognize one of the
interrupt 16h functions and one of the interrupt 21h functions, but it will at
least give you an idea of how to proceed.

At goahd2: in EN32.ASM note the cmp bp,16h and cmp bp,21h. If bp,16h it will
jmp to do16 or if bp,21h it will jmp to do21.

EN32.EXE in 32 bit protected mode recognizes the F5 key to set bp,16h and set
[savah] to zero. It then exits to real mode. ah zero and interrupt 16h is
the 'await key press' interrupt 16h function.

If the F6 key is pressed, it sets bp,21h - then [savah],2 - then [savdl],7 -
and exits to real mode. ah,2 - dl,7 - int 21h is the beep the speaker
interrupt 21h function.

All the F5 key press in protected mode does is to go to real mode and display
the key press character at the top of the screen until Esc is pressed and it
then returns to 32 bit protected mode.

All the F6 key press in protected mode does is to go to real mode and do an
interrupt 21h with ah=2 and dl=7 which produces an annoying BEEP on each key
press until Esc is pressed and it then returns to 32 bit protected mode.

There are as many variations on this theme as an enterprising programmer can
dream up. At least you have a start on this fascinating project.

NOTE:

EN32.EXE does NOT go to real mode on each key press in 32 bit protected mode.
Instead, it sets up its own keyboard translation tables for upper case
characters, lower case characters, and one for converting hexadecimal keyboard
input to decimal zero to 255, (F3 key in MODIFY MODE or SEARCH MODE). The
tables are in the data segment. Ports 60h and 61h provide raw keyboard input
in protected mode.

MAY WRAP AROUND AT 16 MEGABYTES:

The above comment at the beginning of the second line in EN32.EXE is a
reminder that not ALL 80386 and 80486 microcomputers are created equal. Though
an 80286 and 80386SX are limited to 16 megabytes, all 80386DX and 80486DX
microprocessors have the capability of addressing 4 Gigabytes of memory. If
your 80386DX or 80486DX wraps around at 16 megabytes or 32 megabytes the fault
is NOT in the program, but rather the way the mother board manufacturer hard
wired the microprocessor into the mother board. Hopefully, Pentium micro-
computer mother board manufacturers have avoided this problem. Be aware of
this problem.

To test any microcomputer for this problem, just run EN32.EXE on it and press
the c key in EDIT MODE. The c key moves up 16 megabytes at a time. If after
a single or double key press it displays real mode's interrupt vector table or
a duplicate of the page you were on, the microcomputer has this hard wired
problem and most likely cannot be modified.

SWITCHING TO EDMOD.OBJ IN REAL MODE VIA CTRL KEY - DEL KEY TO SWITCH BACK:

EDMOD.OBJ is an `olde` (circa 1977 though frequently updated) program that we
(editorial we) wrote that allows the user to edit/modify any/all ram memory in
real mode, plus displays the 80286 disassembled instruction on the lower left
bottom of the video display (you MUST know where the instruction begins to
disassemble it correctly).

You may switch back to PROTECTED MODE near instantly while in EDMOD.OBJ by
pressing the Del (delete) key. Please write down these directions.

You may switch to the DOS> prompt any time in either protected mode or real mode by pressing the Esc key once or twice.

Use the enclosed EDLIN.COM to read the EN32.ASM source file. It is an updated
version that will read and write 33% larger files than the EDLIN.COM files in
DOS 4.0 and DOS 5.0 standard versions.

EXIT PROTECTED MODE - go to EDMOD.OBJ in real mode - return to protected mode:

Again, in protected mode the Ctrl (control) key is used to switch to EDMOD.OBJ
in real mode and the Del (delete) key used to switch back to protected mode
from EDMOD. Here is the sequence in EN32.ASM's source code when the Ctrl key
is pressed.

EN32.ASM source code:

tez29 : tests al,29 (Ctrl key) and if so jumps to yt11.
yt11 : sets the BP register to 3 = go EDMOD pointer & jumps to yt2.
yt2 : begins exit protected mode procedure; jumps to dun.
dun : + compares bp,3 and jumps to sw_bak (switch back to real mode).
sw_bak : does an interrupt 14h (exit protected) which goes to int_entry.
int_entry: begins reset all variables for real mode & falls thru to go_edmod.
go_edmod : tests bp,3 and jumps to tez_edmod.
tez_edmod: tests for EDMOD's presence and far jumps to it at 9000h:8011h.
(Actually, EDMOD.OBJ was loaded and tested during initialization.)
(If EDMOD.OBJ not present, 2 beeps and return DOS>).

Now we are in EDMOD.OBJ in real mode. Press F7 to read EDMOD.DOC. The F1 key
displays an index of the help options.

º F1 key: EDMOD.OBJ - HELP º
º EDIT MODE (green) º
º Esc key DOS> prompt or Windows º
º Shift F1 ret ur pgm if 0000:0300 set º
º F6 key display any directory º
º D key decimal to hex converter º
º H key hex to decimal converter º
º S key global search ASCII/hex º
º F8 key using the KISS disassembler º
º F9 key zeros out entire segment º
º F10 key zeros out displayed page º
º note: will not zero BIOS or EDMOD º
º MODIFY MODE (yellow) º
º ASCII key modifies mem beneath cursor º
º F2 key toggles back to EDIT MODE º
º F3 key input hex beneath cursor º
º keypad directions keys active º
º MODIFY MODE (red) if in BIOS or EDMOD º
º press F7 to display EDMOD.DOC º

Since we came from protected mode, NOT all of EDMOD's "save the newcomer from
fouling up the programs' functions are available." Yes, you can edit/modify
most all of memory including EN32.EXE's DS and CS segments which will prevent
you from returning to it, plus the BIOS areas in segment 0000h and maybe
segment 1000h which will lockup the program. If you do, about the worst that
can happen is that you will have to restart with a cold boot. To the best of
our knowledge it will not harm any variety of computer.

EDMOD is a fun & games program. It is NOT a replacement for debug or a first
class disassembler, though if you know where an 80286 instruction begins, the
keypad + key will probably disassemble it correctly. The Pentium disassembler
function is about 33% complete and should be finished next year.

º : Up 1024 bytes º : Move cursor º
ADD º : Down 1024 bytes º : <- ^ v -> º F1
[Bx+Si]º : Toggle modify mode º : Change Seg 0 - F º Help
AL º : Hex modify º : Disassemble Memoryº

Exit EDMOD.OBJ and return to EN32.EXE in protected mode:

In either EDMOD's edit or modify mode, pressing the Del (delete) key will
return you to protected mode. This commences the following sequence:

EDMOD tests 0000:0300h for zero. If so it beeps (nothing there, so ignore).
If not zero it saves EN32.EXE's code segment and then tests 0000:0382h for 'E'
denoting an .EXE file. If so it then jumps far to EN32.EXE's code segment
plus 20H which is located in the 15 each nops in EN32.ASM's source code just
after begin:.

It then continues setting up and re-entering protected mode in a millisecond
or less.

Pressing the Esc key in EDMOD will return you to the DOS> prompt. Pressing
the Esc key in protected mode will return to real mode and give you the choice
of:

Press N to go to the DOS> prompt or press enter to return to protected mode

GOING TO EDMOD.OBJ FROM THE DOS COMMAND LINE:

The little program, GOEDMOD.COM will load EDMOD.OBJ to 9000h:8000h from the
DOS> command line and then jump far to it. GOEDMOD.COM may be on any drive in
any subdirectory as long as EDMOD.OBJ is in the same one. You may use a mouse
and/or the keyboard.

Previous loading of EDMOD.OBJ has no effect since upon return to the DOS>
prompt, DOS 6.1's COMMAND.COM reloads itself into the 9000h:8000h region. The
portion of DOS 6.1's COMMAND.COM that is loaded to 9000h:8000h is at its
offset 21,804. EDMOD.OBJ is NOT a terminate and stay ready program.

SUPER VGA BOARDS:

Many super VGA add-on boards with 500k or 1 meg of video memory such as the
IBM XGA graphics board, the ATI boards and many others stash their video
memory at location 00E00000h = 14,680,064 decimal. With EN32.EXE running,
just press the b key to move up in 1 megabyte chunks to 00E00000h. Then press
enter to move up a 1024 byte page at a time. If your super VGA graphics board
uses this memory, you will see it there.

CONCLUSION:

EN32.EXE is strictly a demo of how to enter protected mode, exit protected
mode, re-enter protected mode, and go to and from EDMOD in real mode.

Most protected mode programmers will admit that using the LIM (Lotus-Intel-
Microsoft) 4.0 extended memory 64k page swapping scheme to use a single
segment of extended memory at a time is downtown slowsville compared to
protected mode, yet it has worked for years and is used in countless
successful programs.

As an obvious matter of fact, getting into and out of protected mode is not
exactly simplicity itself.....yet when one becomes accustomed to the new rules
of the protected mode game, it is not all that difficult.

Special thanks go to 'i386/i486 Advanced Programming' author, Shirley Her with
NexGen Microsystems in Silicon Valley (San Jose), California for all her aid,
guidance and superior programming skills that made EN32.EXE possible. Those
who were of assistance to Shirley Her while writing the book include:

Sen-Cuo Ro - coauthor 'i386/i486 Advanced Programming' - NexGen Taiwan
Rajvir Singh - Automata Publishing
Avatar Saini - Intel
Jay Sethuram - Intel
Hal Broome - Sun Microsystems
Steve Thomas - Intergraph
Deepak Verma - VLSI Technology

To dig deeper - highly recommended:

Order 'i386/i486 Advanced Programming' from:

CompuBooks, Cedar Creek, Texas 78612

Phone: (800) 880-6818 Fax: (512) 321-4535

Also recommended:

'PC Interrupts - A Programmer's Reference To Bios, DOS & 3rd Party Calls'
1024 pages. Available from Compubooks.

'Extending DOS' 538 pages. Available from Compubooks.

ADDENDA:

1. If you do not want to load DOS high, delete DOS=HIGH in the CONFIG.SYS
file. DOS 6.1's HIMEM.SYS has an error in it in that it announces that
the A20 address line is set HIGH, but it is NOT. DOS=HIGH sets it HIGH.
To work around this error, EN32.EXE sets the A20 address line high via
interrupt 2fh, function 43h, subfunction 10h, which obtains the address of
the HIMEM.SYS driver entry point. This address is then called far with
AH,5H to set the A20 address line HIGH when EN32.EXE initializes.

2. EN32.EXE automatically clears (zeros out) the unused 64k memory of code
segment 32 in EN32.ASM's clr_rest:. If you do not wish to clear it, (for
instance while disassembling windows), just block call zero_empty with a
semicolon ( ; ).

3. If you move up to fs segment's 00010000+ area you will find the comment,
'Begin 32 bit protected mode.' The following code is EN32.EXE's 32 bit
protected mode code.

- end -

uggs cyber monday