What is an assembly shift?

独自空忆成欢 提交于 2019-12-24 10:38:57

问题


I was reading this document: http://www.fadden.com/techmisc/hdc/lesson11.htm

In it he stated:

Problem is, we don't know how long these are. So, we encode the length with the unary coding we looked at first (colons added for clarity):

 value     binary coding
 1         1:
 2         01:0
 3         01:1
 4         001:00
 5         001:01
 16        00001:0000
 64        0000001:000000
 256       000000001:00000000

This method is actually floor(log i) zeros, followed by a 1, followed by the binary code without the leading 1. Since the first part is a unary count, there is one '0' for every bit in the second part. This means we can intersperse the data bits with the zeros, like this:

 value     binary coding
 1         1
 2         001
 3         011
 4         00001
 5         00011
 16        000000001
 64        0000000000001
 256       00000000000000001

This has the same length, but can be implemented with a simple shift routine (assembly: shift left, if carry set then exit, else shift the next bit into the integer we're forming).

What exactly is this assembly shift and is it reversible, meaning can 00000000000000001 go back to 00000000100000000 without extra data?

An animation of an assembly shift would be excellent. Thanks


回答1:


It's a bit shift operation, see for instance this Wikipedia article: http://en.wikipedia.org/wiki/Bit_shift#Bit_shifts

The bits that get shifted out are usually not recoverable (except for rotate), so the operation is not reversible in itself. There are variants where, if you shift over just a single bit position, the value of the bit shifted out is saved in a flag register (the carry bit mentioned in your quote) where you can use it for a conditional jump.



来源:https://stackoverflow.com/questions/3451987/what-is-an-assembly-shift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!