c - 如何解释汇编并将其编写为类似 RISC 的微操作
问题描述
我正在学习组装并遇到了这种做法。
我正在使用的书是:Randal E. Bryant, David R. O'Hallaron - Computer Systems。程序员的视角 [第 3 版](2016 年,Pearson)
我得到了这段 C 代码内部循环的汇编代码,其中有一个累加计算来计算 r。使用 AT&T。
L3:
mulsd (%rcx,%rax,8), %xmm0
mulsd 8(%rcx,%rax,8), %xmm0
mulsd 16(%rcx,%rax,8), %xmm0
addq $3, %rax
cmpq %r8, %rax
jl .L3
这是对应的C代码
double randomproduct(double a[], long n)
{
long i;
double x, y, z;
double r=1;
for (i=0; i<n-2; i+=3) {
x = a[i]; y = a[i+1]; z = a[i+2];
r = r*x*y*z; //accumulation calc
}
for (; i<n; i++)
r *= a[i];
return r;
}
我不确定我应该如何在类似 RISC 的微操作中编写此代码至少进行几次迭代。
这是我目前拥有的:
load r0, (rcx,rax,8) //r0 is the loading register to store the data from the [array+i*8] calculation
mul r0,rax,rax //not sure if the name and order of the registers are correct I'm pretty lost :(
我真的很困惑应该为此使用哪些寄存器/内存位置以及如何编写类似 RISC 的微操作 shd。请发送帮助,感谢所有帮助。谢谢!
解决方案
推荐阅读
- java - 如何绕过 HTTP 错误 415 - 不支持的媒体类型
- javascript - 当数据是服务器渲染而不是 Vue 数据的一部分时,如何在 Vue.js 中创建即时搜索?
- javascript - 根据复选框单击和取消单击重置下拉菜单
- jquery - 如何通过单击并悬停在不同 div 的元素上来更改另一个 div 的元素
- json - 从 json 对象动态创建变量
- javascript - 确保功能范围
- python - 从 .jpg 图像转换回 2D numpy 数组
- azure-functions - 是否可以按随机时间表触发 azure 功能?
- python-3.x - 对类属性使用 side_effect 不起作用
- javascript - 如何在 React Redux 中获取状态的先前值