Long time ago, even now, I always wanted to learn Assembler, but it’s not as straightforward to learn as Basic, Pascal, C or any other high level language. It’s not English you’re writing, something made to be understood by a human. Coding in Assembler means you talk directly to the CPU in its own language. Assembler gets converted with a semi 1-1 conversion to machine code. Every instruction you type gets converted into a machine opcode.

As an example, here is how you write “Hello, World” in C

#include <stdio.h>
int main() {
   // printf() displays the string inside quotation
   printf("Hello, World!");
   return 0;
}

and now the same, but in x86 ASM (DOS, Exe)

; fasm example of writing Hello, World

format MZ

        push    cs
        pop     ds
        mov     ah,9
        mov     dx,hello
        int     21h

        mov     ax,4C00h
        int     21h

hello db 'Hello world!',24h   

See what I mean? The second snippet is definitely not “intuitive”. Anybody can remember that “printf”, well, prints something. “MOV ah, 9” etc is something else, even if DOS makes it easier than directly using BIOS calls.

Anyway, now that I’m much older and worked a little more on my patience while learning, here is my take at an icon of DOS games, “Dope Wars”.

Dope Wars is an evolution of the original game by John E. Dell called Drug Wars, where you bought and sold drugs to make money. Dope Wars was developed by the Happy Hacker Foundation.

I developed it as a learning tool to get acquainted with ASM x86. I love miniatures, that’s why it’s in ASM, but still have no idea on how to optimize the code, or sometimes why even it works (or not). Yet, here it is.

And the code