Category:68000 Assembly: Difference between revisions

m
 
(6 intermediate revisions by the same user not shown)
Line 1:
{{stub}}{{language}}
{{merge language | M680x0 }}
{{language}}
68000 assembly is the assembly language used for the Motorola 68000, or commonly known as the 68K. It should not be confused with the 6800 (which predates it). The Motorola 68000 is a big-endian processor with full 32-bit capabilities (despite most systems that use it being considered 16-bit.) It was used in many computers such as the Amiga or the Canon Cat, as well as game consoles such as the Sega Genesis and Neo Geo.
 
Line 113 ⟶ 115:
====The Stack====
The 68000's stack is commonly referred to as <code>SP</code> but it is also address register <code>A7</code>. This register is handled differently than the other address registers when pushing bytes onto the stack. A byte value pushed onto the stack will be padded to the <b>right</b>. The stack needs to pad byte-length data so that it can stay word-aligned at all times. Otherwise the CPU would crash as soon as you tried to use the stack for anything other than a byte!
 
 
You can abuse this property of the stack to quickly swap bytes around. Suppose you had a number like <code>#$11223344</code> stored in <code>D0</code> and you wanted to change it to <code>#$11224433</code>:
 
<lang 68000devpac>MOVE.W D0,-(SP) ;push #$3344 onto the stack
ROL.W #8,D0
MOVE.B (SP)+,D0 ;pop them in the order #$44 #$33.</lang>
 
===Length===
Line 140 ⟶ 135:
MOVE.L #0,D3 ;D3 = #$00000000</lang>
 
Loading immediate values into address registers is different. You can only move words or longer into address registers, and if you move a word, the value is sign-extended. This means that if the top nibble of the word is 8 or greater, the value gets padded to the left with Fs, and is padded with zeroes if the top nibble is 7 or less. ItIf you're adding a constant value less than 7FFF to an address, it's bestusually safe to alwaysuse movethe longsword intolength addressoperation, registers.which Thattakes wayless youbytes knowto whatencode you'rethan the long length gettingversion.
 
<lang 68000devpac>MOVEA.W #$8000,A4 ;A4 = #$FFFF8000. Remember the top byte is ignored so this is the same as #$00FF8000.
Line 189 ⟶ 184:
 
* It's best to push all registers (D0 thru D7 and A0-A6) onto the stack at the start and pop them off at the end. This is not required for the traps you call with the <code>TRAP #?</code> command, but for the others it's absolutely necessary, since you can't know in advance when they'll happen. You can leave out A7 when doing this since that's the stack pointer itself.
 
==Interrupts==
The 68000 supports 7 different interrupts, often called IRQs or Interrupt Requests. Enabling interrupts is often a twofold process: first, the interrupt source must be enabled, which is usually an implementation-defined process that involves interacting with memory-mapped ports. Second, the status register must be set accordingly to allow the interrupt to occur, which can be achieved with <code>MOVE #$2x00,SR</code> where X is the desired interrupt level. X can range from 0 to 7, and for an interrupt to occur, its interrupt level (which is determined by the hardware implementation and the placement of the desired address in the vector table) must be greater than X or it will not happen (even if the source is enabled.)
 
==Alignment==
Line 240 ⟶ 238:
#[[https://www.chibiakumas.com/68000/ ChibiAkumas Motorola 68000 Tutorial]]
#[[http://www.easy68k.com/paulrsm/doc/trick68k.htm 68000 Tricks and Traps]]
 
{{merge language | M680x0 }}
1,489

edits