【问题标题】:Motorola 68k Addressing errors摩托罗拉 68k 寻址错误
【发布时间】:2015-02-01 11:41:55
【问题描述】:

所以,基本上,我周三有考试,我周五开始学习 68k 汇编,因为我一直忙于准备数学考试,周五通过了(我知道你不在乎,但我这么说是为了让你不认为我是 a******。)无论如何,我正在尝试编写一个子程序,将 [i] 与数字 #12 进行比较。 IF [i]=#12,则内存偏移量($8200+[i])=D3-#1,ELSE内存偏移量($8100+[i])=2*D3。当我尝试组装它(使用 ASIMTOOL)时,它给了我这些错误

ERROR in line 10: Displacement out of range

ERROR in line 12: Displacement out of range

ERROR in line 15: Invalid syntax

ERROR in line 16: Invalid syntax   

我知道这段代码很垃圾,但我没有人帮助我,我正在尝试自己做这件事。如果你能帮忙,那就太棒了,谢谢。代码如下:

            ORG     $8000
START       MOVE.l      #0,D3
            MOVEA.l  #$8200,a0
            MOVEA.l  #$8100,a1
            CMP.w       #12,i
            BEQ.s       VERO
            JMP     FALSO   

VERO:       SUB.w       #1,D3
            MOVE.l      D3,i(a0)
FALSO:      MULU.w  #2,D3
            MOVE.w  D3,i(a1)
            STOP        #2000
i           DC.w        12
x           DC.w        #4
y           DC.w        #3
            END         START    

【问题讨论】:

    标签: assembly motorola 68000


    【解决方案1】:

    您可能需要下载 M68000 程序员参考手册。以下是该文档中寻址模式的摘要(“表 2-4。有效的寻址模式和类别”):

    Addressing Modes             Syntax  
    Register Direct
      Data                        Dn    
      Address                     An    
    
    Register Indirect
      Address                     (An)  
      Address with Postincrement  (An)+
      Address with Predecrement   -(An)
      Address with Displacement   (d16,An)
    
    Address Register Indirect with Index
      8-Bit Displacement          (d8,An,Xn)
      Base Displacement           (bd,An,Xn)
    
    Memory Indirect
      Postindexed                 ([bd,An],Xn,od)
      Preindexed                  ([bd,An,Xn],od)
    
    Program Counter Indirect
      with Displacement          (d16,PC) 
    
    Program Counter Indirect with Index
      8-Bit Displacement         (d8,PC,Xn)
      Base Displacement          (bd,PC,Xn)
    
    Program Counter Memory Indirect
      Postindexed                ([bd,PC],Xn,od)
      Preindexed                 ([bd,PC,Xn],od)
    
    Absolute Data Addressing
      Short   (xxx).W
      Long    (xxx).L
    
    Immediate      #<xxx>
    

    匹配MOVE.l D3,i(a0)的寻址方式是“注册间接,地址有位移”。问题是您似乎试图从变量中加载值并将其用作单个指令中的位移。位移需要是一个即时常数,所以这就是它不起作用的原因。您可以做的是使用ADDAi 的值添加到a0,然后执行move.l d3,(a0)

    您可能应该从您的DC.ws 中删除# 标志。

    【讨论】:

    • 非常感谢,能否请您帮我处理一下 else 部分?代码正在运行,但在执行“VERO”子程序后,它会跳转到“FALSO”子程序。如何正确编码 IF-ELSE? (就像我在 C 中所做的那样)
    • 作为then 部分的最后一条指令,无条件跳转到位于else 部分最后一条指令之后的标签。
    • ORG $8000 START MOVE.l #0,D3 MOVEA.l #$8200,a0 MOVEA.l #$8100,a1 CMP.w #12,i BEQ.s VERO VERO: SUB. w #1,D3 ADDA.l i,a0 MOVE.l D3,a0 JMP STOP FALSO: MULU.w #2,D3 ADDA.l i,a0 MOVE.w D3,a0 STOP: STOP #2000 i DC.w 12 x DC.w 4 y DC.w 3 END START 第 6 行出现错误:分支指令位移超出范围或无效
    • 第 6 行是 BEQ.s VERO 行。 (如何在 cmets 中编写代码?)
    • 你不应该使用像STOP这样的指令名称作为标签名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    相关资源
    最近更新 更多