【发布时间】:2016-11-06 13:33:15
【问题描述】:
我想开始将一个小的 nasm 项目 {synth.asm, synth_core.nh} 转换为 c,以了解更多关于那个小软合成器的信息。
问题是我的 asm 知识非常生疏,我想知道从哪里开始。我想也许一个反编译器可以帮助我,但我还没有找到任何能够将这些简单的 nasm 列表转换为 c 的开源代码。
另一种选择是手动转换 asm->c 但我很难理解最简单的功能之一:(
即:
;distortion_machine
;---------------------------
;float a
;float b
;---------------------------
;ebp: distort definition
;edi: stackptr
;ecx: length
section distcode code align=1
distortion_machine:
pusha
add ecx, ecx
.sampleloop:
fld dword [edi]
fld dword [ebp+0]
fpatan
fmul dword [ebp+4]
fstp dword [edi]
scasd
loop .sampleloop
popa
add esi, byte 8
ret
失败的尝试:
void distortion_machine(???) { // pusha; saving all registers
int ecx = ecx+ecx; // add ecx, ecx; this doesn't make sense
while(???) { // .sampleloop; what's the condition?
float a = [edi]; // fld dword [edi]; docs says edi is stackptr, what's the meaning?
float b = [ebp+0]; // fld dword [ebp+0]; docs says ebp is distort definition, is that an input parameter?
float c = atan(a,b); // fpatan;
float d = c*[ebp+4]; // fmul dword [ebp+4];
// scasd; what's doing this instruction?
}
return ???;
// popa; restoring all registers
// add esi, byte 8;
}
我猜上面的 nasm 列表是一个非常简单的循环,会扭曲一个简单的音频缓冲区,但我不明白哪些是输入,哪些是输出,我什至不了解循环条件 :')
对于上述例程以及如何在这个小教育项目中取得进展的任何帮助,我们将不胜感激。
【问题讨论】:
-
add ecx, ecx仅表示将 ecx 乘以 2,这在函数正在运行时有意义,例如short样本(即 2 个字节),长度以样本表示。 -
请在帖子中只问一个问题。我假设问题是“如何将 nasm 程序集转换为 C”。 “需要关于如何完成
的建议”类型的问题或“这段代码做什么”在这里是题外话。 -
@RadLexus 是的,确实,我的标题有点误导,现在正在更改
-
你将很难转换这个,因为它针对大小进行了优化,所以例如这个例程做了一些没有调用它的代码上下文就没有意义的事情。比如结尾
add esi,8,而在cmets中甚至没有提到esi,结果会影响调用者。对于任何指令(scasd),请使用 google:“x86 指令 ”(有趣的是,第一个链接指向错误的描述,还包括 ESI 修改)。这里scasd用作edi += 4;的缩写形式。 -
关于初始大小 = size*2 .. 由于代码使用 dword 作为示例数据,我宁愿猜测它是“立体声”调整,而不是短与字节示例? (因为我认为样本是 32b 浮点数,而不是短裤或字节).. 但我没有检查主要代码,所以我只是猜测。