Synook

Writing "hello world" in x86 machine code for Linux with Elfhex

In a previous post, I described my Elfhex project, a simple machine code "assembler" which takes source files containing machine code, represented using hex bytes, and produces executable ELF binaries. While it may seem that it would be quite tedious to produce a working program using this tool, simple executables are not too hard to achieve. In this post, we will use Elfhex to write and "assemble" a simple "hello world" program in x86 machine code, targeting the Linux operating system.

Read more…

Elfhex

View on Github

While the project was actually undertaken several months ago, I have not written about my Elfhex machine code "assembler" on this blog yet. Elfhex is a small language and "assembler", which accepts source files containing machine code (or really, any sequence of bytes, represented by their hex values), and prepends the ELF header (hence the name) in such a way to make the resulting binary executable on an OS that uses the ELF format (e.g. Linux). In order to make this a bit less tedious, the language also contains a number of utilities, such as labels and references, fragments (macros), that make the program construction process easier. Nevertheless, it does not support mnemonics or other typical "assembly language" constructs, and in that manner could be said to be architecture-agnostic as well.

Why did I make Elfhex? Well, I thought it would be interesting to use.

Read more…

The three types of Wikipedia [citation needed]

Burning plastic may produce toxic fumes.[citation needed]

"I have no doubts as to the veracity of this statement, however it would be nice if there was a cititation so people could click on it and learn more about the topic."

The population of Australia is 23 million.[citation needed]

"This seems plausible, but I really have no idea how true this sentence is, so if someone could provide a source for it that would be great."

The Earth is flat.[citation needed]

"The only reason why I didn't delete this outrageous and patently false assertion outright is because I was too afraid of the edit war that would follow."

Vim with Colemak

:set langmap=nj,ek,il,ln,je,ki,NJ,LN

Much better! In this case insert has been mapped to k, since i has been mapped to one of the movement keys.

A simple demonstration of virtual memory

In discussion, it appears many people are unclear on how memory (RAM) is managed in modern OSs, and in particular the concept of virtual memory and its implications for a process. Also, how virtual memory is not the same as paging/swapping (or RAM, or 'storage', or the memory used by virtual machines, etc.).

Many modern computer architectures (e.g., x86-64) possess a Memory Management Unit (MMU) that translates memory addresses as used by processes running on the computer into physical addresses. The memory seen by processes, therefore, is only virtual memory. This allows an OS to present a contiguous and isolated virtual memory space to each process, irrespective of what else is running on the machine—each process in effect thinks it has all the memory to itself. This is simply demonstrated by the program below, which when compiled (on, e.g., Linux x86-64) will show the same memory address holding two different values 'simultaneously'!

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
  int a, i;
  if (fork()) sleep(1);
  a = getpid();
  for (i = 0; i < 4; i++) {
    printf("pid=%i: &a=%p, a=%i\n", getpid(), &a, a);
    sleep(2);
  }
  return 0;
}

Read more…

Nuclear throne

A game I consistently play from time to time is Nuclear Throne, a fairly addictive twin-stick shooter where you try to reach the eponymous Nuclear Throne. Which you won't, since the game is fairly hard too. It's also one of the most highly rated games on Steam with a 96% approval rating (while not being super-niche)—which means it must be good, right?

The basic premise of the game is that you move through procedurally generated levels while fighting enemies from a top-down perspective with various randomly-obtained weapons. As you reach higher levels, the enemies get harder but you are also able to obtain better weapons (still randomly, from chests), leading to an interesting power balance. Eventually (if you get that far) you are facing off against green blobs firing virtually insta-kill plasma balls while running away against other green blobs with insta-kill bite attacks. But you have a nuclear missile-launching bazooka. If you are lucky. Otherwise you have a really slow-firing crossbow. And then you die... probably.

The game by itself only has local co-op, but there is a fairly good online multiplayer mod for the game that enables two people to play together over the internet. It even works with the the Steam friends list for invites, which is pretty good.

Also of note from the developers of the game is Super Crate Box, which is free and also very addictive.

Vultr

Some obscure (or not) letters and diacritics I have come across

  • The diaeresis mark: “ä”. In English, unambiguously indicates a vowel is pronounced separately from the one before it: Noël (no-el, not nol), coöperate (co-operate, not coop-erate), mediëval (medi-eval, not me-die-val), etc. Quite rare except on loanwords. Not like the German umlaut at all.

  • The macron: “ā”. Represents a lengthened vowel sound in transcriptions of some other languages, for example Japanese in Hepburn romanisation: Tokyo is actually Tōkyō, or とうきょう “Toukyou”.

  • The cedilla: “ç”. In French (among others), represents a “c” pronounced like an “s”: “façade”.

  • The eszett: “ß”. Represents a double s-like sound, i.e. “ss” (or “sz”). Originally because there was another letter in the alphabet for a “long s”, “ſ”. “ß” is thus a ligature of “ſs” (originally “ſʒ” (“sz”, hence eszett) but apparently our fonts messed it up back in the day). It is not pronounced like the letter “b”. And related to that…

  • The long s: “ſ”. A former letter in English that was used in place of “s” for non-terminal letters, such as in this cover page for Paradiſe Loſt. The title is not pronounced “Paradife Loft”. And related to that…

  • The thorn: “þ”. Another former letter in English that was pronounced like “th”, as in “þe”, “the”. In some fonts this character came to appear like “y”, leading to words like “ye”, pronounced “the”. So the “ye” in a phrase like “ye old times”, is not actually pronounced “ye”…

A small game from long ago

View

A long long time ago in high school, we used the TI-83 Plus as our calculators. These were "graphical" calculators that had small LCD monochrome screens and which could be programmed using the TI-BASIC scripting language. The display itself had various modes, but the default and easiest to access was the 24×7 (I think?) character text console. Being bored at times like I was, I ended up writing various non-school related programs for the calculator, including several games.

The programs themselves did not last long, in part because by default files were stored in RAM and deleted if the calculator was power cycled (the default "on/off" did not clear the RAM, but taking the batteries out would). Eventually we were upgraded to the amazing (or so it seemed) TI-89, which was much more powerful and capable of symbolic equation-solving—thus known as a "CAS" (Computer Algebra System) calculator (and thus, banned in many assessment environments) (but, it still stored programs in RAM by default). This was the end of my TI-83+ programs—though I did write some for the TI-89, which can be found here.

Read more…

What happened to aspektas.com, you ask?

It's gone. It was old (the codebase had barely been updated since 2007), hard to maintain and eventually broke. And that was the end.

All the article content from the site has been imported onto this one, so it is still available, for what it's worth—I really wrote some pretty strange stuff back in the day! The URL structure has not been retained though so it may be hard to find some stuff. Have a browse if you feel like it.

As for what it looked like, before memories of the site are lost to time...

Screenshot of Aspektas blog

Update: as a bonus, here is what the site used to look like in some of its previous iterations, in chronological order.

Read more…