User Tools

Site Tools


sd-8516_assembly_language

This is an old revision of the document!


SD-8516

Introduction

Welcome to the SD-8516 Assembly Language Reference Manual! Inside here you will find detailed information and discussion about programming your new SD-8516.

A Guide to Registers

There are sixteen general purpose registers available for use> Here they are, with a short comment on name and purpose. Of course, since they're general purpose, there is nothing separating one register from another except convention. You can feel free to use this guide, or use them any way you like.

REG Name Convention Notes
A Accumulator Scratchpad for math operations, function calls, etc. The accumulator – used in much the same way as A or AX on 6502/8086 style systems.
B Assistant to the Accumulator Secondary accumulator This will often hold the results of functins called with A as a variable. Often used as the high byte, or bank pointer, combind with A (see: register AB)
X Column Index Register Intended to help map 2d memory and arrays, loops, etc. Often used for example in cursor or pixel array helper functions
Y Row Index Regisrer Intended to act as a row or record indicator alongside X. Can form the XY paired register with X.
C, I, J, K Iterator Registers C is often used for counting, but I, J, K are also used. Also see: CD, IJ and KT. Some people treat these (especially K, alongside T and TK) as temporary registers
T Temporary Register There is a saying, if you are preserving T you're doing it wrong. Don't PUSH and POP T to protect it– use it locally and then ignore it. T is our favorite temporary register!
M, D Memory pointer and memory pointer Destination. These are often used in pairings like ELM, ELD, etc, to point to memory locations. As such they are generally for immediate use only and could be used on their own as temporary registers. ELM is EL as high-byte
E, F, G Extra registers most often used as high bytes for 24-bit memory access ex. GLD, FLM, etc. but can also be used for general purpose (esp. G – use G for anything! And in that sense, F is the 'Free Register' – use it as you like!)
L The Last True Register If you really need another register, use this one. For emergency use only.
Z Z-index pointer Often used as a third dimensional register for graphics or data processing. Ex. FLZ

Byte Access

Each 16 bit register (such as A) may be accessed as the byte registers H and L. This means AH is the high byte of A, BH is the high byte of B, etc. while AL is the low byte of A, ZL is the low byte of Z, etc.

24-bit Register Pairing

The system uses register pairing, which simulates 24 and 32 bit registers, for certain limited operations. The allowed pairings are:

  • B: BLA, BLY, BLZ and BLT.
  • E: ELA, ELB, ELC, ELD, ELX, ELY, ELZ, ELI, ELJ, ELK, ELT, ELM
  • F: FLA, FLB, FLC, FLD, FLX, FLY, FLZ, FLM,
  • G: GLA, GLB, GLC, GLD, GLI, GLJ, GLK, GLT.

Suggested use is for pointer only since this requires the CPU to manually combine two registers and is therefore much slower than a usual 16 bit register access.

Examples:

  • Source pointer ELM, Destination pointer ELD; if it's in an alternate bank, FLD.
  • S/D pointers ELI, ELJ or ELX, ELY, ELZ, or across banks you could use ELX, FLY, BLZ if you insisted on XYZ.
  • If you needed a second pair you could use FLA, GLB, FLM, GLD, etc.

Warning: B, X and BLX (for example) are not separate! You cannot store something in BLX, then modify B or X independently from destroying BLX. They are built from B and X dynamically by the CPU.

The convention of BLX is that BL is the high-byte. This opposite from 32 bit mode (see below):

32-bit register pairing

The system can simulate 32 bit operations by combining two registers together however be advised this is very slow as it requires the CPU to simulate operations across multiple registers. These otherwise operate like their 24 bit counterparts.

The only allowed pairs are: AB, CD, XY, IJ, TK, LZ, EF, GM.

WARNING: Modifying G or M will destroy GM, etc. as GM is directly made of G and M.

LDGM $12345678 is equivalent to LDG $5678 and LDM $1234. So AB for example uses B as the high-word. This is opposite the BLX convention which uses BL as the high-byte.

This is because during MUL operations overflow moves into the high byte, otherwise it stays in the original register. EX. MUL A, B moves into A but overflow goes into B.

No Borrow Carry

The SD-8516 follows in the grand tradition of no borrow carry. Here's how to understand it:

  1. CMP A, B means we do A-B.
  2. Then we apply the rules; NO BORROW = CARRY SET

This is often called “No borrow carry”. or “no carry borrow”. Here are some examples:

CMP A, B A=1, B=2 evaluate 1-2 = -1 C=0 “NO CARRY on BORROW”
CMP A, B A=2, B=1 evaluate 2-1 = 1 C=1 “NO BORROW sets CARRY”
CMP A, B A=2, B=2 evaluate 2-2 = 0 C=1 “NO BORROW… = CARRY SET”

The common case is CMP X, MAXCOLS. if MAXCOLS is 80, then if X is 0-79 carry will be clear (because a borrow will be needed). This satisfies “no carry, because, borrow”.

LDA #1          ; A = 1
LDB #2          ; B = 2
CMP A, B        ; Compare 1 with 2
                ; Performs: 1 - 2 = -1 (needs borrow)
                ; 1 >= 2? NO
                ; CARRY = 0 (borrow needed)

In the above example, A is less than 2, therefore a carry (i.e. borrow) will be needed. This is “NO-BORROW CARRY”.

CARRY = 0 because A < B.

  1. # The Rule:

``` CMP A, B (performs A - B)

CARRY = 1 if A >= B (no borrow needed) CARRY = 0 if A < B (borrow needed)

sd-8516_assembly_language.1768879215.txt.gz · Last modified: by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki