Sie sind auf Seite 1von 10

Making your Windows XP

ready for NASM


with NASMIDE configuration

Table of Contents
• Installing the files
• Configuring Windows XP
• Configuring NASMIDE
• Running some test programs
K.Campos June-14-2006
Distribution CD Manual
Installing the files
Locate the NASMv0˙98˙39.exe file found in the distribution CD under the NASM folder.
Run the installer and the following window shows up:

Make sure that the Destination folder is C:“NASM“. If the folder is not yet created, the
installer will automatically create one for you. Also make sure that there is no previous
NASM installation when installing the ones in the distribution CD. If you have a previous
installation, simply transfer the old files to a new location or rename the old installation
with, say, c:“nasm˙old, then you can proceed with the new installation.
Click Install and the program will extract and copy the NASM files to the C:“NASM folder.

The program will exit automatically after installing the files. Follow the next step to let
Windows XP recognize the Netwide Assembler.
Configuring Windows XP
You need to configure Windows XP to allow the NT Environment recognize the
commands (especially nasm.exe)˙of the Netwide Assembler.

In your desktop, right click on your My Computer, select Properties, and click the
Advanced Tab of the System Properties window. OR you may go to the Control Panel;
open the System icon and select the Advanced Tab. Doing either will show you the
following window.

Click the Environment Variables button to configure Windows XP to let it recognize the
Netwide Assembler. The Environment Variables window is shown in the next page. You
will see that it contains two parts: User variables for <username> and System
variables.
At the System variables part, locate the Path variable and click Edit.

Edit the Variable value entry by adding at the end of the entire string with:
;C:“nasm
Make sure that you have a semi-colon before the C:“nasm (if the previous entry has ended
the string with a semi-colon, then you do not need to add one)

Click OK when you are done. Then Click OK again for the Environment Variables
window. Lastly, click OK for the System Properties window.
The next step for preparing Netwide Assembler for Windows XP is to enable the ANSI
driver. By default, Windows disables this. You should manually configure the
CONFIG.NT file found in C:“WINDOWS“SYSTEM32“ to enable the driver. Use a text editor
program, like Notepad, to edit CONFIG.NT file. *

The original contents of the CONFIG.NT file are shown below:

REM Windows MS-DOS Startup File


REM
REM CONFIG.SYS vs CONFIG.NT
REM CONFIG.SYS is not used to initialize the MS-DOS environment.
REM CONFIG.NT is used to initialize the MS-DOS environment unless a
:
— more information of the file goes here or blablabla ˝
:
REM The EMM size is determined by pif file(either the one associated
REM with your application or ˙default.pif). If the size from PIF file
REM is zero, EMM will be disabled and the EMM line will be ignored.
REM
dos=high, umb
device=%SystemRoot%“system32“himem.sys
files=40

We are after only for the few last lines of the file as shown in BOLD.

Before any device= entry, add the following line:


device=%SystemRoot%“system32“ansi.sys which looks like the one below:

REM Windows MS-DOS Startup File


REM
REM CONFIG.SYS vs CONFIG.NT
REM CONFIG.SYS is not used to initialize the MS-DOS environment.
REM CONFIG.NT is used to initialize the MS-DOS environment unless a
:
— more information of the file goes here or blablabla ˝
:
REM The EMM size is determined by pif file(either the one associated
REM with your application or ˙default.pif). If the size from PIF file
REM is zero, EMM will be disabled and the EMM line will be ignored.
REM
dos=high, umb
device=%SystemRoot%“system32“ansi.sys
device=%SystemRoot%“system32“himem.sys
files=40

Save the CONFIG.NT file. This finalizes the configuration of the DJGPP.

* NOTE: If you see that the ansi.sys has already been added. You do not need to
perform this task. You can skip this and proceed to testing if NASM is working smoothly.
Configuring NASMIDE
The distribution package for Netwide Assembler contains a free Integrated Development
Environment (IDE) program which is called as NASMIDE. Configuring properly the
previous step allows you to run NASMIDE in anywhere; this will not bother you to go the
c:“NASM“ folder.

