Pattern 26Bytecode Assembler

Purpose

This pattern translates a text-based human-readable assembly language program into binary bytecode instructions.

The assembly language instruction set accepted by this pattern is reprogrammable (it isn’t fixed) and handles both stack-based and register-based instructions.

Discussion

Bytecode interpreters feed off low-level byte arrays full of bytecodes (operation codes that fit into a byte) and integer operands. Generating raw bytecodes from a bytecode compiler is an extra burden on an already complex compiler. It’s easier to generate text-based assembly code and then have an assembler convert that to machine code. In other words, rather than generating bytes 14, 0, 0, 0, 0, and 21, it’s easier to generate ...

Get Language Implementation Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.