我正在尝试编写一个使用.align指令来确保数据不跨越页面边界的asm程序。
但是,虽然数据位于内存中正确的位置,但编译后的代码没有使用正确的地址。
根据文档( https://www.cc65.org/doc/ld65-5.html )
如果请求对齐,链接器将向输出文件添加足够的空间,以便新段从一个地址开始,该地址可以被给定的数字除除而没有剩余部分。所有地址都进行了相应的调整。用于填充未使用的空间,使用零字节,或者,如果内存区域具有“填充”属性,则使用该值。
这种调整似乎并没有发生。
要再现,我有以下配置文件:(请注意DATA256段上的“对齐”)
# Assembly configuration for R38
FEATURES {
STARTADDRESS: default = $0801;
}
SYMBOLS {
__LOADADDR__: type = import;
# Putting "-u __EXEHDR__" on cl65's command line will add a BASIC RUN stub to your program.
# __EXEHDR__: type = import;
__HIMEM__: type = weak, value = $9F00;
}
MEMORY {
ZP: file = "", start = $0022, size = $0080 - $0022, define = yes;
ZP2: file = "", start = $00A9, size = $0100 - $00A9;
LOADADDR: file = %O, start = %S - 2, size = $0002;
MAIN: file = %O, start = %S, size = __HIMEM__ - %S;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp;
EXTZP: load = ZP2, type = zp, optional = yes; # OK if BASIC functions not used
LOADADDR: load = LOADADDR, type = ro;
EXEHDR: load = MAIN, type = ro, optional = yes;
CODE: load = MAIN, type = ro;
LOWCODE: load = MAIN, type = ro, optional = yes;
RODATA: load = MAIN, type = ro;
DATA: load = MAIN, type = rw;
DATA256: load = MAIN, type = rw, align = $100;
DATA4k: load = MAIN, type = rw, align = $1000;
BSS: load = MAIN, type = bss, define = yes;
}
FEATURES {
CONDES: type = constructor,
label = __CONSTRUCTOR_TABLE__,
count = __CONSTRUCTOR_COUNT__,
segment = ONCE;
CONDES: type = destructor,
label = __DESTRUCTOR_TABLE__,
count = __DESTRUCTOR_COUNT__,
segment = RODATA;
CONDES: type = interruptor,
label = __INTERRUPTOR_TABLE__,
count = __INTERRUPTOR_COUNT__,
segment = RODATA,
import = __CALLIRQ__;
}以asm为
.org $0801 ; Assembled code should start at $0801
; (where BASIC programs start)
; The real program starts at $0810 = 2064
; 10 SYS 2064
.byte $0C, $08 ; $080C - pointer to next line of BASIC code
.byte $0A, $00 ; 2-byte line number ($000A = 10)
.byte $9E ; SYS BASIC token
.byte $20 ; [space]
.byte $32, $30, $36, $34 ; $32="2",$30="0",$36="6",$34="4"
.byte $00 ; End of Line
.byte $00, $00 ; This is address $080C containing
; 2-byte pointer to next line of BASIC code
; ($0000 = end of program)
.byte $00, $00 ; Padding so code starts at $0810
cld
stp
lda testdata
rts
.segment "DATA256"
testdata:
.byte $01, $02, $03, $04使用以下命令行生成:
cl65 --verbose -o build.prg --cpu 65c02 -t cx16 -C asm.cfg -Ln labels.txt -m map.txt -T main.asm这是编译好的.prg。您可以看到从$0816读取的'lda测试数据‘,它不是对齐地址。填充到$01,$02,$03显示数据是对齐的。

这在调试器中得到确认。

我做错了什么?或者这是链接器中的一个bug?
发布于 2021-04-09 23:49:30
不要使用.org指令。配置文件设置地址:STARTADDRESS: default = $0801。
另外,该指令告诉汇编程序告诉链接器,“不要重新定位下面的代码”。这就阻止了.segment指令执行我们期望它做的事情。
https://stackoverflow.com/questions/66950892
复制相似问题