Large binary shifts in 8086 assembly?

六月ゝ 毕业季﹏ 提交于 2019-12-13 16:07:05

问题


I have a binary chunk of data 512 bytes long, I was wondering what the most efficient way would be if I wanted to shift it once to the right.

My best guess right now (very new to assembly) would be that I would have to first check a chunk (probably int) to see what it would shift out, shift, then carry in whatever the previous int would have shifted out and proceed carrying this shift down the data. Is there an easier way? If I have to use this carry technique, what's the largest chunk I can shift? DWord? QWord?


回答1:


If you just want to shift once, use the rotate-through-carry instructions.

First, make sure the carry flag is zero. Then:

  1. Pull 4 bytes into a register
  2. RCR
  3. Write back out
  4. Repeat with the next 4 bytes



回答2:


Shifting under x86 is very simple even for large memory structutes.

1)Set or clear carry flag depend of what do you wont as first bit (LSB) of result.

2)There is no need to pull data in registers you can direct shift 32bits at once in memory like:

rcr     dword ptr[edx], 1

or even better

rcr     dword ptr[edx + ecx *4], 1

where ecx is a loop counter and edx a memory pointer.

2)Store last shifted carry bit

EDIT: In memory you can shift at once 32bits and don't forget on memory aligment, shift 32bit aligend dwords to increase execution speed.




回答3:


The x86 processors have a Carry flag that works wonderfully for this purpose. There are instructions to shift with the Carry flag, scr and scl. http://en.wikibooks.org/wiki/X86_Assembly/Shift_and_Rotate#Shift_With_Carry_Instructions



来源:https://stackoverflow.com/questions/3209851/large-binary-shifts-in-8086-assembly

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