📄 cmp.html
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Comparison instructions</title><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /><meta http-equiv="content-language" content="en" /><meta name="resource-type" content="document"><meta name="copyright" content="This document copyright 2001 by Richard Murray. Use for non-profit and education purposes explicitly granted."><meta name="author" content="Richard Murray"><meta name="rating" content="general"></head><!-- /assembler/cmp.html --><!-- --><!-- (C) Copyright 2001 Richard Murray --><!-- Designed by Richard Murray --><!-- rmurray@heyrick.co.uk --><!-- --><body bgcolor="#f0f0f0" text="#000000" link="#0022dd" vlink="#002288"><table border = "0" width="100%"> <tr> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td> <td> <h1 align="center"><font color="#800080">Comparison<br>instructions</font></h1> </td> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td></table><p> <p><a name="cmn"></a><h2>CMN : Compare Negative</h2><pre> CMN<suffix> <op 1>, <op 2> status = op_1 - (- op_2)</pre><code>CMN</code> is the same as <code>CMP</code>, except it allows you to compare against smallnegative values (the logical NOT of operand two) that would be hard to implement otherwise; suchas -1 to end a list.<br>So to compare with -1 we would use:<pre> CMN R0, #1 ; Compare R0 with -1</pre>Refer also to the details for the <code>CMP</code> instruction.<p> <p> <p><a name="cmp"></a><h2>CMP : Compare</h2><pre> CMP<suffix> <op 1>, <op 2> status = op_1 - op_2</pre><code>CMP</code> allows you to compare the contents of a register with another register or animmediate value, updating the status flags to allow conditional execution to take place.<br>It performs a subtraction, but does not store the result anywhere. Instead, the flags are updatedas appropriate.<br>The flags refer to operand one compared against operand two. Thus, the GT suffix will be executedif operand one is greater than operand two.<br>Obviously you do not need to explicitly specify the <code>S</code> suffix as the point of thecommand is to update the status flags... If you do specify it, it will be ignored.<p> <p> <p><a name="teq"></a><h2>TEQ : Test Equivalence</h2><pre> TEQ<suffix> <op 1>, <op 2> Status = op_1 EOR op_2</pre><code>TEQ</code> is similar to <code>TST</code>. The difference is that the notional arithmeticalcalculation is an EOR rather than an AND.<br>This provides a way to see if bits in both operands are the same or not <i>without</i> affectingthe Carry flag (unlike <code>CMP</code>).<br><code>TEQ</code> is also used with the <code>P</code> suffix to alter the flags in R15 (in 26-bitmode). Refer to <a href="psr.html"><i>psr.html</i></a> for more details, or<a href="psr.html#32bit"><i>go here</i></a> for how to do it in 32-bit mode.<p> <p> <p><a name="tst"></a><h2>TST : Test bits</h2><pre> TST<suffix> <op 1>, <op 2> Status = op_1 AND op_2</pre><code>TST</code>, like <code>CMP</code>, does not produce a result to be placed into adestination register. Instead it performs an operation on the two operands given and reflectsthe result of this in the status flags.<br><code>TST</code> is used to see if a particular bit is set. Operand one is the data word totest and operand two is a bit mask. After testing, the Zero flag will be set upon a match, orotherwise clear.<br>Like <code>CMP</code>, it does not matter if you specify the <code>S</code> suffix or not.<pre> TST R0, #%1 ; Test if bit zero is set in R0</pre><p> <p> <p><hr size = "3"><a href="index.html#02">Return to assembler index</a><hr size = "3"><address>Copyright © 2001 Richard Murray</address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -