dasm-assembler / dasm-assembler/dasm
Range error in constant
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 257
- Forks
- 55
- PR merge metrics
- No merged PRs in 30d
Description
dasm special-cases negative immediates in, for example...
VAL = -1
lda #VAL. ; assembles OK
Although numbers are stored internally as 32 bits, and by rights this would be equivalent to...
lda #$FFFFFFFF
... it assembles OK with dasm using the low bye ($FF) of the internal 32-byte number.
All good so far. It's detecting that the two's complement negative can be expressed as a single byte.
However, long ago when I was "fixing" things, and as a result we were required to write ...
VAL = -1
lda #VAL&$FF. ; nobody liked this
... well the "fix" was reverted/fixed, and we could once again write just ``lda #-1"
The rationale being that dasm would range-check (I am guessing) to detect if the operand was in the correct (signed or unsigned) range. And now to my point...
The valid signed range is of course 8 bits (2's complement). That is from $80 (-128 signed) to $FF (unsigned).
We should be able to use any value in that range without error. But not outside it.
It seems, however, that dasm is restricting the range to -$FF to +$FF, which is incorrect.
The correct range, as noted, is -$80 to +$FF.
As an example, the following assembles - and it should not...
lda #-130. ; whoops! Range should be -128 to 255 inclusive.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the lda #-130. example and locate the immediate-operand range-checking path in the assembler. Verify the accepted boundary values, ensuring -128 through 255 assemble while values outside that range are rejected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100