About OFRAK Tetris
OFRAK Tetris is like the Tetris you know and love, except the blocks are assembly instructions.
Players can change registers and instruction order as blocks fall, then lock the block into the .text
section. When the program counter (PC
register) points to instructions, it executes them. Blocks pause falling until there are no more instructions to execute. This means that players can queue up instructions in the .text
segment, but only when they are at the top of the instruction region will they be executed. And only when they are done executing do more instructions continue to fall.
The player’s score is stored in memory at the address pointed to by the R12 register. Every time an instruction is executed, the score increases by a fixed amount multiplied by a difficulty multiplier. In other words, there are several strategies to earn points. For example: execute as many instructions as possible without crashing, change the four bytes that R12 points to in the data segment to be a high number, or point R12 to a region of memory with a higher four-byte signed integer value. Doing any of these at a higher difficulty level increases the score further.
Execution happens in a WebAssembly port of the Unicorn Engine. In other words, instructions are being executed on a full CPU emulator running entirely in the browser! Since Unicorn is a full CPU emulator, executing the instructions works exactly the way it would on a real CPU.
The execution environment has a 4096-byte text segment mapped to address 0x10000
, and a 256-byte data segment mapped to address 0x0
. Both segments have read, write, and execute permission (hint for fun, advanced game strategies…). All of the registers except for PC
start out with value zero by default.
Executing invalid instructions, accessing invalid memory, or running out of time all end the game.
When it’s game over, players can download their game as an ELF executable to relive the experience in GDB on their favorite ARM machine. Or, players can drop their generated ELF into OFRAK and explore its structure.
In addition to working on desktop and mobile browsers, OFRAK Tetris also works with USB game pads.