lea    (MarkeyJester’s).l,a0

        lea    (Motorola).l,a1

        move.l #$00068000,d0

        add.l  #Beginner’s,d0

        move.l #Tutorial,d1

        move.l d0,(a0)+

        move.l d1,(a1)+

 

(MarkeyJester’s Motorola 68000 Beginner’s Tutorial)

 

Introduction

 

Hello.  I’m MarkeyJester, and for several years, I have been programming in 68k assembly.  I have made quite a few Sonic The Hedgehog ROM modifications (a.k.a. hacks), have made a few proto games, and I’m currently in the process of programming a full game from ground up, for the SEGA Mega Drive system.

 

I had trouble learning the language to begin with, and found that a lot of 68k assembly tutorials didn’t really help.  In fact, hardly any of them explained it from a beginner’s point of view, and were extremely vague.  There was only one tutorial I found that really pointed me in the right direction, and it was a guide by SonicRetro member redhotsonic, though his tutorial has a few holes in places which makes it sort of impractical.

 

So, this tutorial here is an attempt at teaching 68k assembly at an extreme beginner’s level, to help steer away from all of those vague guides out there.  If you have any questions to ask, or any advice or feedback to share, then feel free to contact me by email at markeyjester “at” gmail “dot” com.

 

Please note, I have been getting a lot of emails regarding the simulator BSVC, and a lot of the questions related to problems with using macros correctly.  I’m afraid I don’t work with BSVC or EASy68k, and these questions are very hardware specific and actually have nothing to do with 68k itself.  So chances are, I cannot help you in that regard.  So please keep that in mind, and maybe check out manuals/documents that may have came with the hardware/simulator.

 

Good luck.

 

 

 

Contents

 

Section 01 – Getting Started

 

 

 

 

This section shows the basics of 68k assembly programming.

 

 

 

 

Part 01

Computer Memory

 

Part 02

Memory Storage

 

Part 03

Instruction Set Out

 

Part 04

Registers

 

Part 05

The MOVE Instruction

 

Part 06

Addressing & Program Flow

 

Part 07

Homework Results 01

 

 

 

Section 02 – Basic Instructions

 

 

 

 

In this section, we look at some basic instructions that are relatively simple to use.

 

 

 

 

Part 01

The ADD Instruction

 

Part 02

The SUB Instruction

 

Part 03

The SWAP Instruction

 

Part 04

The EXG Instruction

 

Part 05

The CLR Instruction

 

Part 06

Homework Results 02

 

 

 

Section 03 – Binary Instructions

 

 

 

 

This section deals with binary manipulation (bit specific instructions).

 

 

 

 

Part 01

The NOT Instruction

 

Part 02

The AND Instruction

 

Part 03

The OR Instruction

 

Part 04

The EOR Instruction (XOR)

 

Part 05

The BSET, BCLR and BCHG Instructions

 

Part 06

Homework Results 03

 

 

 

Section 04 – Positive and Negative Instructions

 

 

 

 

This section looks at instructions that work with positive and negative.  We also look at other similar instructions too.

 

 

 

 

Part 01

Bit significance

 

Part 02

Signed and Unsigned

 

Part 03

The NEG Instruction

 

Part 04

The EXT Instruction

 

Part 05

Bit shifting

 

Part 06

The LSL, LSR, ASL & ASR Instructions

 

Part 07

The ROL & ROR Instructions

 

Part 08

The MULU & MULS Instructions

 

Part 09

The DIVU & DIVS Instructions

 

Part 10

Homework Results 04

 

 

 

Section 05 – Program Flow Change

 

 

 

 

Here, we take a look at instructions that cause the 68k to jump to different locations to read different instructions.

 

 

 

 

Part 01

The PC (Program Counter)

 

Part 02

The JMP Instruction

 

Part 03

The BRA Instruction

 

Part 04

The SP (Stack Pointer)

 

Part 05

The JSR and RTS Instructions

 

Part 06

The BSR Instruction

 

 

 

Section 06 – Conditional Branches

 

 

 

 

In this section, we look at instructions that change the PC of the 68k, but this time, based on certain conditions.

 

 

 

 

Part 01

The CCR (Conditional Code Register)

 

Part 02

The CMP, TST & BTST Instructions

 

Part 03

The BEQ & BNE Instructions

 

Part 04

The BPL & BMI Instructions

 

Part 05

The BVC & BVS Instructions

 

Part 06

Signed Branches (BGE, BGT, BLE, BLT)

 

Part 07

Unsigned Branches (BCC, BHI, BLS, BCS)

 

Part 08

Homework Results 05

 

 

 

Section 07 – Conditional Instructions & Others

 

 

 

 

This section covers other instructions which function based on certain conditions.  And other miscellaneous instructions...

 

 

 

 

Part 01

The SEQ, SNE, SPL & SMI Instructions

 

Part 02

The SVC, SVS, ST & SF Instructions

 

Part 03

Signed Sets (SGE, SGT, SLE, SLT)

 

Part 04

Unsigned Sets (SCC, SHI, SLS, SCS)

 

 

 

Cycle times

 

Description - NEW

 

 

All instructions will take a certain amount of CPU time to process, they are usually measured in “Cycles”, or “states”.  So, you’ll want to know the speed of each instruction, with different source and destination operands.

 

Here, I have collected and compiled together the cycle times a 68k CPU from a model 1 Mega Drive (this information was recorded from the hardware itself, not an emulator), and has been done with great care and attention.

 

While I’m certain these cycle times are accurate, the shift based instructions (lsl, lsr, asl, asr, rol, ror, roxl and roxr) might not be accurate.  The numbers you’ll see, are exactly how they came out on hardware, I couldn’t find an explanation for this, but have left it here for your viewing pleasure.

 

Please follow this link to an index page of instruction cycle times.

 

 

 

 

Updates

 

2017 September 16

 

 

Once again, it’s been a while, I’ve finally removed those stupid “NEW” tags, since they’re technically not new d=

 

This update isn’t anything to do with the tutorial site, I still haven’t touched it, and probably won’t for a long while.  But what I have done, is compiled a list of cycle times for all instructions I possibly could.  These were collected from hardware with the highest accuracy I could muster given the technology I have available to me.  Look for “Cycle Times” just below the “Contents” menu.

 

I’ve been getting into lofi hip hop lately, so maybe you’ll enjoy it too~

 

 

 

 

Click here for previous "older" updates

 

 

 

Minor Fixes Thanks To...

 

 

 

Tim Hansson, Stuart Patton, Mathieu Stempell, Anthony Vanover, Paul Krigovsky, Andre Tampubolon, Daniel Kang, Robert, Krzysztof Lasocki, Matt Cole, Fran Jednobrkovic, and Gus Lund.

 

If you find an error or mistake somewhere, be sure to email me, and I’ll fix it almost immediately.

 

 

 

 

Personal 68k Project(s)

 

The chaos Layer

 

 

 

 

This was a platform game I was working on for the SEGA Mega Drive, unfortunately, I've gotten rather bored of programming on the Mega Drive these days, so I've taken a break from it all.

 

 

 

 

I did of course, release what I had of this game so far, it's majorly incomplete, but it is what it is.  You can download it here, you will need either a Mega Drive/Genesis emulator program to play this ROM, or a flash cart device and an actual Mega Drive/Genesis.

 

 

Special thanks to http://www.quotegarden.com/ and http://www.brainyquote.com/ for the quotes used in this tutorial, to redhotsonic for inspiration and ideas drawn from his guide, and to Jorge, andlabs and FraGag, for their help, opinions, overviews and corrections.

 

The HTML Counter

 

A visitor counter (Because why not!).