Wednesday, November 5, 2014

Assembly Tutorial 1: Part 1 Intro to x86 Assembly

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

Intro 
This is the first in a long series of tutorials on assembly programming.  The first many will be strictly in real mode.  We will eventually get into protected mode toward the end of this series.  At that point there will be another series on operating system development using mixed C and Assembly.

Disclaimer
I do no make any claims that this is the best or most efficient way to write any of the code you see.  In many cases I deliberately chose to demonstrate in a less efficient manner because I feel it is easier to explain.

I also will not give any guarantee with the code as it is for educational purposes only.
tools needed

Feel free to copy any of the code from these tutorials for use in your own programs.  I only ask that if you do directly copy large portions of my code that you remark in your code that you did so.

Tools Required
To complete the examples in these tutorials you will need the following tools.  I am going to leave the setup of the tools out of this tutorial as that can change depending on your environment, if assistance is needed though I would be happy to help.

The first tool you will need is a text editor.  You don't need anything fancy, notepad will do.  If you prefer though there are options like Notepad++ and Sublime Text that will offer some form of syntax highlighting.

Next you will need the Netwide Assembler (NASM), which can be found at nasm.us.  This is what we will be using to compile our assembly code into binary machine code.

Finally you will need an emulator.  While this code should run just fine on a computer, it is much faster and safer to test on an emulator.  At this low of a level you can damage your computer among other things, so it is best to play it safe.  I choose to use QEMU which can be found at http://qemu.weilnetz.de/w64/, and all future tutorials will be using it.

Feel free to use another emulator such as Bochs if you want.

Try to avoid virtual machines as they generally do not emulate the processor, but pass off the instructions to your machine's processor. This can cause irregularities when developing assembly code.

No comments:

Post a Comment