nurpax / c64jasm

C64 6502 assembler in TypeScript
51 stars 14 forks source link

[Limitation] < and > operators to get low/high byte of a word don't work in data directive #76

Closed shazz closed 3 years ago

shazz commented 3 years ago

Example:

* = $1000
data: !byte 1, 2, 3, 4

* = $1010
data_ptr_msb: !byte <data
data_ptr_lsb: !byte >data

Error:

main.asm:5:21: error: Syntax error: Expected "!", "$", "%", "(", "*", "+", "-", ".", "0", "::", "[", "\"", "{", "~", [1-9], or [a-zA-Z_] but "<" found.

Workaround:

* = $1000
data: !byte 1, 2, 3, 4

* = $1010
data_ptr_msb: !byte data>8
data_ptr_lsb: !byte data

Workaround is fine for me. But maybe a proper operator could be define ?

nurpax commented 3 years ago
* = $1010
data_ptr_msb: !byte data>8
data_ptr_lsb: !byte data

I think you meant:

* = $1010
data_ptr_msb: !byte data>>8
data_ptr_lsb: !byte data

(Just thought I'd mention as the former probably compiles too but will evaluate to true or false.)

I might in fact choose not to support this syntax for generic expressions, as I am worried it will conflict in the parser as there are already < and > operators in the grammar. The < and > for lo/hi bytes is currently only supported in the immediate field denoted with #<foo.

shazz commented 3 years ago

Sorry for the typo. I think the workaround using >> 8 is good enough. Just need to be documented: if < > for immediate values, the shift operator for labels.