简体   繁体   中英

Do integers wrap around in ARMv6 assembly?

If I start with integer 1 and repeatedly LSL the value in the register, once the integer overflows, what is the intended behaviour?

mov r0,#1 /* 00000000000000000000000000000001 */
lsl r0,#1 /* 00000000000000000000000000000010 */
/* repeat 31 times */
lsl r0,#1 /* 10000000000000000000000000000000 */

On the next LSL, should the program:

  1. Crash
  2. Set r0 back to 1
  3. Something else? r0 = 0 ?

From section A2.2.1 of the v6-M reference manual, "Integer arithmetic", subsection "Shift and rotate operations":

(LSL) moves each bit of a bitstring left by a specified number of bits. Zeros are shifted in at the right end of the bitstring. Bits that are shifted off the left end of the bitstring are discarded, except that the last such bit can be produced as a carry output.

Therefore it becomes 0 and the carry flag is set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM