Category:68000 Assembly: Difference between revisions
Content deleted Content added
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
Line 111:
<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>
==The Flags==
The flags are stored in the Condition Code Register, also known as the <code>CCR</code>. The 68000 has no built-in commands like <code>CLC</code> for clearing/setting individual flags. Rather, you can alter them directly with <code>MOVE</code>,<code>AND</code>,<code>OR</code>, and <code>EOR</code>. Unfortunately, this means you'll have to remember which bits represent which flags. Or, if your assembler supports macros, you can define a macro that handles this for you.
The flags update automatically after most operations, and take into consideration the operand sizes when doing so. Check out this example:
<lang 68000devpac>
MOVE.L #$12FF,D0
ADD.B #1,D0
</lang>
Since we used <code>ADD.B</code>, D0 now contains $1200, and the extend, carry, and zero flags are all set. Had we done <code>ADD.W</code>, we would get $1300 in D0 with none of those flags set. The flags are based on what the actual instruction "sees", not the entire register at all times.
* X: The eXtend flag is bit 4 of the CCR, and is similar to the carry flag. It gets set and cleared often for the same reasons and is used with the <code>ADDX</code>, <code>SUBX</code>, <code>NEGX</code>, <code>ROXL</code>, and <code>ROXR</code> commands. Why the 68000 has both this and the carry flag, I still don't know.
* N: The negative flag is bit 3 of the CCR, and is set when the last operation resulted in a "negative" value. What constitutes a negative value depends on the size of the last operation - for <code>.B</code> instructions, $80-$FF. For <code>.W</code> instructions, $8000-$FFFF, and for <code>.L</code> instructions, $80000000-$FFFFFFFF.
* Z: The zero flag is bit 2 of the CCR and works like you would expect - it's set whenever an operation results in zero. Unlike x86 Assembly, this also includes moving 0 directly into a register, clearing a register <b>or memory</b> with <code>CLR</code>, etc.
* V: The overflow flag is set whenever a math operation results in a value crossing the $7F-$80 boundary. (Wraparound from 00 to FF doesn't count as overflow, but it does set the carry flag.)
* C: The carry flag is set when a math operation results in a carry or borrow. Rolling over from FF to 00, or a 1 getting "pushed out" via a bit shift or rotate, set the carry flag. When using <code>CMP</code>, the carry flag determines the unsigned magnitude comparison. Carry set is less than, carry clear is greater than or equal.
In truth, the flags are a 16-bit register, of which the CCR is just the "low half". The SR (status register) is the full 16-bit register.
There are a few additional flags in the upper half, which are used by the operating system. You can read these but for the most part you won't need to write to them.
==The Vector Table==
|