Search code examples
assemblyeasy68k

EASy68K Assembly - first program errors


I'm new to assembly language, so I'm having a little trouble with my first program. I am supposed to basically recreate the following code, except in assembly language obviously. Can anyone help me fix the errors and help me get my program to work properly? I think I am close.

Original non-assembly Code:

Q = 7;
P = 15;  // also test on P = 14 and P = 6
if (P > 12)
  P = 8 * P + 4;   // Requirement: use ASL for multiplied by 8
else
  P = P - Q;
print P;

Here is what I have so far, but I'm getting errors. I'll post the errors at the bottom.

START   ORG     $1000   //Program starts at loc $1000
IF      CMP     #12,P   //Is P > 12?
        BLE     ENDIF   //If P < 12, go to ENDIF
        ASL     #3,P    //Shift left 3 times (Multiply P * 8)
        ADD     #4,P    //P + 4 
ENDIF   SUB     Q,P     //P - Q

* Data section
    ORG $2000    //Data starts at loc 2000
P   DC.W    15  //int P = 15;
Q   DC.W    7   //int Q = 7;
    END START

Line 4: ERROR: Invalid addressing mode Line 7: ERROR: Invalid addressing mode


Solution

  • I recommend that you keep the M68000 Programmer's Reference Manual around to look up the correct way of using instructions.

    ASL has no #<data>,<ea> form. It does have a <ea> form, so you can do ASL P three times. Or you can move P into a register, shift it 3 bits to the left, and put the result back in P.

    Likewise, there's no <ea>,<ea> form of SUB. One solution would be to move the Q into a D-register, and subtract that register from P.