Category:68000 Assembly: Difference between revisions

no edit summary
m (Added Sega Genesis and Neo Geo)
No edit summary
Line 1:
{{stub}}{{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.
 
 
==Architecture Overview==
 
===Data Registers===
There are eight 32-bit data registers on the 68000, numbered D0-D7. As the name implies, these are designed to hold data. Similar to the ARM processor, each one is identical in terms of which commands it can use. A command that can be used for D0 can be used for any other D-register.
 
<lang 68000devpac>MOVE.B #$FF,D0 ;move the hexadecimal value 0xFF into the bottom byte of D0.
ADD.W #$8000,D4 ;add hexadecimal 0x8000 to the value stored in D4.</lang>
 
===Address Registers===
There are eight of these as well, numbered A0-A7. A7 is reserved as the stack pointer, and is commonly referenced as SP in assemblers. The others are free to use for any purpose. Although these registers are 32-bit, the 68000's address space is 24-bit (ranges from 0x000000 to 0xFFFFFF), so the leftmost byte is ignored. You can do simple math involving these registers but more complicated commands like multiply or divide can only be used with data registers. Address registers are used to contain addresses and extract the values stored within.
 
<lang 68000devpac>MOVEA.L #$200000,A2 ;usually these are loaded from a label.
;The hex dump of address $200000: 44 55 66 77
MOVE.L #$00000000,D0
MOVE.B (A2),D0 ;load the byte stored at $200000 into D0. D0 = #$00000044
MOVE.W (A2),D0 ;load the word stored at $200000 into D0. D0 = #$00004455
MOVE.L (A2),D0 ;load the long stored at $200000 into D0. D0 = #$44556677</lang>
 
===Length===
The 68000 can work with 8-bit, 16-bit, or 32-bit values. Some commands only work with specific lengths but most work with all three. To specify which length you are using, the command ends in a different suffix:
* .B for byte length (8 bit)
* .W for word length (16 bit)
* .L for long length (32 bit)
 
If you don't specify a length with your command, it usually defaults to word length, but ultimately it depends on the command you are using. (Some commands cannot be used at word length.)
 
Bytes and words moved into a register are always stored on the right-hand side. For example:
<lang 68000devpac>MOVE.L #$FFFFFFFF,D7
MOVE.B #$00,D7 ;D7 contains #$FFFFFF00
MOVE.W #$2222,D7 ;D7 contains #$FFFF2222</lang>
 
If the given constant is smaller than the length provided, the value is padded to the left with zeroes.
<lang 68000devpac>MOVE.W #$FF,D3 ;D3 = #$xxxx00FF, where x is the previous value of D3.
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. It's best to always move longs into address registers. That way you know what you're getting.
 
<lang 68000devpac>MOVEA.W #$8000,A4 ;A4 = #$FFFF8000. Remember the top byte is ignored so this is the same as #$00FF8000.
MOVEA.W #$7FFF,A3 ;A3 = #$00007FFF</lang>
 
 
 
==Citations==
#[[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