In Windows XP, simply run the command prompt by going to the Accessories in the
Program Files of the Start menu. OR you may click the Run found in the Start menu and
type in there CMD as shown below.

The command prompt is shown below, run the NASMIDE by typing nasmide at the
command prompt. Notice that the folder is not c:“nasm“ but on a different folder.

Pressing Enter after typing nasmide will run NASMIDE as shown below.
You must configure nasmide to locate the nasm.exe file. Close the About window then
Click OPTIONS → ASSEMBLER.

Clicking Assembler… allows you to configure the type of output file you want to produce.
NASM can produce different binary files depending on the target architecture you want.

Simply follow the settings shown above. The Target can be COFF (i386) object file
(if you plan to program in Protected Mode) or COM executable binary file (if you
plan to program in Real-Mode). Check all Warnings. Parameters is left empty. NASM
Location is C:“NASM“NASM.EXE. Click OK when you are done.
Running some test programs
Before you test NASM, there are two things you need to know. Developing in low-level
environments requires you to (1) have a background about the underlying processor
architecture and including the operating system. Or generally speaking, (2) your typical
PC system has two modes: Real-Mode, and the Protected Mode.

Real-Mode Test

To work in Real-Mode, you must assemble your code without the use of a driver program.
Create a blank file using nasmide. Code the following:

BITS 16 ;Set code generation to 16 bit mode


ORG 0x0100 ; COM Code Starting address
SEGMENT .text ;Main code segment
BEGIN: LEA DX, [GREET] ; get offset of GREET to DX
MOV AH, 09H ; inform print string
INT 21H ; execute print string
MOV AX, 4C00H ; inform OS that program will end
INT 21H ; execute program termination

SEGMENT .data ;Initialized data segment


GREET DB ”HELLO WORLD!”, 10, 13, ”$”

Save the file as realtest.asm Assemble the code: click Assemble → Assemble.

The assembler will compile the ASM code. It will inform you the errors that occurred.
No errors occurred means that the code has been assembled successfully as shown
below.
You can run your assembled program by clicking Assemble → Run as shown below.

Or you may run the program by going back to the command prompt and execute
realtest.com
You should be getting the HELLO WORLD! message. If you get it, then you are good to go!

Protected-Mode Test

To work in protected mode, you must have a driver program – usually, we let a C
program call your assembly program. Code the following into a C file and name it as
driver.c You will be compiling this code using DJGPP and at this point it is assumed
that you know how to use DJGPP.

int main()

int ret˙status;
ret˙status = asm˙main();
return ret˙status;
˝
Then code the following into an ASM file and name it as pmtest.asm

BITS 32 ;Set code generation to 32 bit mode


SEGMENT .text ;Main code segment
GLOBAL ˙asm˙main ;Same as extern in C
˙asm˙main: ;entry point when called by driver.c
ENTER 0,0 ;begin routine
PUSHA ;save registers to stack
LEA DX, [GREET] ;load offset of GREET to DX
MOV AH, 09H ;inform of print screen
INT 21H ;execute print screen
POPA ;reload registers from stack
MOV EAX, 0 ;return value to C program
LEAVE ;end routine
RET ;routine terminates
SEGMENT .data ;Initialised data segment
GREET db ”HELLO WORLD!”, 10, 13, “$”

Save both files into the same folder (can be any folder that you want).

First, assemble the pmtest.asm file using COFF (i386) object file in the Target
settings found in the Options → Assembler... The assembler will produce a pmtest.o
object file which your driver.c code needs.

Second, compile the driver.c code by typing the following at the command prompt
where you are working with the pmtest files.

gcc –o pmtest pmtest.o driver.c


After compiling, DJGPP will produce pmtest.exe. Simply run pmtest.exe and you will
receive the message: HELLO WORLD!

If you do get the message, you’re good to go!