请问循环左/右移的汇编语句应该怎么写呢?

mstlq 2009-12-02 04:48:21
如题^_^
体力不支,没心思去google,只好懒一回^_^

另外,求下面代码的汇编版本,谢谢^_^

void Udadress(UINT *adress,size_t len, UINT newValue, size_t ex)
{
assert(ex<8 && len>0);
for (size_t pos=0; pos<len-1; ++pos)
{
adress[pos] = (adress[pos]<<ex) | (adress[pos+1] >> (32-ex));
}
adress[len-1] = (adress[len-1]<<ex) | ((0x01<<len) -1) & (newValue);
return ;
}

...全文
456 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
苍蝇①号 2009-12-02
  • 打赏
  • 举报
回复
在AT &T的汇编中相应的左右移指令:
sall k,D
shll k,D
sarl k,D
shrl k,D
jernymy 2009-12-02
  • 打赏
  • 举报
回复
使用的是mingw 自带的gcc编译的汇编
jernymy 2009-12-02
  • 打赏
  • 举报
回复


#define UINT unsigned int
#define size_t int

void Udadress(UINT *adress, size_t len, UINT newValue, size_t ex)
{
assert(ex<8 && len>0);
for (size_t pos=0; pos<len-1; ++pos)
{
adress[pos] = (adress[pos]<<ex) | (adress[pos+1] >> (32-ex));
}
adress[len-1] = (adress[len-1]<<ex) | ((0x01<<len) -1) & (newValue);
return ;
}



.file "new.c"
.text
.globl _Udadress
.def _Udadress; .scl 2; .type 32; .endef
_Udadress:
pushl %ebp
movl %esp, %ebp
pushl %edi
pushl %esi
pushl %ebx
subl $12, %esp
movl $0, -20(%ebp)
cmpl $7, 20(%ebp)
jg L2
cmpl $0, 12(%ebp)
jle L2
movl $1, -20(%ebp)
L2:
movl -20(%ebp), %eax
movl %eax, (%esp)
call _assert
movl $0, -16(%ebp)
L3:
movl 12(%ebp), %eax
decl %eax
cmpl %eax, -16(%ebp)
jl L6
jmp L4
L6:
movl -16(%ebp), %eax
leal 0(,%eax,4), %esi
movl 8(%ebp), %edi
movl -16(%ebp), %eax
leal 0(,%eax,4), %edx
movl 8(%ebp), %eax
movzbl 20(%ebp), %ecx
movl (%eax,%edx), %eax
movl %eax, %ebx
sall %cl, %ebx
movl -16(%ebp), %eax
sall $2, %eax
addl 8(%ebp), %eax
leal 4(%eax), %edx
movl $32, %eax
movl %eax, %ecx
subl 20(%ebp), %ecx
movl (%edx), %eax
shrl %cl, %eax
orl %ebx, %eax
movl %eax, (%edi,%esi)
leal -16(%ebp), %eax
incl (%eax)
jmp L3
L4:
movl 12(%ebp), %eax
sall $2, %eax
addl 8(%ebp), %eax
leal -4(%eax), %ebx
movl 12(%ebp), %eax
sall $2, %eax
addl 8(%ebp), %eax
subl $4, %eax
movzbl 20(%ebp), %ecx
movl (%eax), %eax
movl %eax, %edx
sall %cl, %edx
movl $1, %eax
movzbl 12(%ebp), %ecx
sall %cl, %eax
decl %eax
andl 16(%ebp), %eax
orl %edx, %eax
movl %eax, (%ebx)
addl $12, %esp
popl %ebx
popl %esi
popl %edi
popl %ebp
ret
.def _assert; .scl 2; .type 32; .endef


老邓 2009-12-02
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 mstlq 的回复:]
请问现在的csdn是不是取消“问专家”功能了 >_ <?
[/Quote]
取消了半年左右了...
mstlq 2009-12-02
  • 打赏
  • 举报
回复
请问现在的csdn是不是取消“问专家”功能了 >_<?
mLee79 2009-12-02
  • 打赏
  • 举报
回复
偶觉得这个定向到汇编版的宝宝或者数据结构版出没的gxqcn写这个比较放心....

whg01 2009-12-02
  • 打赏
  • 举报
回复
http://hi.baidu.com/shawpinlee/blog/item/1cf5f8fb3efb5c214f4aea9b.html
楼主想用的是SHL和SHR吧?
z569362161 2009-12-02
  • 打赏
  • 举报
回复
我是来接点分的
loveour 2009-12-02
  • 打赏
  • 举报
回复
标记一下...
对汇编还真是有一个反复的认识...最开始觉得,这才是编程,厉害;然后觉得没什么用,反正用不到,再然后发现还是离不开,而且有助于很多问题的理解...
baihacker 2009-12-02
  • 打赏
  • 举报
