Wednesday, November 5, 2014

Assembly Tutorial 1: Part 4 Using NASM and QEMU

The code for this tutorial can be found at https://github.com/musicman89/Assembly-Tutorial

Part 1: Intro
Part 2: Basic Concepts
Part 3: Writing the Code
Part 4: Using QEMU and NASM

Registering Paths in Windows
First to make using NASM and QEMU easy to use we will register them in Windows.

This is done by simply adding each path to the Path Environment Variable.
This is found by going to System Properties (Right Click on My Computer and Click Properties) then go to Advanced System Settings and Click the Environment Variables Button.

The the path field is a list of paths separated by semi-colons.

We simply need to add the paths that the QEMU and NASM executable files are in to this field and click OK.  You will need to restart you computer for this change to take effect.

Compiling with NASM
To compile basic assembly code in NASM simply open a command window and navigate to the folder the code is located in and call nasm.exe with the following parameters.
nasm -f bin "<assembly file name>.asm" -o "<output file name>.com"

The -f parameter specifies the file type, we are using binary output.  We then specify the name of the file we put the assembly code and, finally the -o parameter specifies the output file path including the name.

Running with QEMU
Once your have your code compiled you can run it in QEMU with the following command.
qemu-system-i386 -m 256 -hda "<file name>.com"

This specifies that we are going to emulate the 386 processor with 256 MB of RAM and we are setting the Hard Drive to our binary file.

No comments:

Post a Comment