Vasm for Motorola 68000无法将两标签间距赋值给符号的问题
Vasm计算Amiga Copper-List大小失败的问题排查与解决
问题场景
编写Amiga Copper-List代码时,尝试通过CLend - CLstart自动计算列表大小,却触发汇编错误,相关代码与编译命令如下:
Copper-List定义
CLstart: dc.w COLOR00,$0000 dc.w $780f, $fffe dc.w COLOR00,$0f00 dc.w $d70f,$fffe dc.w COLOR00,$0fb0 dc.w $ffff,$fffe CLend:
大小计算与出错代码
最初将大小计算写在标签之前,导致汇编报错:
;Sonstige Label Execbase = 4 Chip = 2 ; Ramtype: Chip-RAM anfordern CLsize = CLend - CLstart ; CLstart和CLend尚未定义,表达式无法解析为常数 ;*** Vorprogramm ;Speicher für Copper-List anfordern Start: move.l Execbase,a6 moveq #CLsize, d0 ;Parameter für AllocMem setzen
编译命令:
vasmm68k_mot -m68000 -Fhunk -linedebug -o e:\Amiga\Assembler\Testing\mywork\build\copperdemo.o e:\Amiga\Assembler\Testing\mywork\copperdemo.s
错误信息
error 10 in line 40 of "e:\Amiga\Assembler\Testing\mywork\copperdemo.s": number or identifier expected > moveq #CLsize, d0 ;Parameter für AllocMem setzen error 9 in line 40 of "e:\Amiga\Assembler\Testing\mywork\copperdemo.s": instruction not supported on selected architecture > moveq #CLsize, d0 ;Parameter für AllocMem setzen
问题原因
- 符号解析顺序问题:汇编器按代码顺序线性处理,定义
CLsize = CLend - CLstart时,CLstart和CLend还未被定义,此时CLsize不是固定常数,而是未解析的符号表达式。 - moveq指令限制:68000架构的
moveq要求立即数必须是编译期确定的8位常数(范围-128~127),无法接受未解析或浮动的符号。即便示例中Copper-List大小为12字节(符合范围),但CLsize未被解析为常数,汇编器仍无法识别。
解决办法
1. 调整CLsize的定义位置
将CLsize的定义移到CLend标签之后,确保汇编器已处理过CLstart和CLend,能计算出固定值:
CLstart: dc.w COLOR00,$0000 dc.w $780f, $fffe dc.w COLOR00,$0f00 dc.w $d70f,$fffe dc.w COLOR00,$0fb0 dc.w $ffff,$fffe CLend: CLsize = CLend - CLstart ; 此时可正常计算出列表大小
2. 匹配指令的数值范围要求
如果Copper-List大小超过8位范围(>127或<-128),不能使用moveq,需改用move.l或move.w(AllocMem参数为32位,需确保是长字):
; 超过8位范围时用move.l直接赋值32位常数 move.l #CLsize, d0 ; 或者先赋值16位再清零高16位 move.w #CLsize, d0 clr.w d0+2
3. 语法验证
Vasm的Motorola语法中,=和equ均可定义符号,但必须确保符号在使用前已被解析为固定常数。
内容的提问来源于stack exchange,提问作者Christoph Linden
相关产品推荐
相关产品推荐

