Ian Fieggen Ian's Software Site Ian's JPGExtra program
Ian's Software Site - Minimalist software programs that are tiny yet very powerful
Assembly Language Programming
Information about writing powerful programs in assembly language My programming experience dates back to the 1970s, when personal computers were still in their infancy and serious programs were written in Assembly Language in order to squeeze as much power and performance from those tiny computers. I still program this way today, and the results speak for themselves.


What is Assembly Language?
Computer Programming:
Every computer program is a sequence of instructions that the processor chip of the computer understands. Instructions such as: ADD THESE TWO NUMBERS, or PRINT THIS MESSAGE, or STORE THIS VALUE, or QUIT IF THE RESULT IS ZERO.

Programming Languages:
There are many different programming languages, like "Basic" or "C", with varying similarities and differences. Most of these are called "high-level" languages because they take a series of powerful, high-level commands (which are relatively easy for humans to understand) and convert them into a series of low-level processor instructions (which are understood by the computer).

Assembly Language, on the other hand, is called a "low-level" language - it's like writing in the native tongue of the processor chip. In Assembly Language, the programmer is responsible for writing each and every processor instruction.

What Makes Assembly Language Better?
Generally speaking, the more "human-readable" the language, the less efficient is the resulting program because there will always be some inefficiencies in translation. Because there is no translation in Assembly Language, the result is a more efficient finished program that contains fewer "overheads".

Although programming in Assembly Language is harder up front, the rewards are reaped over and over again while the program runs. To me, this is a modern example of the old adage:
"The end justifies the means."


Comparing Programming Languages
A simple example that is commonly used to test different programming languages is a program to write the message: "Hello, World", then exit. Let's see this example written in three different programming languages.
The following three sample programs can be downloaded for your testing. Note that they are written only for IBM PC type computers running Microsoft Windows. They are NOT for Apple Macs, nor have they been tested under Linux, Unix, OS2 or other operating systems.

Most browsers let you right-click on the name of the program, then choose something like: "Save Target As" to save the program onto your computer. You can save straight onto your Desktop so that you don't then need to create a "Shortcut" to run the program.
1. Basic
In this high level language, the source code amounts to two simple instructions:

o
o
o
o

PRINT "Hello, World"
END
o
o
o
o

When this program is compiled using, for example, Turbo Basic, the result is a DOS executable program Hello1.exe that is 29,152 bytes in size. That's because the compiler has added to the finished program a whole library of additional functions that are never even used by the program.
2. Assembly Language (for DOS)
The same function requires many more lines of source code (16 in this example):

o
o
o
o
o
o
o
o
o
o
o
o
o
o
o

SEGMT SEGMENT
ASSUME CS:SEGMT, DS:SEGMT
ORG 100h

Main:
MOV AH,09h
MOV DX,OFFSET Text
INT 21h
MOV AX,4C00h
INT 21h

Text:
DB "Hello, World$"

SEGMT ENDS
END Main
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o

Despite the larger source code, the finished result when compiled is a TINY stand-alone DOS executable program Hello2.com of only 25 bytes!
3. Assembly Language (for 32-bit Windows)
Although this source code is also 16 lines (as above), they're slightly more complicated lines due to the more advanced function calls in Windows:

o
o
o
o
o
o
o
o
o
o
o
o
o
o
o

.386
.MODEL FLAT, STDCALL

INCLUDELIB USER32.LIB
MessageBoxA PROTO :DWORD, :DWORD, :DWORD, :DWORD
INCLUDELIB KERNEL32.LIB
ExitProcess PROTO :DWORD

.CODE
Heading DB "Ian's Message Box", 0
Text DB "Hello, World", 0

Main:
INVOKE MessageBoxA, 0, OFFSET Text, OFFSET Heading, 0
INVOKE ExitProcess, 0
END Main
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o

Hello World program screenshot This compiles to a 1,536 byte Windows executable program Hello3.exe, which displays the "Hello, World" in a simple message box. Although larger than the previous example due to the overhead required by Windows, it's still TINY compared with the Megabytes of typical Windows programs!
For those wondering about the "odd looking" layout on the above code examples, I've tried to make them to look like the traditional sprocket-fed paper on which such programs used to be printed! (Ahh, nostalgia...)

Conclusion
Despite the fact that Assembly Language can produce the most powerful and efficient programs, the majority of today's software (even Windows itself) in written in high-level programming languages.

Software developers have many reasons for this, some quite legitimate, but mostly to do with maximising profits. The simple truth is that it takes more effort to produce a program using Assembly Language than it does with other languages. As a result, Assembly Language is generally only used on those portions of programs where performance is critical (such as the core functions of Windows).

However, if you look around, you'll find that there are still some dedicated programmers out there writing powerful applications in Assembly Language. In my case, I love the challenge of producing the smallest, most efficient programs that will do the job; the performance gains are part of the reward.
See the Software Links page for some others who program in Assembly Language.

Sponsored Links
Sponsor's ADs

Sponsored Links