Skip to content

Commit

Permalink
spcasm: add warning for too high address in full-range bit addressing…
Browse files Browse the repository at this point in the history
… instructions
  • Loading branch information
kleinesfilmroellchen committed Nov 21, 2024
1 parent 6ae6e99 commit d14f30a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/assembler/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,16 @@ impl MemoryValue {
},
resolved => Self::NumberRelative(resolved),
},
Self::NumberHighByteWithContainedBitIndex(number, bit_index) => match number.try_resolve() {
Self::NumberHighByteWithContainedBitIndex(ref number, bit_index) => match number.clone().try_resolve() {
AssemblyTimeValue::Literal(reference_memory_address, ..) => {
// TODO: perform byte size check
if reference_memory_address > 0x1FFF {
frontend.report_diagnostic(AssemblyError::ValueTooLarge {
value: reference_memory_address,
size: 13,
location: number.source_span(),
src: source_code.clone(),
});
}
let resolved_data = ((reference_memory_address & 0x1F00) >> 8) as u8 | (bit_index << 5);
Self::Resolved(resolved_data)
},
Expand Down
2 changes: 2 additions & 0 deletions tests/bit-index-overflow.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org 0
and1 C,$fe2b.0
16 changes: 16 additions & 0 deletions tests/cli/bit-index.trycmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```trycmd
$ spcasm tests/bit-index-overflow.s
spcasm::value_too_large

⚠ The value `FE2B` is being used as a 13-bit operand here, but it is larger
│ than this. The extra upper bits are truncated.
╭─[tests/bit-index-overflow.s:2:8]
1 │ org 0
2 │ and1 C,$fe2b.0
· ──┬──
· ╰── 13-bit operand
╰────
help: If this was intentional, explicitly truncate the value.


```

0 comments on commit d14f30a

Please sign in to comment.