How to store the carry-bit from Assembly 68K CCR?

1.9k views Asked by At

I did find a MOVE from CCR instruction in the manual... http://www.freescale.com/files/archives/doc/ref_manual/M68000PRM.pdf

But I keep getting an 'invalid addressing mode' error. I've tried different forms of syntax and anyways I only want to store the carry bit, not the entire CCR. These are all syntax I've tried with no luck. It very explicitly says the size must be word.

MOVE.W CCR,D6
MOVE.W CCR,CARRY
MOVE   CCR,D6
MOVE   CCR,CARRY
MOVE.B CCR,D6
MOVE.B CCR,CARRY

Nada. What am I doing wrong? Is there a better way to store specifically the carry out bit (C)?

1

There are 1 answers

0
Durandal On

You should not access the SR/CCR directly to get the state of a single flag.

The 68K family has the very handy S(cc) instruction (set on condition) that takes a conditional predicate for (cc), and results in a byte reflecting the condition. Example:

SEQ D0

If zero flag is cleared, D0.b becomes 0x00, otherwise 0xFF. All conditional predicates are valid for this instruction, that includes the carry based tests (SCS, SCC).

Your problem with the CCR is that it is first and foremost not allowed on the MC68000 (it simply doesn't exist, its an extension introduced with the MC68010). I'm not sure if executing a MOVE from CCR triggers an IllegalInstruction or if it converts silently to MOVE from SR (they have almost the same encoding, only MOVE SR is word sized, MOVE CCR is byte sized).

You should also not use MOVE from SR instead, that will blow up on all the MC680x0 with x > 0, because the instruction is supervisor only (privileged) on these processors.

Accessing the SR requires great care because of these differences within the family.