CHAPTER 1 - Getting started


Here i predict you have some basic information about what are bytes and some idea what is ASCII code. Maybe i will describe ASCII in later versions of tutorial.

First try to compile empty source file. Just create empty file "empty.asm" and write
fasm empty.asm empty.bin
into command line. You should see that file "empty.bin" is created, and it's length is zero.

Now we will create binary file containing some data. Create text file containing line
db 'a'
and compile it (i hope you already know how). When you look at created file you should see it is 1 byte long and it contains character "a".

Now let's analyze (?) source: db is "directive" (directive is command to compiler, remember this!) which means "define byte". So this directive will put byte into destination file. Value of byte should follow this directive. For example db 0 will insert byte of value 0 to destination file. But if you want to enter some character, you would have to remember it's ASCII value. In this case, you can enter the character enclosed in apostrophes (') and compiler will "get" it's value for you. This is that code works.

directive
command to compiler
Now let's make file with more than one character. It will be:
db '1'
db '2'
db '3'
How this work is clear, i think, it stores three bytes into destination file, which should now contain simple line with 123. By the way you can't write
db '1' db '2' db '3'
because every directive must be on separate line. But if you want to define more bytes, you can use simple db directive followed by more values, sperated by commas (,):
db '1','2','3'
This will produce file with 123 too.

But what if you want to define something longer, for example file containing This is my first long string in FASM? You could write
db 'T','h','i','s'  etc...
but it is not very nice. For this reason, if you want define more consecutive characters using db , you can use this form:
db 'This is my first long string in FASM'
So you have to enclose whole text in quotes. You can use this too:
db 'This is my first long string in ','FASM'
or
db 'Thi','s is my first lo','ng string in',' FASM'
etc.

string, quoted string
Text enclosed in apostrophes is called "string". In general, "string" is array of characters. Term used for string inside source code is called "quoted string".