0

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    
Giulio Paoli
  • 85
  • 11

1 Answers1

1

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.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • Thank you very much, could you please help me with the else part? The code is working, but after the "VERO" subroutine is executed, it jumps to the "FALSO" subroutine. How can I correctly code an IF-ELSE? (Like I do in C) – Giulio Paoli Feb 01 '15 at 12:35
  • As the last instruction of the `then` part, put an unconditional jump to a label placed right after the last instruction of the `else` part. – Michael Feb 01 '15 at 13:24
  • 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 It gives me error at line 6: Branch instruction displacement is out of range or invalid – Giulio Paoli Feb 01 '15 at 13:44
  • The line 6 is the BEQ.s VERO line. (how can I write code in comments?) – Giulio Paoli Feb 01 '15 at 13:49
  • You shouldn't be using instruction names like `STOP` as label names. – Michael Feb 01 '15 at 14:22
  • I don't understand the purpose of "i(A0)". It would mean: Address the memory at "A0+i" however I think the actual intention is to address the memory at i, not at A0+i. – Martin Rosenau Feb 01 '15 at 14:48
  • @MartinRosenau: My understanding of `i(a0)` was that the OP hoped that it would work the same as `12(a0)` (or whatever the value at `i` happens to be). – Michael Feb 01 '15 at 14:51
  • As Michael said, It was intended i+a0, as you normally do with #3(a0). Basically, I suck at coding in assembly. – Giulio Paoli Feb 01 '15 at 16:49
  • The comment character is ; – puppydrum64 Jul 01 '22 at 18:18