Building Programs
From ASM Book
Assembly language allows you to code programs using mnemonics, but the computer doesn't understand these. What the computer does understand is simply a sequence of high and low voltage fluctuations represented by binary digits. So, we need some kind of program to convert our code into a form the computer can understand and execute. High-level languages make use of compilers for this purpose. Assembly language, however, requires the use of an assembler, which is a sort of compiler itself.
Before we begin building programs using assemblers, we will first demonstrate a few things.
Contents |
A crude "Hello, World"!
Using Debug
This "Hello, World!" example is unlike the programs that you may have written in other languages or assembly itself, because it does not use any direct function calls to print it to the screen nor does it print to the screen. It is very crude because it is only a binary file made of a series of bytes used to represent the characters in the string "Hello, World!". One important point to remember here is that a program is essentially a series of bytes.
We use the command 'type' to display the contents of the resulting file. First, run DEBUG by typing 'DEBUG' at the command-prompt, and at the debug prompt (-), type as in the following (input emboldened):
C:\>DEBUG -A 0B18:0100 db "Hello, World!" 0B18:010D ; press ENTER here -R CX ; CX = 'number' of bytes we want to output to file CX 0000 ; initial value of CX 000D ; D = 13, the length of "Hello, World!", ENTER N hello.bin ; name of the output file W ; save the data "Hello, World!" to file Q ; Quit DEBUG C:\>type hello.bin Hello, World! C:\>
'db', or define byte, is simply a directive to DEBUG to tell it to define some bytes for us.
The entire compilation process, called building, is not a single step though. The process is basically divided into three steps: resource compiling, assembling, and linking.
Resource Compilation (Windows specific)
Resources are objects, such as strings, bitmaps, icons, video, audio and menus, that you will use in your programs. Information concerning the resources that you want your program to use are contained in a text file, called a _resource script_ (.RC). The resource compiler program reads this resource script and combines all the resources referenced in it to form a packed resource file.
Generally, for the Windows platform this resource file has the extension .RES. There are resource compilers, however, that also generate Windows object files (.OBJ) instead of or in addition to resource files (GoRC is such an example). Also, utilities to convert between the two formats exist.
A Windows resource file (.RES) contains a series of packed resource entries, with no headers, footers, padding, etc.. On the other hand, a Windows object file (.OBJ) contains more than just resource bytes: relocation lists, symbol lists, modules, segment data, checksum bytes, etc.. You do not need to worry about these to start build programs--the assemblers do all the dirty work for you. (However, that shouldn't stop you from diggin' in and building the next big assembler.)
Information regarding specific resource compilers can be found a little later.
Assembling
Assembly language source code files are strictly plain-text files having the extension ".ASM".
