AriX
AriX

Reputation: 1687

How does the carry flag work on the 68000?

So I'm a bit confused about how the carry flag works, specifically on the 68000 processor (but it may not matter).

My main question is as follows:

move.b (a0),d0
moveq #7,d1
cmp.b d1,d0
bcc.s DATAErr3

Obviously the byte at A0 is being copied to D0, and then D0 is being compared to 7. But then, there is a branch to DATAErr3 if the carry flag is set ("bcc"). In this operation, what values of D0 would cause the carry flag to be set? What values would cause it to not be set?

Thanks!

Upvotes: 1

Views: 2951

Answers (3)

Miro Kropacek
Miro Kropacek

Reputation: 2886

Another way of looking at bcc and bcs is:

  • blo = bcs
  • bhs = bcc

I.e. bcc is equivalent to unsigned "higher than or same" condition and blo to unsigned "lower than"

Upvotes: 0

lvd
lvd

Reputation: 812

As you probably know, cmp is actually a subtraction, but without updating destination. For 68000 assembler syntax, destination is always at the right. So cmp.b d1,d0 command subtracts byte stored in d1 from byte stored in d0 and then discards result, but updates flags according to that operation.
Carry flag is set based on unsigned values in registers.
Therefore, if d0.b contains anything from 0 up to 6, subtraction of 7 from 0..6 will generate borrow and set carry flag. bcc.s will not branch. When d0.b is anything from 7 up to 255, carry will be cleared and bcc.s will branch.

Upvotes: 3

Thomas Minor
Thomas Minor

Reputation: 657

BCC branches if d0 >= d1, in an unsigned comparison. In this case, the BCC instruction will branch if d0 is greater than or equal to 7, or is negative.

http://www.easy68k.com/paulrsm/doc/trick68k.htm

Upvotes: 3

Related Questions