You only enforce the range of operands, not all expressions.
How do you find a label that's in a bank? Well, the label has that metadata attached somehow by the assembler. It might have an associated ".bank" or ".segment" or some other property like this depending on the assembler. That's not part of the operand, though, so it's not applicable. (If you need to get an associated bank number to write to a banking register, some assemblers have mechanisms for that too. CA65 lets you add a bank number attribute to a segment and retrieve it with a pseudo-function
, for example.)
The address of a thing in the file probably isn't really something you'd want to use in a 6502 assembler... I'm not sure of an application for that. For any 6502 instruction operand
, you need it's address in memory
, and that is never more than 16-bit. The platform doesn't do
Some assemblers will truncate expressions larger than 16 bits without warning, and probably there are some people who prefer it that way, but personally I love to have range checking and will gladly accept having to manually truncate the rare cases where I need to. It's safer and more explicit. Though, one sticky point here is what to do about signed values... ca65's range checking is unsigned only and it doesn't have a mechanism to turn it off temporarily around code that needs signed stuff. On the other hand, something like allowing -128 to 255 has the converse problem of not catching unsigned values that have underflowed. I'd take either of these compromises over silent truncation in a heartbeat though.
on the other hand should be some practical large type size. 32-bit seems to be common. I wouldn't expect them to be limited to 16-bits unless this was a very old assembler written for an actual 16-bit computer. The extra bits are important when you need to do assemble-time calculations (especially multiplying and dividing). The range check only
belongs on instruction operands.
koitsu wrote: There is no standard for what the maximum size of an expression can be (and I would say most assembler documentations do not disclose this).
Well, NESASM and ASM6 don't, but ca65 explicitly documents it
. I think I've seen it documented in several assembler manuals, but maybe we're talking about a domain where a lot of assemblers don't have very comprehensive documentation to begin with.