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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.