3

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)?

RobIII
  • 8,488
  • 2
  • 43
  • 93
Milan Novaković
  • 331
  • 8
  • 16
  • I'm recalling that in some architectures the thing to do is to simply add the carry bit to zero. – Hot Licks May 27 '14 at 02:45
  • @HotLicks But how would I access the carry bit? I'm at a loss as to how to grab/separate this information out of the CCR. – Milan Novaković May 27 '14 at 02:53
  • The point is, most instruction sets have a "add carry" instruction of some sort, which adds the carry bit to the low-order bit of another operand. This is used for a "chained" add. – Hot Licks May 27 '14 at 03:18
  • Look at ADDX. Close as I can figure in 5 minutes browsing, the X bit is set from the carry. – Hot Licks May 27 '14 at 03:35
  • One slow way is to set some register to one, then use BCC, and if jump was not taken, set that register to 0. This is value of carry. – dbrank0 May 27 '14 at 08:17

1 Answers1

4

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.

Durandal
  • 19,919
  • 4
  • 36
  • 70