Category: Assembler for Amiga

  • How the heck does a CPU work?

    68K is the SUV of prosessors.

    The Motorola 68K line of CPUs is probably among the most coder-friendly on the market, with its rich feature set and sensible syntax. This makes it an ideal choice for learning assembler coding, but be warned: once you understand the inner workings of the 68K, you might find yourself disliking the design of other CPUs. Switching from 68K to x86 coding is like trading your SUV for a kit car.

    Are CPU’s magic?

    A CPU isn’t magical, though it might seem like you need to master some arcane art to program one. It’s simply a unit that can move data around, store it in internal registers, and perform calculations. Once you understand the basics, it’s actually pretty straightforward.

    The 68000 CPU features eight data registers, eight address registers, a Program Counter, and a Status Register. The 68080 CPU, found in Apollo computers, adds 40 extra registers for calculations and data storage. In the remaining articles of this series, the focus will be on the classic 68K, used in early Amiga, Atari, and Apple computers, the Sega Megadrive, and various other devices like laser printers, synthesizers, and medical equipment.

    d0-d7 : 32 bit data registers
    a0-a7 : 32 bit Address registers
    pc    : 24 bit Program Counter
    sr    : 16 bit Status Register
            Lower 8 bits are the Condition Control Register
            Higher 8 bits are system control bits

    Next up are the CPU’s instructions. These are stored in memory and executed by the CPU one by one sequentially. The PC register always holds the address of the next instruction to run. Changing the value of the PC register will make the CPU jump to that memory location to execute code.

    Address      Instruction
    $f8000       moveq #10,d0
    $f8002       moveq #5,d1     <- pc register = $f8004
    $f8004       add.l d0,d1
    
    These instructions happen to be two bytes each, but a 68K instruction can range from two to ten bytes in length.

    In addition to showing how the CPU knows which instruction to execute next, the example also introduces two common commands: Move, for transferring data, and Add, for performing a mathematical addition. There are several variants of both these instructions, but explaining these details is beyond the scope of this article.

    This is all well and good, but how does it turn into a real program a computer user can run? That’s where integration with the rest of the hardware comes in. The CPU, or Central Processing Unit, sits at the core of the hardware design, executing commands. By sending data to the screen buffer, it displays images on the screen, and by fetching data from I/O (input/output), it processes the user’s keyboard input.

    For more information and a straightforward example, take a look at this article next.

    Your first ever Assembler program for the Amiga

  • Your first ever Assembler program for the Amiga

    If you’re looking to learn Motorola 680×0 Assembler for the Amiga computer and compatible systems like Apollo’s Vampire or Unicorn, you’ve come to the right place. This site offers a variety of resources for anyone interested in low-level coding.

    To follow along, make sure your developer tools are set up and installed on your computer. For more details on how to do that, please see:

    LINK

    LINK

    Now that you’re ready, let’s jump right in. I can guess what you’re thinking—another “Hello World” code example to kick off learning a new programming language.

    In the Amiga world, we do things a bit differently. Here, we start by learning how to read input from the mouse’s left button, of course.

    waitLoop:
              btst   #6,$bfe001
              bne.s  waitLoop
              rts

    Now compi….. assemble the code, and run it. It will loop continuously until you click the left mouse button.

    Let’s break it down and go over what each part means.

    waitLoop:

    This is a label, essentially a bookmark in the code pointing to this location. It’s not an instruction for the CPU, but a marker for the assembler to reference when generating actual machine code.

    Labels must either end with a colon or be placed at the start of a line with no space before them to be recognized by the assembler, and they are case-sensitive.

    btst #6,$bfe001

    The “btst” instruction, short for “Bit Test,” is a real CPU command. Here, it’s checking bit number 6 at the memory address $bfe001. The outcome of this test is saved in the CPU’s Condition Code Register (CCR). Essentially, it’s used to determine if that specific bit is set to zero.

    On the Amiga hardware platform, the system sets this particular bit to zero when the LMB is pressed; otherwise, it’s set to one.

    bne.s waitLoop

    BNE stands for “branch if not equal,” meaning that if the previous test doesn’t result in zero, the program jumps to the label waitLoop. You might have noticed the “.s” after BNE—this is an optimization, where “.s” means short. It’s used to create smaller code when the branch or jump is to a nearby address.

    rts

    RTS stands for “Return to Subroutine.” When our program is called by the operating system, we need the CPU to resume executing the OS’s own instructions; otherwise, the system will crash. In later articles, we’ll use the RTS command extensively when creating our own functions and subroutines.

    There you have it—your first Amiga program, written in the programming language for hardcore bearded or bald guys. And if you happen to be a gal, you’re, of course, welcome to be a little less hairy.