From d5edf1d593c543433fcb1ff31a08709f76f9a3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Henrik=20Sk=C3=A5rstedt?= Date: Thu, 1 Oct 2015 23:16:36 -0700 Subject: [PATCH] Label Pools and Conditional Assembly Awesome stuff added. --- README.md | 107 ++++++--- asm6502.cpp | 673 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 635 insertions(+), 145 deletions(-) diff --git a/README.md b/README.md index 1d8898a..1c0df6e 100644 --- a/README.md +++ b/README.md @@ -90,21 +90,22 @@ Next_Function: ; next global label, the local label above is now erased. Directives are assembler commands that control the code generation but that does not generate code by itself. Some assemblers prefix directives with a period (.org instead of org) so a leading period is accepted but not required for directives. -* **ORG** (same as **PC**): Set the current compiling address. -* **LOAD** Set the load address for binary formats that support it. -* **ALIGN** Align the address to a multiple by filling with 0s -* **MACRO** Declare a macro -* **EVAL** Log an expression during assembly. -* **BYTES** Insert comma separated bytes at this address (same as **BYTE**) -* **WORDS** Insert comma separated 16 bit values at this address (same as **WORD**) -* **TEXT** Insert text at this address -* **INCLUDE** Include another source file and assemble at this address -* **INCBIN** Include a binary file at this address -* **CONST** Assign a value to a label and make it constant (error if reassigned with other value) -* **LABEL** Decorative directive to assign an expression to a label -* **INCSYM** Include a symbol file with an optional set of wanted symbols. +* [**ORG**](#org) (same as **PC**): Set the current compiling address. +* [**LOAD**](#load) Set the load address for binary formats that support it. +* [**ALIGN**](#align) Align the address to a multiple by filling with 0s +* [**MACRO**](#macro) Declare a macro +* [**EVAL**](#eval) Log an expression during assembly. +* [**BYTES**](#bytes) Insert comma separated bytes at this address (same as **BYTE**) +* [**WORDS**](#words) Insert comma separated 16 bit values at this address (same as **WORD**) +* [**TEXT**](#text) Insert text at this address +* [**INCLUDE**](#include) Include another source file and assemble at this address +* [**INCBIN**](#incbin) Include a binary file at this address +* [**CONST**](#const) Assign a value to a label and make it constant (error if reassigned with other value) +* [**LABEL**](#label) Decorative directive to assign an expression to a label +* [**INCSYM**](#incsym) Include a symbol file with an optional set of wanted symbols. +* [**POOL**](#pool) Add a label pool for temporary address labels -**ORG** +**ORG** ``` org $2000 @@ -113,7 +114,7 @@ org $2000 Sets the current assembler address to this address -**LOAD** +**LOAD** ``` load $2000 @@ -121,7 +122,7 @@ load $2000 For c64 .prg files this prefixes the binary file with this address. -**ALIGN** +**ALIGN** ``` align $100 @@ -129,11 +130,11 @@ align $100 Add bytes of 0 up to the next address divisible by the alignment -**MACRO** +**MACRO** See the 'Macro' section below -**EVAL** +**EVAL** Example: ``` @@ -146,7 +147,7 @@ Eval (15): Current PC : "*" = $2010 When eval is encountered on a line print out "EVAL (\) \: \ = \" to stdout. This can be useful to see the size of things or debugging expressions. -**BYTES** +**BYTES** Adds the comma separated values on the current line to the assembled output, for example @@ -161,11 +162,11 @@ RandomBytes: byte is also recognized -**WORDS** +**WORDS** Adds comma separated 16 bit values similar to how **BYTES** work -**TEXT** +**TEXT** Copies the string in quotes on the same line. The plan is to do a petscii conversion step. Use the modifier 'petscii' or 'petscii_shifted' to convert alphabetic characters to range. @@ -175,7 +176,7 @@ Example: text petscii_shifted "This might work" ``` -**INCLUDE** +**INCLUDE** Include another source file. This should also work with .sym files to import labels from another build. The plan is for Asm6502 to export .sym files as well. @@ -186,7 +187,7 @@ include "wizfx.s" ``` -**INCBIN** +**INCBIN** Include binary data from a file, this inserts the binary data at the current address. @@ -196,7 +197,7 @@ Example: incbin "wizfx.gfx" ``` -**CONST** +**CONST** Prefix a label assignment with 'const' or '.const' to cause an error if the label gets reassigned. @@ -204,7 +205,7 @@ Prefix a label assignment with 'const' or '.const' to cause an error if the labe const zpData = $fe ``` -**LABEL** +**LABEL** Decorative directive to assign an expression to a label, label assignments are followed by '=' and an expression. @@ -214,14 +215,50 @@ label zpDest = $fc zpDest = $fa ``` -**INCSYM** Include a symbol file with an optional set of wanted symbols. +**INCSYM** -Open a symbol file and extract a set of symbols, or all symbols if no set was specified. +Include a symbol file with an optional set of wanted symbols. + +Open a symbol file and extract a set of symbols, or all symbols if no set was specified. Local labels will be discarded if possible. ``` incsym Part1_Init, Part1_Update, Part1_Exit "part1.sym" ``` +**POOL** + +Add a label pool for temporary address labels. This is similar to how stack frame variables are assigned in C. + +A label pool is a mini stack of addresses that can be assigned as temporary labels with a scope ('{' and '}'). This can be handy for large functions trying to minimize use of zero page addresses, the function can declare a range (or set of ranges) of available zero page addresses and labels can be assigned within a scope and be deleted on scope closure. The format of a label pool is: "pool start-end, start-end" and labels can then be allocated from that range by '