【发布时间】:2009-11-07 22:14:56
【问题描述】:
我需要将方法中的注释翻译成汇编程序。我有一个大概的想法,但不能。
有人可以帮帮我吗?适用于 Intel x32 架构:
int
secuencia ( int n, EXPRESION * * o )
{
int a, i;
//--- Translate from here ...
for ( i = 0; i < n; i++ ){
a = evaluarExpresion( *o );
o++;
}
return a ;
//--- ... until here.
}
翻译后的代码必须在 __asm 中:
__asm {
translated code
}
谢谢,
最终更新:
这是最终版本,正在运行并已发表评论,感谢大家的帮助:)
int
secuencia ( int n, EXPRESION * * o )
{
int a = 0, i;
__asm
{
mov dword ptr [i],0 ; int i = 0
jmp salto1
ciclo1:
mov eax,dword ptr [i]
add eax,1 ; increment in 1 the value of i
mov dword ptr [i],eax ; i++
salto1:
mov eax,dword ptr [i]
cmp eax,dword ptr [n] ; Compare i and n
jge final ; If is greater goes to 'final'
mov eax,dword ptr [o]
mov ecx,dword ptr [eax] ; Recover * o (its value)
push ecx ; Make push of * o (At the stack, its value)
call evaluarExpresion ; call evaluarExpresion( * o )
add esp,4 ; Recover memory from the stack (4KB corresponding to the * o pointer)
mov dword ptr [a],eax ; Save the result of evaluarExpresion as the value of a
mov eax,dword ptr [o] ; extract the pointer to o
add eax,4 ; increment the pointer by a factor of 4 (next of the actual pointed by *o)
mov dword ptr [o],eax ; o++
jmp ciclo1 ; repeat
final: ; for's final
mov eax,dword ptr [a] ; return a - it save the return value at the eax registry (by convention this is where the result must be stored)
}
}
【问题讨论】:
-
这是作业吗?如果是的话,不要指望有人会给你答案。展示你目前拥有的东西。
-
为什么需要这样做?编译器完全有能力为您做到这一点。编译器输出不够好是不是有什么原因?
-
找
gcc为你做作业比找一个编程问答网站要快。试试man gcc。 -
Professional Assembly 的自我作业......但我被卡住了!
-
为了那些不会说西班牙语的人的利益,您会考虑将 cmets 翻译成英文吗?我会自己做,除非这似乎不是我编辑帖子的正当理由,礼仪方面