📄 shift.html
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Shift</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/shift.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">Shifting</font></h1> </td> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td></table><p> <p>The ARM processor incorporates a barrel shifter that can be used with the data processinginstructions (ADC, ADD, AND, BIC, CMN, CMP, EOR, MOV, MVN, ORR, RSB, SBC, SUB, TEQ, TST). Youcan also use the barrel shifter to affect the index value in LDR/STR operations.<p>There are six mnemonics for the different shift types:<pre> LSL Logical Shift Left ASL Arithmetic Shift Left LSR Logical Shift Right ASR Arithmetic Shift Right ROR Rotate Right RRX Rotate Right with Extend</pre><code>ASL</code> and <code>LSL</code> are the same, and may be freely interchanged.<p>You can specify a shift with an immediate value (from zero to thirty one), or by a registerwhich contains a value between zero and thirty one.<p> <p><a name="lsl"></a><a name="asl"></a><h2>Logical or Arithmetic Shift Left</h2><pre> Rx, LSL #n or Rx, ASL #n or Rx, LSL Rn or Rx, ASL Rn</pre>The contents of Rx will be taken and shifted to a more significant position by the amountspecified by 'n' or in the register Rn. The least significant bits are filled with zeroes. Thehigh bits shifted off to the left are discarded, except for the notional bit thirty three (ie,the last bit to be shifted off) which becomes the value of the carry flag on exit from the barrel shifter.<p>Consider the following:<pre> MOV R1, #12 MOV R0, R1, LSL#2</pre>On exit, R0 is 48. The instructions forming the sum <code>R0 = #12, LSL#2</code> is equivalentto the BASIC <code>R0 = 12 << 2</code><p> <p><a name="lsr"></a><h2>Logical Shift Right</h2><pre> Rx, LSR #n or Rx, LSR Rn</pre>This does the notional opposite of shifting left. Everything is shifted to the right, to a lesssignificant position. It is the same as <code>register = value >>> shift</code>.<p> <p><a name="asr"></a><h2>Arithmetic Shift Right</h2><pre> Rx, ASR #n or Rx, ASR Rn</pre>This is similar to LSR, with the exception that the high bits are filled with the value of bit31 of the register being shifted (Rx), in order to preserve the sign in 2's complement maths.It is the same as <code>register = value >> shift</code>.<p> <p><a name="ror"></a><h2>Rotate Right</h2><pre> Rx, ROR #n or Rx, ROR Rn</pre>Rotate Right is similar to a Logical Shift Right, except the bits which would normally beshifted off the right are replaced on the left, this the bits 'rotate'. An operation where theamount to be shifted by is 32 would result in the output being identical to the input as allbits would have been shifted by 32 places, ie, right back to where they started!<p> <p><a name="rrx"></a><h2>Rotate Right with Extend</h2><pre> Rx, RRX</pre>This is a ROR#0 operation, which rotates one place to the right - the difference is that theprocessor's Carry flag is used to provide a 33 bit quantity to be shifted.<br><font size = "-1">Thanks to <i>Ian Jeffray</i> for the correction.</font><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 + -