Treat PEA operand as imm const16

We were treating PEA's operand as an absolute address and attempting to
extend it to 24 bits.  This wasn't very successful, and was
counter-productive when the argument was actually a constant, which is
common.  Worse, if the operand appeared to reference an internal address
outside bank 0, we would output a 24-bit value, breaking 64tass and cc65.

We now treat PEA as having an immediate operand.  (It was already
classified as an "extended immediate", but the operand-address
computation was still happening.)

This will have little to no effect on projects that use OMF relocation
data, because PEA arguments are explicitly identified as symbols or
constants.

New tests were added to 20032-labels-and-symbols to exercise the code
generation failures.  A few other tests that used PEA were affected.
20152-local-variables was fixed by adding a symbolic reference, the
others remained as-is and the expected output was revised.

(issue #172)
This commit is contained in:
Andy McFadden committed 2025-07-18 13:25:29 -07:00
1 parent 859a22fe60
commit 4846a26c9a
20 files changed
+293 -101

No files matched your search

Binary file not shown.
@@ -1,8 +1,8 @@
### 6502bench SourceGen dis65 v1.0 ###
{
"_ContentVersion":6,
"FileDataLength":729,
"FileDataCrc32":-1745845873,
"FileDataLength":761,
"FileDataCrc32":1509582706,
"ProjectProps":{
"CpuName":"65816",
"IncludeUndocumentedInstr":false,
@@ -146,6 +146,15 @@
"PreLabel":"",
"DisallowInward":false,
"DisallowOutward":false,
"IsRelative":false},
{
"Offset":732,
"Addr":135168,
"Length":-1024,
"PreLabel":"",
"DisallowInward":false,
"DisallowOutward":false,
"IsRelative":false}],
"TypeHints":[{
"Low":0,
@@ -252,6 +261,13 @@
"Value":4538,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"733":{
"Label":"ptest",
"Value":135169,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"}},
"OperandFormats":{
@@ -1514,6 +1530,57 @@
"Label":"after",
"Part":"Low"},
"Extra":null},
"736":{
"Length":3,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null,
"Extra":null},
"739":{
"Length":3,
"Format":"NumericLE",
"SubFormat":"Symbol",
"SymbolRef":{
"Label":"ptest",
"Part":"Low"},
"Extra":null},
"748":{
"Length":3,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null,
"Extra":null},
"751":{
"Length":3,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null,
"Extra":null},
"754":{
"Length":3,
"Format":"NumericLE",
"SubFormat":"Symbol",
"SymbolRef":{
"Label":"biggie",
"Part":"Low"},
"Extra":null},
"757":{
"Length":3,
"Format":"NumericLE",
"SubFormat":"Symbol",
"SymbolRef":{
"Label":"biggie",
"Part":"Bank"},
"Extra":null}},
"LvTables":{
+115 -47
View File
@@ -1,6 +1,6 @@
### 6502bench SourceGen dis65 v1.0 ###
{
"_ContentVersion":4,
"_ContentVersion":6,
"FileDataLength":237,
"FileDataCrc32":1833028653,
"ProjectProps":{
@@ -26,7 +26,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Decimal",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":false,
@@ -43,7 +44,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"project const",
"HasWidth":false,
@@ -60,7 +62,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"project const",
"HasWidth":false,
@@ -77,7 +80,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"project addr",
"HasWidth":false,
@@ -94,7 +98,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"project addr",
"HasWidth":false,
@@ -111,7 +116,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"project addr, should clash",
"HasWidth":false,
@@ -125,11 +131,21 @@
"AddressMap":[{
"Offset":0,
"Addr":4096},
"Addr":4096,
"Length":-1024,
"PreLabel":"",
"DisallowInward":false,
"DisallowOutward":false,
"IsRelative":false},
{
"Offset":126,
"Addr":128}],
"Addr":128,
"Length":-1024,
"PreLabel":"",
"DisallowInward":false,
"DisallowOutward":false,
"IsRelative":false}],
"TypeHints":[{
"Low":0,
"High":0,
@@ -143,12 +159,14 @@
"LongComments":{
"-2147483647":{
"Text":"Edited to have duplicate labels (PROJ_ZERO, DPCODE).",
"IsFancy":false,
"BoxMode":false,
"MaxWidth":80,
"BackgroundColor":0},
"81":{
"Text":"Test name redefinition. This is mostly of interest for assemblers without redefinable variables, but also of interest to the cross-reference window.",
"IsFancy":false,
"BoxMode":false,
"MaxWidth":80,
"BackgroundColor":0}},
@@ -206,31 +224,37 @@
"SubFormat":"Symbol",
"SymbolRef":{
"Label":"CONST_ZERO",
"Part":"Low"}},
"Part":"Low"},
"Extra":null},
"24":{
"Length":2,
"Format":"NumericLE",
"SubFormat":"Decimal",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"26":{
"Length":2,
"Format":"NumericLE",
"SubFormat":"Decimal",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"136":{
"Length":2,
"Format":"NumericLE",
"SubFormat":"Ascii",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"143":{
"Length":2,
"Format":"NumericLE",
"SubFormat":"Ascii",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"155":{
"Length":3,
@@ -238,7 +262,19 @@
"SubFormat":"Symbol",
"SymbolRef":{
"Label":"STRING",
"Part":"Bank"}}},
"Part":"Bank"},
"Extra":null},
"158":{
"Length":3,
"Format":"NumericLE",
"SubFormat":"Symbol",
"SymbolRef":{
"Label":"STRING",
"Part":"Low"},
"Extra":null}},
"LvTables":{
"12":{
@@ -247,7 +283,8 @@
"Length":2,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -264,7 +301,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -281,7 +319,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -298,7 +337,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -317,7 +357,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"clash with project symbol",
"HasWidth":true,
@@ -334,7 +375,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"clash with user label",
"HasWidth":true,
@@ -361,7 +403,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"hidden table",
"HasWidth":true,
@@ -378,7 +421,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"hidden table",
"HasWidth":true,
@@ -397,7 +441,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"not hidden",
"HasWidth":true,
@@ -414,7 +459,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"not hidden",
"HasWidth":true,
@@ -433,7 +479,8 @@
"Length":2,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -450,7 +497,8 @@
"Length":4,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -469,7 +517,8 @@
"Length":2,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"#1",
"HasWidth":true,
@@ -488,7 +537,8 @@
"Length":2,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"#2",
"HasWidth":true,
@@ -507,7 +557,8 @@
"Length":2,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"#3",
"HasWidth":true,
@@ -526,7 +577,8 @@
"Length":2,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -545,7 +597,8 @@
"Length":2,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -564,7 +617,8 @@
"Length":4,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -583,7 +637,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -602,7 +657,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -619,7 +675,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -636,7 +693,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -653,7 +711,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -670,7 +729,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -687,7 +747,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -706,7 +767,8 @@
"Length":4,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -725,7 +787,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"same as org",
"HasWidth":true,
@@ -744,7 +807,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -763,7 +827,8 @@
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -786,7 +851,8 @@
"Length":2,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -803,7 +869,8 @@
"Length":4,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -820,7 +887,8 @@
"Length":4,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"SymbolRef":null,
"Extra":null},
"Comment":"",
"HasWidth":true,
@@ -34,7 +34,7 @@ start clc
lda #>start
lda #`start
pea $feed
pea start & $ffff
pea $2345
pea $0001
pea $3456
pea $0012
@@ -226,6 +226,20 @@ after ldx <after+8,y
ldy <after+9,x
pei (<after+10)
nop
jml _L21000
.here
.logical $021000
_L21000 nop
ptest pea $1001
pea $1001
pea ptest & $ffff
pea $3456
pea $0012
pea $3456
pea $0012
pea biggie & $ffff
pea biggie >> 16
rts
.here
@@ -23,5 +23,6 @@
!hex 656172206f6e20746865206669727374206c696e652e20205468652071756963
!hex 6b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920
!hex 646f67732ea97aa959a934c230a97b56a95a34a93412eaad9f11a59fa5a0b2a1
!hex b1a2b7a3a7a4b5a5a1a6b9a700a5c0b1c1b6c2b4c3d4c4ea60
!hex b1a2b7a3a7a4b5a5a1a6b9a700a5c0b1c1b6c2b4c3d4c4ea5c001002eaf40110
!hex f40110f40110f45634f41200f45634f41200f45634f4120060
}
@@ -32,7 +32,7 @@ start: clc
lda #>start
lda #^start
pea $feed
pea start & $ffff
pea $2345
pea $0001
pea $3456
pea $0012
@@ -223,5 +223,18 @@ after: ldx <after+8,y
ldy <after+9,x
pei (<after+10)
nop
jml @L21000
.org $021000
@L21000: nop
ptest: pea $1001
pea $1001
pea ptest & $ffff
pea $3456
pea $0012
pea $3456
pea $0012
pea biggie & $ffff
pea biggie >> 16
rts
@@ -29,7 +29,7 @@ start clc
lda #>start
lda #^start
pea $feed
pea start
pea $2345
pea $0001
pea $3456
pea $0012
@@ -214,5 +214,18 @@ after ldx <after+8&$ff,y
ldy <after+9&$ff,x
dfb $d4,$c4
nop
jml :L21000
org $021000
:L21000 nop
ptest pea $1001
pea $1001
pea ptest
pea $3456
pea $0012
pea $3456
pea $0012
pea biggie
pea ^biggie
rts
@@ -4,7 +4,7 @@
.xs
nop
L1001 bit L1001
caddr pea caddr-1
caddr pea $1003
per caddr-1
lda L1001+2
lda caddr
@@ -4,7 +4,7 @@
!rs
nop
L1001 bit L1001
caddr pea caddr-1
caddr pea $1003
per caddr-1
lda L1001+2
lda caddr
@@ -4,7 +4,7 @@
.i8
nop
L1001: bit L1001
caddr: pea caddr-1
caddr: pea $1003
per caddr-1
lda L1001+2
lda caddr
@@ -1,7 +1,7 @@
org $1000
nop
L1001 bit L1001
caddr pea caddr-1
caddr pea $1003
per caddr-1
lda L1001+2
lda caddr
@@ -273,7 +273,7 @@ L11FC cmp @wL0086,x
_L122A sbc (L0080),y
sbc (L0080)
sbc ($80,s),y
pea L0086
pea $0086
sbc L0080,x
inc L0080,x
sbc [L0080],y
@@ -273,7 +273,7 @@ L11FC cmp+2 L0086,x
@L122A sbc (L0080),y
sbc (L0080)
sbc ($80,S),y
pea L0086
pea $0086
sbc+1 L0080,x
inc+1 L0080,x
sbc [L0080],y
@@ -273,7 +273,7 @@ L11FC: cmp a:L0086,x
@L122A: sbc (L0080),y
sbc (L0080)
sbc ($80,S),y
pea L0086
pea $0086
sbc z:L0080,x
inc z:L0080,x
sbc [L0080],y
@@ -270,7 +270,7 @@ L11FC cmp: L0086,x
:L122A sbc (L0080),y
dfb $f2,$80
sbc ($80,S),y
pea L0086
pea $0086
sbc L0080,x
inc L0080,x
sbc [L0080],y
@@ -248,8 +248,22 @@ before nop
ldx <after+2&$ff,y
ldy <after+3&$ff,x
dfb $d4,$c4 ;pei (<zip+4&$ff)
after nop
jml checkpea
; Dig into PEA, using both internal and external addresses. We want to do
; this outside bank 0 to see if the bank byte creeps in.
org $021000
checkpea nop
ptest pea ptest ;don't format
pea ptest ;explicitly format as hex
pea ptest ;format as symbol
pea biggie ;don't format
pea ^biggie
pea biggie ;explicitly format as hex
pea ^biggie
pea biggie ;format as symbol (low+bank)
pea ^biggie
rts