Search code examples
assemblymotorola68000

Motorola 68k Addressing errors


So, basically, I have an exam on Wednesday, and I started studying the 68k assembly on Friday, because I've been busy studying for the math exam, passed on Friday (I know you don't care, but I say this so you don't think I'm an a******.) Anyway, I'm trying to write a subroutine, that compares the [i] with the numer #12. IF [i]=#12, then memory offset ($8200+[i])=D3-#1, ELSE memory offset($8100+[i])=2*D3. When I try to assemble this (using ASIMTOOL), it gives me these errors

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   

I know this code it's a load of s*it, but I've no one assisting me and I'm trying to do this by myself. If you could help, it would awesome, thank you. Here's the code:

            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    

Solution

  • You might want to download the M68000 Programmer's Reference Manual. Here's a summary of the addressing modes from that document ("Table 2-4. Effective Addressing Modes and Categories"):

    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>
    

    The addressing mode matching MOVE.l D3,i(a0) is "Register Indirect, Address with Displacement". The problem is that you seem to be trying to load the value from a variable and use it as a displacement in a single instruction. The displacement needs to be an immediate constant, so that's why it's not working. What you could do instead is use ADDA to add the value of i to a0 and then do move.l d3,(a0).

    And you should probably remove the # signs from your DC.ws.