📄 mov.html
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Arithmetic and Logical 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/mov.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">Arithmetic and Logical<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="adc"></a><h2>ADC : Addition with Carry</h2><pre> ADC<suffix> <dest>, <op 1>, <op 2> dest = op_1 + op_2 + carry</pre><code>ADC</code> will add the two operands, placing the result in the destination register. Ituses a carry bit, so can add numbers larger than 32 bits. The following example will add two 128bit numbers.<br>128 bit result: Registers 0, 1, 2, and 3<br>128 bit first: Registers 4, 5, 6, and 7<br>128 bit second: Registers 8, 9, 10, and 11.<pre> ADDS R0, R4, R8 ; Add low words ADCS R1, R5, R9 ; Add next word, with carry ADCS R2, R6, R10 ; Add third word, with carry ADCS R3, R7, R11 ; Add high word, with carry</pre>If doing addition such as this, don't forget to set the S suffix so that the status of theCarry flag is updated.<p> <p> <p><a name="add"></a><h2>ADD : Addition</h2><pre> ADD<suffix> <dest>, <op 1>, <op 2> dest = op_1 + op_2</pre><code>ADD</code> will add the two operands, placing the result in the destination register.Operand 1 is a register, operand 2 can be a register, shifted register, or an immediate value:<pre> ADD R0, R1, R2 ; R0 = R1 + R2 ADD R0, R1, #256 ; R0 = R1 + 256 ADD R0, R2, R3,LSL#1 ; R0 = R2 + (R3 << 1)</pre>The addition may be performed on signed or unsigned numbers.<p> <p> <p><a name="and"></a><h2>AND : Logical AND</h2><pre> AND<suffix> <dest>, <op 1>, <op 2> dest = op_1 AND op_2</pre><code>AND</code> will perform a logical AND between the two operands, placing the result in thedestination register; this is useful for masking the bits you wish to work on.Operand 1 is a register, operand 2 can be a register, shifted register, or an immediate value:<pre> AND R0, R0, #3 ; R0 = Keep bits zero and one of R0, discard the rest.</pre>An AND table (result = both):<pre> Op_1 Op_2 Result 0 0 0 0 1 0 1 0 0 1 1 1</pre><p> <p> <p><a name="bic"></a><h2>BIC : Bit Clear</h2><pre> BIC<suffix> <dest>, <op 1>, <op 2> dest = op_1 AND (!op_2)</pre><code>BIC</code> is a way to clear bits within a word, a sort of reverse OR.<br>Operand two is a 32 bit bit mask. If a bit is set in the mask, it will be cleared. Unset maskbits indicate bits to be left alone.<pre> BIC R0, R0, #%1011 ; Clear bits zero, one, and three in R0. Leave the remaining bits alone.</pre>A BIC table:<pre> Op_1 Op_2 Result 0 0 0 0 1 0 1 0 1 1 1 0</pre><p> <p> <p><a name="eor"></a><h2>EOR : Logical Exclusive OR</h2><pre> EOR<suffix> <dest>, <op 1>, <op 2> dest = op_1 EOR op_2</pre><code>EOR</code> will perform a logical Exclusive OR between the two operands, placing theresult in the destination register; this is useful for inverting certain bits.Operand 1 is a register, operand 2 can be a register, shifted register, or an immediate value:<pre> EOR R0, R0, #3 ; Invert bits zero and one in R0</pre>An EOR table (result = either, but not both):<pre> Op_1 Op_2 Result 0 0 0 0 1 1 1 0 1 1 1 0</pre><p> <p> <p><a name="mov"></a><h2>MOV : Move</h2><pre> MOV<suffix> <dest>, <op 1> dest = op_1</pre><code>MOV</code> loads a value into the destination register, from another register, a shiftedregister, or an immediate value.<br>You can specify the same register for the effect of a NOP instruction, or you can shift thesame register if you choose:<pre> MOV R0, R0 ; R0 = R0... NOP instruction MOV R0, R0, LSL#3 ; R0 = R0 * 8</pre>If R15 is the destination, the program counter or flags can be modified. This is used to returnto calling code, by moving the contents of the link register into R15:<pre> MOV PC, R14 ; Exit to caller MOVS PC, R14 ; Exit to caller preserving flags <font color="red">(not 32-bit compliant)</font></pre><p> <p> <p><a name="mvn"></a><h2>MVN : Move Negative</h2><pre> MVN<suffix> <dest>, <op 1> dest = !op_1</pre><code>MVN</code> loads a value into the destination register, from another register, a shiftedregister, or an immediate value.<br>The difference is the bits are inverted prior to moving, thus you can move a negative value intoa register.<br>Due to the way this works (two's complement), you want to move one less than the required number:<pre> MVN R0, #4 ; R0 = -5 MVN R0, #0 ; R0 = -1</pre><p> <p> <p><a name="orr"></a><h2>ORR : Logical OR</h2><pre> ORR<suffix> <dest>, <op 1>, <op 2> dest = op_1 OR op_2</pre><code>OR</code> will perform a logical OR between the two operands, placing the result in thedestination register; this is useful for setting certain bits to be set.Operand 1 is a register, operand 2 can be a register, shifted register, or an immediate value:<pre> ORR R0, R0, #3 ; Set bits zero and one in R0</pre>An OR table (result = either or both):<pre> Op_1 Op_2 Result 0 0 0 0 1 1 1 0 1 1 1 1</pre><p> <p> <p><a name="rsb"></a><h2>RSB : Reverse Subtraction</h2><pre> RSB<suffix> <dest>, <op 1>, <op 2> dest = op_2 - op_1</pre><code>SUB</code> will subtract operand <b>one</b> from operand <b>two</b>, placing the result inthe destination register.Operand 1 is a register, operand 2 can be a register, shifted register, or an immediate value:<pre> RSB R0, R1, R2 ; R0 = R2 - R1 RSB R0, R1, #256 ; R0 = 256 - R1 RSB R0, R2, R3,LSL#1 ; R0 = (R3 << 1) - R2</pre>The subtraction may be performed on signed or unsigned numbers.<p> <p> <p><a name="rsc"></a><h2>RSC : Reverse Subtraction with Carry</h2><pre> RSC<suffix> <dest>, <op 1>, <op 2> dest = op_2 - op_1 - !carry</pre>This is the same as <code>SBC</code>, except the operands are subtracted the other way around.<p> <p> <p><a name="sbc"></a><h2>SBC : Subtraction with Carry</h2><pre> SBC<suffix> <dest>, <op 1>, <op 2> dest = op_1 - op_2 - !carry</pre><code>SBC</code> will subtract the two operands, placing the result in the destination register.It uses the carry bit to represent 'borrow', so can subtract numbers larger than 32bits.<br><code>SUB</code> and <code>SBC</code> generate the Carry flag the wrong way around, if a borrowis required then the carry flag is UNSET. Thus, this instruction requires a NOT Carry flag - itinverts the flag automatically during the instruction.<p> <p> <p><a name="sub"></a><h2>SUB : Subtraction</h2><pre> SUB<suffix> <dest>, <op 1>, <op 2> dest = op_1 - op_2</pre><code>SUB</code> will subtract operand two from operand one, placing the result in thedestination register.Operand 1 is a register, operand 2 can be a register, shifted register, or an immediate value:<pre> SUB R0, R1, R2 ; R0 = R1 - R2 SUB R0, R1, #256 ; R0 = R1 - 256 SUB R0, R2, R3,LSL#1 ; R0 = R2 - (R3 << 1)</pre>The subtraction may be performed on signed or unsigned numbers.<p> <p> <p><a name="swp"></a><h2>SWP : Swap</h2><pre> SWP<suffix> <dest>, <op 1>, [<op 2>]</pre><code>SWP</code> will:<ul> <li> Load a word from memory, address pointed to by operand two, and put that word in the destination register. <li> Store the contents of register operand one to that same address.</ul>If the destination and operand one are the same register, then the contents of the register andthe contents of the memory location given will be swapped.<br>If the <code>B</code> suffix is set, then a byte will be transferred, otherwise a word will betransferred.<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 + -