From e5ca4671acd56408826c6e0d5a7619eaa6d3f33e Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 13 Apr 2026 23:25:06 +0200 Subject: Add a note on numeric literals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 53b07d1..01c4847 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,24 @@ your editor (and this repository also holds an [.editorconfig](./.editorconfig) to help you on this). If your editor doesn't support some of these options, just replace it. +# Numeric literals + +In 6502 assembly you can express numeric literals in decimal, hexadecimal and +binary formats. One useful rule I have been developing over the course of +programming in 6502 assembly is: + +1. Prefer the hexadecimal format: debuggers, emulators, ROM dumps, and related + tooling will default to this format. +2. Use the decimal format for simple numbers which can be trivially translated + into hexadecimal format, but which are more simple to write this way + (e.g. `lda #0`). +3. Use binary format for bitmap masks, or other arrangements where each bit has + been set/unset following a very strict order (e.g. preparing the value for a + PPU register). As for masks, it might be quite trivial to mentally parse + which bits are set/unset with something like `lda #$81`, but something like + `lda #$AC` might take more time to mentally parse than the more explicit `lda + #%10101100`. + # Allocation conventions I am not going to reinvent the wheel here: just stick to the comments on the -- cgit v1.2.3