This project is read-only.

Introduction

NASM is an open-source x86 assembler which has similar syntax to Intel syntax. It is popular in OS development and popular for Linux development. But it is an all purpose assembler. Please note that NASM has completely different syntax from MASM a macro assembler developed by Microsoft.

Prerequisites

Have basic knowledge of what an Assembly language is, and the concepts used in Assembly programming. This tutorial is not going to explain everything from top to bottom. Because it would be to long to explain everything here. So if you do not understand stuff like registers, or even pointers then find another resource that will help you understand what is troubling you.

The Code

Simply Hello World.png

Things To Note

Since this is NASM, everything is a pointer, thus if I did not dereference age at line 18 or yourage at line 31. Then I would print the reference which is not what I want with the exception of calling scanf because it requires a pointer as an argument. Why dword next to the dereference because NASM needs to specify the size when getting the actual contents at that address. Since age is a 32-bit integer dword is the appropriate size. Since this code was built using a GCC toolchain, MinGW to be exact.  The calling convention for GCC is to push the arguments from right to left.  In addition, since this is Windows all function names must have a leading underscore, or else you might get a linker error when it is time to link the object files into an executable.

This is how the output would look like if I didn’t dereference where I was suppose to dereference:

image

As you can see my age is not 4202496! Why is this happening because the program is printing the address of age and yourage; which happens to be 4 million and something. If you do not believe me just remove the brackets surrounding  age and myage.

Last edited Jun 29, 2012 at 12:58 AM by stack_and_heap, version 13

Comments

No comments yet.