The 65xx series and a few other assembler languages differentiate between an immediate constant and a memory address by the presence/absence of the # character:
Since the # is not required on constants in other common computer languages or general writing, it is very easy to forget. The value at the unintended address might work most of the time, making the bug rare to appear. You may think you never forget this, but there's no way to be know since the assembler can't warn you.
My proposal is to prevent this error by adding a warning to assemblers for the second case above. To avoid the warning, the value must have some sort of "this is an address" prefix on it, or be defined symbolically in advance. For the moment I'll use the @ symbol, but any syntax could be used:
The main aspects of implementation would be
* Assembler keeps track of the type of a value, either an address if prefixed with @, or a pure value if not
* Assembler warns on use of pure value not prefixed with a #
* Labels are addresses
* In an arithmetic expression, if any value is an address, the result of the expression is an address
I think the need to use @ would be minimal, only for the absolute addresses of hardware registers, which would be in a common include file anyway. Non-absolute addresses (i.e. variables and constants) would virtually all be labels, which the assembler would already treat as an address. If there's any complaining about this issue, it should be that the annoying # is required everywhere, when the most common case is a numeric constant, not an absolute address. Enabling this warning would involve the addition of a small number of @ symbols (unless you don't use symbolic constants).
Code:
lda #10 ; A = the value 10
lda 10 ; A = byte at address 10
lda 10 ; A = byte at address 10
Since the # is not required on constants in other common computer languages or general writing, it is very easy to forget. The value at the unintended address might work most of the time, making the bug rare to appear. You may think you never forget this, but there's no way to be know since the assembler can't warn you.
My proposal is to prevent this error by adding a warning to assemblers for the second case above. To avoid the warning, the value must have some sort of "this is an address" prefix on it, or be defined symbolically in advance. For the moment I'll use the @ symbol, but any syntax could be used:
Code:
lda 10 ; warning
lda @10 ; OK
addr = @10
lda addr ; OK
lda #addr ; OK, sets A to the value 10
not_addr = 10
lda not_addr ; warning
lda @not_addr ; OK
table: .byte 1,2,3,4
lda table ; OK
lda @10 ; OK
addr = @10
lda addr ; OK
lda #addr ; OK, sets A to the value 10
not_addr = 10
lda not_addr ; warning
lda @not_addr ; OK
table: .byte 1,2,3,4
lda table ; OK
The main aspects of implementation would be
* Assembler keeps track of the type of a value, either an address if prefixed with @, or a pure value if not
* Assembler warns on use of pure value not prefixed with a #
* Labels are addresses
* In an arithmetic expression, if any value is an address, the result of the expression is an address
I think the need to use @ would be minimal, only for the absolute addresses of hardware registers, which would be in a common include file anyway. Non-absolute addresses (i.e. variables and constants) would virtually all be labels, which the assembler would already treat as an address. If there's any complaining about this issue, it should be that the annoying # is required everywhere, when the most common case is a numeric constant, not an absolute address. Enabling this warning would involve the addition of a small number of @ symbols (unless you don't use symbolic constants).