To this day I remain in absolute awe of ’80s game pioneers like Braben and Bell, Jez San and Matthew Smith, who wrote complex classics like Elite, Starglider and Jet Set Willy in machine and assembly code. It’s a ludicrous thing to consider, as this snippet for “Hello World” in assembly shows.

Yes, I know, it looks very scary… In Figure 5, lines 1ā€“5 are initializing constants. For example, the first line sets LAST_RAM_WORD to 0x007FFFFC which is a memory location in hexadecimal. Line 8 allows the linker to know where the program starts. In this case, the program starts on line 11. Line 9 lets the assembler know that the memory location of the following line. In Figure 5, line 9 tells the assembler that _start: is at location 0x00000000.

Now, I will explain what is happening in the _start: label, beginning on line 11 in Figure 5. The first line inside of _start:, line 12, moves the value of LAST_RAM_WORD to the stack pointer (sp). That line has essentially initiated sp to contain memory address, 0x007FFFFC.

The following line moves ā€˜\nā€™ or the next line character into register 2, an internal register on the CPU. Line 14 calls PrintChar. This means that the program will begin executing the code following the PrintChar: label starting on line 20. For simplicity, from now on I will refer to _start:, _end:, PrintChar:, and PrintString: as functions or routines even though they are labels.

Leave a Reply

Your email address will not be published. Required fields are marked *