Scene.org Demoscene News Service

GCC for asm Experts (and C/C++ Intermediates) - Part 2

[ Atariscne.org - News ] GCC for asm Experts (and C/C++ Intermediates) - Part 2

What a Compiler Must Get Right (That You Don't)

When you write assembly, you know the context. You know which registers hold what, whether a pointer is aligned, whether the loop count fits in a word. You know because you put it there.

Consider a demo screen where you reserve a6 for the background rasters. You update the pointer in the VBL interrupt and just advance with a minimal (a6)+ in the HBL. All your other code simply does not touch a6, because you wrote all of it. Need to update a screen pointer? Just write the global. No function call, no overhead, no uncertainty.

A compiler has no such luxury. It must be correct for every possible input the language allows. It cannot "just know" that a pointer is word-aligned, or that two buffers never overlap, or that a register is free. It must prove it, or assume the worst. And not all code it calls may even have been compiled by it. Maybe it was built with an older compiler, a different language, or maybe you wrote it in assembly yourself.