我需要將該方法中評論的內容翻譯成彙編程序。我有一個大致的想法,但不能。將FOR轉換爲彙編程序
任何人都可以幫助我嗎?是英特爾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)
}
}
這是功課嗎?如果是這樣,不要指望有人給你答案。顯示你到目前爲止。 – 2009-11-07 22:16:39
爲什麼你需要這樣做?編譯器完全可以爲你做到這一點。編譯器輸出有沒有足夠的理由? – 2009-11-07 22:18:42
讓'gcc'爲你做功課要比問一個編程問答網站要快。試試'man gcc'。 – 2009-11-07 22:22:02