[2004-10-11]

Assembly Language Snippets

 

Introduction

From time to time I enjoy myself by writing small assembly programs. Most of the times I do it simply because it's relaxing and I really enjoy bumming assembly code. There is something to be said about banging the bare metal -- it can be enormous fun. Of course, I still have a long way to go.

MS-DOS font dumper

The source of a small program which simply dumps the currently used DOS font to a file (fontdump.bin). Unless you're running a custom font, that would be the default ROM BIOS font for the screen resolution in use.

A small 32-bit hash

I read a post by Bob Jenkins in comp.compilers where he mention this as being his then current favourite character-by-character hash:

hash = ( hash ^ current_character ) + ( (hash<<26) + (hash>>6) )

I have no idea if this is something of his own design or if it is a classic. Obviously there are many hashes similar to this one, but I don't recognize this particular version. Anyway, I immediately found some kind of beauty in the simplicity and I decided to implement it and take it for a spin. He made no mention of a favourite seed for the hash, but I guess -1L or even zero will do nicely as long as you don't forget that there's very little diffusion in the first few passes.

The code is an exercise not in achieving speed but in keeping the size of the code down. The function assembles to some 26 bytes.

EMM386 detection routine

Small x86 assembly program for detecting the presence of EMM386 or a similar (emulating) memory manager. I wrote this after a discussion on linux, of all things. It happened that someone that I communicate with on the fidonet was having serious stability problems with linux on his Tyan Trinity 100AT/VIA MVP3 based system using 384Mb of ECC-memory. After much going back and forth and testing it surfaced that the problem occured because he was starting linux using loadlin while having EMM386 loaded. Apparently loadlin contains code to check for this, but the check failed for some reason or another.

There's really no practical use for this code, but I got it down to 41 bytes and you can view it here all the same :-)

Win32: Calling unnamed functions by use of ordinals

My code for doing "call by ordinal". This is a must if you are in need of calling undocumented functions of the Win32 API for which Microsoft does not export a function name. In converting to NASM I've adapted my original TASM-source and I have updated this package with the new source and a pre-assembled executable. The original code can still be viewed online.

 

©2000, 2004 Eddy L O Jansson. All rights reserved. All trademarks acknowledged.