M68K Complete Documentation
Addressing Modes
In the documentation, wherever there is (An), this addressing mode is valid too
Condition Codes
For example the tst, cmp instructions will set the condition codes that represent the result of the comparison of the operands.
The following are all the condition codes available:
Condition codes flags
X is the extend flag, it is set when the result of an operation is too large to fit in the destination register.
N is the negative flag, it is set when the result of an operation is negative.
Z is the zero flag, it is set when the result of an operation is zero.
V is the overflow flag, in arithmetical operations, it is set if it caused the result to overflow.
C is the carry flag, when an operation causes a carry, like an addition or a shift, it is set to the value of the carry.
Shift Directions
Trap tasks
The M68K has one system call: trap #15. The task number goes in D0.B, its arguments in the other registers, and the answer comes back in the
registers the task names. The interface is EASy68K's, so a program written for that
simulator runs here unchanged as far as its I/O goes.
Text and graphics share one image, as they do in EASy68K's output window: what a program prints is drawn on the screen at the text cursor and appended to the terminal transcript, which is what testcases assert on. Click the screen panel to give the program the keyboard; the ring around it says the editor's own shortcuts are off while it has focus.
Text I/O tasks 0 to 20
Printing and reading. Everything printed is appended to the terminal transcript and drawn on the screen at the text cursor, because EASy68K has one output window where text and graphics share the image; the transcript is what testcases assert on. Typed input is echoed to both.
0 Display string with CR, LF
Displays up to D1.W characters of the string at (A1), stopping at a NULL, then a new line. See task 13 for the NULL terminated form.
1 Display string
Displays up to D1.W characters of the string at (A1) without a new line. See task 14 for the NULL terminated form.
2 Read string
Reads a line of input. With a screen keyboard the line is typed on the screen and ends with Enter; otherwise the editor asks for it, and a testcase answers it from its scripted input.
3 Display signed number
Displays D1.L in decimal, in the smallest field it fits. See tasks 15 and 20.
4 Read number
Reads a line and parses it as a decimal number.
5 Read character
Reads one character. With a screen keyboard it is taken as soon as it is typed, without waiting for Enter; check task 7 first to poll instead of waiting.
6 Display character
Displays one character.
9 Terminate
Ends the program.
11 Set or get the text cursor, or clear the screen
The text cursor is where printed text lands, in character cells counted from the top left. Clearing with $FF00 clears text and graphics together, since they share one image, and homes the cursor. Positions outside the screen are clamped to it.
13 Display NULL terminated string with CR, LF
Displays the NULL terminated string at (A1), then a new line.
14 Display NULL terminated string
Displays the NULL terminated string at (A1) without a new line.
15 Display unsigned number in a base
Displays D1.L as an unsigned number in the base in D2.B.
17 Display string and number
Task 14 then task 3: the NULL terminated string, then the signed number.
18 Display string and read number
Task 14 then task 4: the NULL terminated string as a prompt, then a number.
20 Display signed number in a field
Task 3 right justified in a field D2.B columns wide. A number too long for the field is displayed in full.
Graphics tasks 33 to 96
Drawing on the screen. The origin is the top left, coordinates are signed pixels, so a shape may start off the left or the top, and whatever falls outside the screen is clipped. Colors are $00BBGGRR longs, the same encoding EASy68K uses, so its color equates are unchanged. Rectangles and ellipses exclude their right and bottom edges, as they do in EASy68K, which draws them through the Windows GDI.
Colors
A color is a long written $00BBGGRR: blue in bits 23-16, green
in bits 15-8 and red in bits 7-0. These are EASy68K's own equates, and a
program that defines them by name needs no change.
$00000000 black$00000080 maroon$00008000 green$00008080 olive$00800000 navy$00800080 purple$00808000 teal$00808080 gray$000000FF red$0000FF00 lime$0000FFFF yellow$00FF0000 blue$00FF00FF fuchsia$00FFFF00 aqua$00C0C0C0 ltgray$00FFFFFF white33 Set or get the screen size
Resizes the screen and clears it. The minimum is EASy68K’s 640 by 480, which is also the size a program starts with. The windowed and full screen requests are accepted and ignored, since the screen is a panel in the editor.
80 Set pen color
The color lines, outlines, pixels and text are drawn in.
81 Set fill color
The color the insides of rectangles and ellipses and a flood fill are drawn in.
82 Draw pixel
One pixel in the pen color. The pen width does not apply and the drawing point does not move.
83 Get pixel color
Reads the pixel of the image being drawn on, which with double buffering is the off screen one. Outside the screen it answers with the background color.
84 Draw line
A line in the pen color, leaving the drawing point at X2, Y2.
85 Draw line to
A line in the pen color from the drawing point to X, Y, which becomes the new drawing point: a polyline is one task per point.
86 Move to
Moves the drawing point without drawing.
87 Draw rectangle
Filled with the fill color and outlined with the pen. The right and bottom edges are excluded, so a rectangle whose edges meet draws nothing.
88 Draw ellipse
The ellipse inscribed in that rectangle, filled with the fill color and outlined with the pen. A square bounding rectangle draws a circle.
89 Flood fill
Spreads the fill color from X, Y over every neighbouring pixel of the color that was there, four ways.
90 Draw unfilled rectangle
The outline of task 87 in the pen color, with nothing inside.
91 Draw unfilled ellipse
The outline of task 88 in the pen color, with nothing inside.
92 Set drawing mode
Mode 4 draws normally and is the default; mode 2 moves the drawing point without changing any pixel; mode 16 turns double buffering off and mode 17 turns it on, so drawing goes to an off screen image until task 94 shows it.
EASy68K’s bitwise modes (0, 1, 3 and 5 to 15) stop the program with an error naming the mode. Double buffering covers the sprite erasing use of the XOR mode.
93 Set pen width
The width of lines and of the outlines of rectangles and ellipses. A single pixel (task 82) ignores it.
94 Repaint the screen
Shows the off screen image drawn under mode 17. With double buffering off it does nothing but ask for a repaint.
95 Draw text at a pixel position
Draws the string in the pen color with its top left corner at X, Y, over whatever is already there, so a label can sit on a drawing. Control characters are ignored. Text printed with the text tasks lands at the text cursor instead (task 11).
96 Get the drawing point
Where the next line-to would start.
Keyboard and mouse tasks 7 to 61
Polled input from the focused screen. Key codes are EASy68K’s, which every environment in this editor uses. There are no input interrupts: a program asks for the state it wants when it wants it (tasks 60 and 62 are therefore not supported).
Key codes
A letter key is the ASCII code of its capital, so
Ais $41 andZis $5A. Shift, Alt and Ctrl do not change it.A top row digit is its ASCII code, so
0is $30 and9is $39.The function keys are contiguous from F1, so F1 is $70 and F12 is $7B.
The keypad digits with Num Lock on are contiguous from $60.
$08 Backspace$09 Tab$0D Enter$10 Shift$11 Ctrl$12 Alt$14 Caps Lock$1B Esc$20 Space$21 Page Up$22 Page Down$23 End$24 Home$25 Left arrow$26 Up arrow$27 Right arrow$28 Down arrow$2D Insert$2E Delete$BA Semicolon$BB Equals$BC Comma$BD Minus$BE Period$BF Slash$C0 Backquote$DB Open bracket$DC Backslash$DD Close bracket$DE Quote7 Check for keyboard input
Polls without consuming anything: the character it reports is the one task 5 or task 2 reads next. A testcase reports its remaining scripted input the same way.
19 Get key state
Reads whether up to four keys are held right now, one byte of the answer per key code in the same order; with D1.L = 0 it answers with the last key released and the last key pressed instead. A key held down is reported at least once however briefly it was tapped, so a polling loop never misses one.
24 Enable or disable the simulator shortcut keys
Accepted and ignored: the screen panel already hands every key it takes to the program, so there are no simulator shortcuts to give up.
61 Read the mouse
The pointer position is in screen pixels with the same origin drawing uses, whatever the panel’s zoom. The release and press states persist until the next one, so a program that polls slowly still sees every click; the double bit is only ever set on a press.
Program time tasks 8 to 23
Waiting and reading the clock. A delay suspends the program without blocking the editor, so Stop still answers and the screen still repaints while it runs. Testcases run on a virtual clock, where a delay completes at once and the clock starts at zero.
8 Get time
The time the program has been running, in hundredths of a second.
EASy68K counts from midnight; here the clock starts at zero when the run starts, and a testcase’s virtual clock does too. Programs measure elapsed time by subtracting two reads, which is unchanged.
23 Delay
Lets D1.L hundredths of a second of program time pass. The editor stays responsive throughout, and the screen is repainted, so this is how an animation paces itself.
A testcase runs on a virtual clock: the delay completes immediately and advances that clock instead of waiting.
Tasks that are not supported
These stop the program with an error naming the task, rather than doing something the program did not ask for. Everything they configure is either hardware this editor does not have or a decision the editor makes for itself.
Differences from EASy68K
- Everything printed also reaches the terminal transcript, which EASy68K does not have. It is what keeps testcases and the non-graphical view working.
- The screen draws text in one fixed 8 by 16 cell font, so task 21 (font properties) is not supported and the text screen cannot be read back (task 22) or scrolled (task 25).
- Task 92's bitwise drawing modes (0, 1, 3 and 5 to 15) stop the program with an error naming the mode. Double buffering, modes 17 and 94, covers the sprite erasing the XOR mode is usually used for.
- Task 8 counts from the start of the run rather than from midnight, and task 23 completes immediately during a testcase, which runs on a virtual clock.
- Rectangles and ellipses exclude their right and bottom edges. That is what EASy68K does too, because it draws through the Windows GDI, but it surprises people often enough to be worth saying twice.
Directives
Defines constants, following the directive there can be a list of constants separated by commas, the size of each constant depends on the selected size. If no size is selected, the size is determined by the value of the constant. If the constant is a string, it will be stored as a sequence of bytes, if it is a number, it will be stored as a sequence of words
Defines a space in memory of N elements, the size of each element depends on the specified size, the content of the space is undefined
Defines a space in memory of N elements, the size of each element depends on the specified size, the content of the space is initialized to the second operand
Sets the current position in memory for the following instructions
Defines a constant that will be replaced by the value when the program is assembled
Assembler Features
Instructions
add
(b, w, l) {w}Adds the value of the first operand to second operand. If the second operand is an address register, the ADDA instruction is used instead.
adda
(l, w) {w}Adds the value of the first operand to second operand. It does not change the SR. When using word size, the first operand is sign extended to long and the second is read and written as a long.
addi
(b, w, l) {w}Adds the immediate value to the second operand
addq
(b, w, l) {w}Adds the value of the first operand to second operand. The first operand value must be between 1 and 8. If the destination is a address register, it is always treated as a long, and the condition codes are not affected.
and
(b, w, l) {w}Performs a logical AND between the first and second operand, stores the result in the second operand
andi
(b, w, l) {w}Performs a logical AND between the first immediate value and second operand, stores the result in the second operand
asd
(b, w, l) {w}Shifts the bits of the destination operand to the {direction}. Two forms: (1) as<d> Dx/Im, Dn shifts Dn by the count in Dx or immediate (1–8), any size. New bits are filled with the sign bit. Defaults to word. Note: ASL sets the overflow flag if the MSB changes during the shift, while ASR always clears it. (2) as<d> (An) shifts a memory word by 1, no size suffix allowed.
bcc
Branches to the specified address if {condition code}
bchg
Inverts the bit of the second operand at the position of the value of the first operand
bclr
Clears the bit of the second operand at the position of the value of the first operand
bra
Branches to the specified address unconditionally
bset
Sets to 1 the bit of the second operand at the position of the value of the first operand
bsr
Branches to the specified address and stores the return address in the stack
btst
Tests the bit of the second operand at the position of the value of the first operand, it changes the Z (zero) flag, the destination operand is not modified
clr
(b, w, l) {w}Sets to 0 all the bits of the destination operand, how many bits are set to 0 depends on the specified size, defaults to long
cmp
(b, w, l) {w}Compares the second operand with the first operand, it sets the flags accordingly which will be used by the branching instructions. Works by subtracting the first operand from the second operand and setting the flags. If the second operand is an address register, the CMPA instruction is used instead.
cmpa
(l, w) {w}Compares the second operand with the first operand, it sets the flags accordingly which will be used by the branching instructions. When using word size, the first operand is sign extended to long and the second is read and written as a long.
cmpi
(b, w, l) {w}Compares the second operand with the first operand, it sets the flags accordingly which will be used by the branching instructions.
cmpm
(b, w, l) {w}Compares two memory regions, only valid operand is the post increment, it sets the flags accordingly which will be used by the branchin instructions.
dbcc
Decrements the first operand by 1 and branches to the specified address if {condition code} is false and the first operand is not -1. dbra is the same as dbf (will decrement untill it reaches -1). It reads the operand as a word, so it can run at maximum 64k times
dbra
Decrements the first operand by 1 and branches to the specified address if the first operand is not -1. dbcc is the same as dbf (will decrement untill it reaches -1)
divs
Divides (signed) the value of the second operand by the value of the first operand (op2 / op1). The quotient is stored in the first 16 bits of the destination register and the remainder is stored in the last 16 bits of the destination register. The first operand is read as a word, the second as a long
divu
Divides (unsigned) the value of the second operand by the value of the first operand (op2 / op1). The quotient is stored in the first 16 bits of the destination register and the remainder is stored in the last 16 bits of the destination register. The first operand is read as a word, the second as a long
eor
(b, w, l) {w}Performs a logical XOR between the first and second operand, stores the result in the second operand
eori
(b, w, l) {w}Performs a logical XOR between the first immediate value and second operand, stores the result in the second operand
exg
Exchanges the values of the two operands, only works in 32 bits
ext
(l, w) {w}Extends the sign of the operand, depending on the specified size. If the part to extend is negative, it will be filled with 1s, otherwise it will be filled with 0s. Defaults to word
jmp
Jumps to the specified address unconditionally
jsr
Jumps to the specified address, like the "lea" instruction, when resolving the address, it does not read the memory, so "jsr 4(a0)" will jump to the value of "a0 + 4", the address is loaded and stores the return address in the stack
lea
Loads the address of the first operand into the second operand, when using indirect addressing, the value is not read, only the address is loaded. For example "lea 4(a0), a0" will load a0 + 4 in a1
link
Pushes to the stack the long content of the address register, sets the address register to the current stack pointer and then decrements the stack pointer by the specified amount
lsd
(b, w, l) {w}Shifts the bits of the destination operand to the {direction}. Two forms: (1) ls<d> Dx/Im, Dn shifts Dn by the count in Dx or immediate (1–8), any size. New bits are filled with 0s. Defaults to word. (2) ls<d> (An) shifts a memory word by 1, no size suffix allowed.
move
(b, w, l) {w}Moves the value from the first operand to second operand. If the second operand is an address register, the MOVEA instruction is used instead.
movea
(l, w) {w}Moves the value from the first operand to second operand. If the size is word, it is sign extended to long. It does not change the SR. When using word size, the first operand is sign extended to long and the second is written as a long.
movem
(l, w) {w}Move many, useful when you want to save a bunch of registers, for example to save their value when branching to a function it moves a list of registers to memory, or memory to a list of registers. The first operand is the list of registers, the second operand is the memory region. If you define the registers as the first operand, then it will save the registers to memory, if the first operand is the memory, then it will load the registers from memory. You can write the list of registers by separating them with a "/", and the range between registers by using a dash. ex: a3-a5/d0-d2 will select d0, d1, d2, a3, a4, a5. The order of the register will be converted to first data, then address registers, from 0 to 7. When using the pre-decrement operand, the order of the registers will be reversed, going from a7 to a0, and d7 to d0.
moveq
Moves the value from the first operand to second operand. The first operand is read as a byte so only values between -127 and 127.
muls
Multiplies the value of the first operand by the second operand. The result is stored in the second operand. The first operand is read as a word, the second as a long
mulu
Multiplies (unsigned) the value of the first operand by the second operand. The result is stored in the second operand. The first operand is read as a word, the second as a long
neg
(b, w, l) {w}Flips the sign of the operand, depending on the specified size, defaults to word
nop
This instruction is a no-operation, it does not do anything.
not
(b, w, l) {w}Inverts the bits of the operand depending on the specified size
or
(b, w, l) {w}Performs a logical OR between the first and second operand, stores the result in the second operand
ori
(b, w, l) {w}Performs a logical OR between the first immediate value and second operand, stores the result in the second operand
pea
Same as lea, but it pushes the address to the stack
rod
(b, w, l) {w}Rotates the bits of the destination operand to the {direction}. Two forms: (1) ro<d> Dx/Im, Dn rotates Dn by the count in Dx or immediate (1–8), any size. Defaults to word. (2) ro<d> (An) rotates a memory word by 1, no size suffix allowed.
rts
Returns from a subroutine, pops the return address from the stack and jumps to it
scc
Sets the first byte of the destination operand to $FF (-1) if flags {condition code} is true, otherwise it sets it to 0
sub
(b, w, l) {w}Subtracts the value of the first operand from second operand and stores in the second. If the second operand is an address register, the SUBA instruction is used instead.
suba
(l, w) {w}Subtracts the value of the first operand from second operand and stores in the second. It does not change the SR. When using word size, the first operand is sign extended to long and the second is read and written as a long.
subi
(b, w, l) {w}Subtracts the immediate value to the second operand
subq
(b, w, l) {w}Subtracts the value of the first operand from second operand and stores in the second. The first operand value must be between 1 and 8. If the destination is a address register, it is always treated as a long, and the condition codes are not affected.
swap
Swaps the two word of the register, you can see the register as [a,b] after the swap it will be [b,a]
trap
Executes a trap, the value of the operand is used as the trap number, only #15 is supported. The register d0 holds the task number. The full table, with the registers each task takes and answers with, is on the trap tasks page.
| Task | Description |
|---|---|
| 0 | Print string pointed by a1 with length read in d1.w, null terminated with max of 255, then prints a new line. |
| 1 | Print string pointed by a1 with length read in d1.w. |
| 2 | Read string from keyboard, writes the string at address of a1 and overrides the value of d1 with the length of the string. |
| 3 | Print signed number at d1. |
| 4 | Read number, writes to d1. |
| 5 | Read character, writes to d1. |
| 6 | Print character at d1. |
| 7 | Check for keyboard input, writes 1 or 0 to d1.b. |
| 8 | Get the time in hundredths of a second since the run started, writes to d1. |
| 9 | Terminate. |
| 11 | Set or get the text cursor, or clear the screen with d1.w = $FF00. |
| 13 | Prints null terminated string pointed by a1 then prints new line, errors if string is longer than 16kb, to prevent infinite loops. |
| 14 | Prints null terminated string pointed by a1, errors if string is longer than 16kb, to prevent infinite loops. |
| 15 | Prints unsigned number at d1 in base (from 2 to 36) specified in d2.b |
| 17 | Prints the null terminated string at a1, then the signed number in d1. |
| 18 | Prints the null terminated string at a1, then reads a number into d1. |
| 19 | Reads the state of up to four keys given in d1.l, or the last keys pressed and released with d1.l = 0. |
| 20 | Print the signed number in d1 right justified in a field d2.b columns wide. |
| 23 | Delay for the number of hundredths of a second in d1. |
| 24 | Enable or disable the simulator shortcut keys; accepted and ignored. |
| 33 | Set or get the screen size, or set the window mode. |
| 61 | Read the mouse: flags in d0, y:x in d1. |
| 80-96 | Graphics: colors, pixels, lines, rectangles, ellipses, flood fill, drawing modes, double buffering, text and the pen position. |
tst
(b, w, l) {w}Compares the operand with 0
unlk
Sets the SP to the address register, then Pops a long value from the stack and stores the result in the address register