liveBook · Manning

Bytecode

As explained in Systems Programming with Zig

Bytecode is a compact instruction representation intended to be executed by an interpreter or virtual machine.

Bytecode is binary executable instructions ready to be fed to an interpreter. Each byte or short sequence of bytes can represent an instruction. section 6.0

In CHIP-8, each instruction is two bytes. Splitting those bytes into four-bit nibbles helps decode instructions; some instructions also contain 12-bit addresses. section 6.5.1

Listing 6.15 Nibbling
const nibbles = [4]u4{
    @intCast(bytecode[0] >> 4), #1
    @truncate(bytecode[0]), #2
    @intCast(bytecode[1] >> 4), #3
    @truncate(bytecode[1]), #3
};

See how shifts and truncation extract four nibbles from a two-byte instruction. section 6.5.1

Running a CHIP-8 program

Load an original program into memory, then step the interpreter repeatedly between reading keypad input and drawing the display. section 6.4.4

How Systems Programming with Zig covers it

How deep it goes
Defines bytecode and explains nibble-based instruction decoding, while leaving instruction implementation to independent work.
Examples
Uses original CHIP-8 programs and splits each two-byte instruction into four nibbles.
What you can do after
Build a CHIP-8 interpreter that loads bytecode and steps instructions in a runtime.
How it connects
Connects bytecode to interpreters, virtual machines, instruction decoding, and bitwise operations.

Also explained in

Compare how 2 books explain bytecode →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.