回复
ROR Rotate bits right

operands bytes 8088 186 286 386 486 Pentium
reg, 1 2 2 2 2 3 3 1 PU
mem, 1 2+d(0,2) 23+EA 15 7 7 4 3 PU
reg, cl 2 8+4n 5+n 5+n 3 3 4 NP
mem, cl 2+d(0,2) 28+EA+4n 17+n 8+n 7 4 4 NP
reg, imm 3 - 5+n 5+n 3 2 1 PU
mem, imm 3+d(0,2) - 17+n 8+n 7 4 3 PU*

* = not pairable if there is a displacement and immediate

Example: ror eax, 16


ROL Rotate bits left

operands bytes 8088 186 286 386 486 Pentium
reg, 1 2 2 2 2 3 3 1 PU
mem, 1 2+d(0,2) 23+EA 15 7 7 4 3 PU
reg, cl 2 8+4n 5+n 5+n 3 3 4 NP
mem, cl 2+d(0,2) 28+EA+4n 17+n 8+n 7 4 4 NP
reg, imm 3 - 5+n 5+n 3 2 1 PU
mem, imm 3+d(0,2) - 17+n 8+n 7 4 3 PU*

* = not pairable if there is a displacement and immediate

Example: rol eax, 16


RCL Rotate bits left with CF

operands bytes 8088 186 286 386 486 Pentium
reg, 1 2 2 2 2 9 3 1 PU
mem, 1 2+d(0,2) 23+EA 15 7 10 4 3 PU
reg, cl 2 8+4n 5+n 5+n 9 8-30 7-24 NP
mem, cl 2+d(0,2) 28+EA+4n 17+n 8+n 10 9-31 9-26 NP
reg, imm 3 - 5+n 5+n 9 8-30 8-25 NP
mem, imm 3+d(0,2) - 17+n 8+n 10 9-31 10-27 NP

Example: rcl eax, 16


RCR Rotate bits right with CF

operands bytes 8088 186 286 386 486 Pentium
reg, 1 2 2 2 2 9 3 1 PU
mem, 1 2+d(0,2) 23+EA 15 7 10 4 3 PU
reg, cl 2 8+4n 5+n 5+n 9 8-30 7-24 NP
mem, cl 2+d(0,2) 28+EA+4n 17+n 8+n 10 9-31 9-26 NP
reg, imm 3 - 5+n 5+n 9 8-30 8-25 NP
mem, imm 3+d(0,2) - 17+n 8+n 10 9-31 10-27 NP

Example: rcr eax, 16









Legend:
General
acc = AL, AX or EAX unless specified otherwise
reg = any general register
r8 = any 8-bit register
r16 = any general purpose 16-bit register
r32 = any general purpose 32-bit register
imm = immediate data
imm8 = 8-bit immediate data
imm16 = 16-bit immediate data
mem = memory address
mem8 = address of 8-bit data item
mem16 = address of 16-bit data item
mem32 = address of 32-bit data item
mem48 = address of 48-bit data item
dest = 16/32-bit destination
short = 8-bit destination

Integer instruction timings:
n - generally refers to a number of repeated counts
m - in a jump or call;
286: bytes in next instruction
386/486: number of components
(each byte of opcode) + 1 (if immed data) + 1 (if displacement)
EA = cycles to calculate the Effective Address
8088/8086:
base = 5 BP+DI or BX+SI = 7 BP+DI+disp or BX+SI+disp = 11
index = 5 BX+DI or BP+SI = 8 BX+DI+disp or BP+SI+disp = 12
disp = 6 segment override = +2
286 - 486:
base+index+disp = +1 all others, no penalty

instruction length:

The byte count includes the opcode length and length of any required
displacement or immediate data. If the displacement is optional, it
is shown as d() with the possible lengths in parentheses. If the
immediate data is optional, it is shown as i() with the possible
lengths in parentheses.

pairing categories for Pentium:

NP = not pairable
UV = pairable in the U pipe or V pipe
PU = pairable in the U pipe only
PV = pairable in the V pipe only
(end of legend)

老邓 2009-12-02
  • 打赏
  • 举报
回复
关于汇编,编译器可以生成汇编代码。详见:http://www.qpsoft.com/blog/asm-c-cpp-cl-fa-compiler/
mstlq 2009-12-02
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 whg01 的回复:]
http://hi.baidu.com/shawpinlee/blog/item/1cf5f8fb3efb5c214f4aea9b.html
楼主想用的是SHL和SHR吧?
[/Quote]
其实是想要下面四个的例子……
ROL
ROR
RCL
RCR
FancyMouse 2009-12-02
  • 打赏
  • 举报
回复
x86 asm: ror/rol

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