The Design of the Go Assembler: Achieving Portability in Assembly Language
0:47 The Need for Assembly Language: Assembly language remains essential for bootstrapping, performance optimization, and accessing specific hardware features.
3:14 Common Structure: Despite variations, assembly languages across different architectures share a common structure: labels, instructions, operands, and comments.
4:22 Plan 9's Influence: Plan 9's approach, where the compiler generated pseudo-instructions and the linker performed instruction selection, was a key inspiration for Go's assembler design.
7:47 Go 1.3: Moving Towards Go Implementation: Go 1.3 started the transition to a Go-based implementation by introducing the "liblink" library for instruction selection.
9:50 Go 1.5: Eliminating C Code: Go 1.5 completed the transition with a translator that converted the C code of the Go compilers and linker into Go.
10:46 Single Compiler, Multiple Architectures: Go uses a single compiler (compile) for all architectures, leveraging environment variables (GOOS and GOARCH) for configuration.
11:37 Go 1.5 Assembler: A Universal Assembler: The Go 1.5 assembler (go tool asm) is a single Go program that replaces architecture-specific assemblers, achieving portability through a common input language and the "obj" library.
15:26 Dynamic Configuration: The assembler is dynamically configured at runtime based on the GOARCH environment variable, loading architecture-specific tables from the "obj" library.
18:57 Testing Through Comparison: The new assembler was rigorously tested by comparing its output with the output of the previous C-based assemblers.
21:25 Towards Machine-Generated Tables: The future goal is to automatically generate the architecture-specific tables from machine manuals, further simplifying assembler development and porting to new architectures.
22:53 Conclusion: Portable Assembly Language: Go's assembler design demonstrates that assembly language can be portable. This approach enables a unified environment for compiler and linker interaction, making it easier to maintain, test, and extend to support new architectures.