Difference between revisions of "680x0:Condition codes"

From Amiga Coding
Jump to: navigation, search
(added signed/unsigned, mathematical meaning and some more CC's)
(added explaination/example)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
{|
 +
|valign=top|
 
Condition codes are used in branch instructions Bcc and DBcc.<br />
 
Condition codes are used in branch instructions Bcc and DBcc.<br />
Replace the cc with any of the following codes:
+
Replace the cc with any of the code you see in the list.
  
  
 +
===Example===
 +
If you like to branch/goto another place in the code if a signed number is greater or equal to 8 use:
 +
 +
<code><pre>
 +
  CMP.B #8,D0
 +
  BGE  ItsGreaterOrEqual
 +
 +
ItsGreaterOrEqual:
 +
</pre></code>
 +
 +
 +
===Signed/unsigned===
 +
Unsigned numbers can only be positive, while in signed numbers the highest bit is used to tell if the number is negative. As assembler programmer it's up to you to conciously choose the correct condition code for signed/unsigned numbers.
 +
|width=60|
 +
|valign=top|
 
<table class="sortable">
 
<table class="sortable">
 
<tr><th>cc</th><th>mathematical</th><th>meaning</th><th>bitcode</th><th>signed</th><th>comment</th></tr>
 
<tr><th>cc</th><th>mathematical</th><th>meaning</th><th>bitcode</th><th>signed</th><th>comment</th></tr>
Line 8: Line 25:
 
<tr><td>EQ</td><td>b==a</td><td>Equal</td><td>0111</td><td></td></tr>
 
<tr><td>EQ</td><td>b==a</td><td>Equal</td><td>0111</td><td></td></tr>
  
<tr><td>HI</td><td>b>a</td><td>High</td><td>0010</td><td>unsigned</td></tr>
+
<tr><td>HI</td><td>b>a</td><td>HIgher</td><td>0010</td><td>unsigned</td></tr>
 
<tr><td>LO</td><td>b<a</td><td>LOwer</td><td></td><td>unsigned</td></tr>
 
<tr><td>LO</td><td>b<a</td><td>LOwer</td><td></td><td>unsigned</td></tr>
 
<tr><td>HS</td><td>b>=a</td><td>Higher or Same</td><td></td><td>unsigned</td></tr>
 
<tr><td>HS</td><td>b>=a</td><td>Higher or Same</td><td></td><td>unsigned</td></tr>
 
<tr><td>LS</td><td>b<=a</td><td>Lower or same</td><td>0011</td><td>unsigned</td></tr>
 
<tr><td>LS</td><td>b<=a</td><td>Lower or same</td><td>0011</td><td>unsigned</td></tr>
  
<tr><td>GT</td><td>b>a</td><td>Greater then</td><td>1110</td><td>signed</td></tr>
+
<tr><td>GT</td><td>b>a</td><td>Greater Then</td><td>1110</td><td>signed</td></tr>
<tr><td>LT</td><td>b<a</td><td>Less then</td><td>1101</td><td>signed</td></tr>
+
<tr><td>LT</td><td>b<a</td><td>Less Then</td><td>1101</td><td>signed</td></tr>
<tr><td>GE</td><td>b>=a</td><td>Greater then or equal</td><td>1100</td><td>signed</td></tr>
+
<tr><td>GE</td><td>b>=a</td><td>Greater then or Equal</td><td>1100</td><td>signed</td></tr>
<tr><td>LE</td><td>b<=a</td><td>Less then or equal</td><td>1111</td><td>signed</td></tr>
+
<tr><td>LE</td><td>b<=a</td><td>Less then or Equal</td><td>1111</td><td>signed</td></tr>
  
 
<tr><td>MI</td><td>b<0</td><td>Minus</td><td>1011</td><td></td></tr>
 
<tr><td>MI</td><td>b<0</td><td>Minus</td><td>1011</td><td></td></tr>
Line 33: Line 50:
  
 
</table>
 
</table>
 +
|}

Latest revision as of 23:45, 4 March 2008

Condition codes are used in branch instructions Bcc and DBcc.
Replace the cc with any of the code you see in the list.


Example

If you like to branch/goto another place in the code if a signed number is greater or equal to 8 use:

  CMP.B #8,D0
  BGE   ItsGreaterOrEqual

ItsGreaterOrEqual:


Signed/unsigned

Unsigned numbers can only be positive, while in signed numbers the highest bit is used to tell if the number is negative. As assembler programmer it's up to you to conciously choose the correct condition code for signed/unsigned numbers.

ccmathematicalmeaningbitcodesignedcomment
NEb<>aNot equal0110
EQb==aEqual0111
HIb>aHIgher0010unsigned
LOb<aLOwerunsigned
HSb>=aHigher or Sameunsigned
LSb<=aLower or same0011unsigned
GTb>aGreater Then1110signed
LTb<aLess Then1101signed
GEb>=aGreater then or Equal1100signed
LEb<=aLess then or Equal1111signed
MIb<0Minus1011
PLb>0Plus1010
CCCarry clear0100
CSCarry set0101
VCNo overflow1000
VSOverflow1001

(the next 2 are not known by all assemblers, because they aren't really usefull) (Seka does know them)
TTrue0000allways branch, same as bra
FFalse0001never branch