内联汇编语言 [英] Inline assembly language
问题描述
我做的64位移民,我需要口内联汇编code为他code
I am doing 64 bit migration and i need to port inline assembly code to cpp Here is he code
void ExternalFunctionCall::callFunction(ArgType resultType, void* resultBuffer)
{
// I386
// just copy the args buffer to the stack (it's already layed out correctly)
int* begin = m_argsBegin;
int* ptr = m_argsEnd;
while (ptr > begin) {
int val = *(--ptr);
__asm push val
}
}
我要迁移此__asm推到VAL CPP。这个函数被调用四次,每次调用我们得到m_argsBegin和m_argsEnd(包括m_argsBegin和m_argsEnd是动态数组)的不同值。
这个while循环执行4次,这种callFunction功能的每次呼叫。所以,在4×4总量= 16的值存储在一个连续存储位置这是什么推__asm VAL做我猜。我需要用C实现此++。我试图百般(堆栈,数组,Lnked名单,甚至排队分离到一个单独的asm文件这一点,但没有一个是工作)
谁能帮助?
I want to migrate this __asm push val to cpp. This function is called four times and for every call we get different values of m_argsBegin and m_argsEnd(both m_argsBegin and m_argsEnd are dynamic arrays). This while loop executes 4 times for every call of this "callFunction" function. So, in total 4x4 = 16 values are to be stored in a "CONTINUOUS memory location" this is what "__asm push val" does i guess. I need to implement this in c++ . I tried every possible way (stack, array, Lnked list, Queue even separated this into a separate asm file but none are working) Can anyone help?
我分开这个内联汇编函数转换成一个单独的程序文件。这里是code:
I separated this inline assembly function into a separate assembly file . Here is the code:
.386
.model c,flat
public callFunction_asm
CSEG segment public 'CODE'
callFunction_asm PROC
push ebp
mov ebp, esp
mov ecx, [ebp+8] ;val
push dword ptr [ecx]
mov esp, ebp
pop ebp
RETN
callFunction_asm ENDP
CSEG ends
END
其中callFunction_asm是一个外部函数,我宣布它为:
where callFunction_asm is an extern function , I declared it as:
为externC
无效callFunction_asm(INT VAL);
extern "C" void callFunction_asm(int val);
和我调用这个函数为:
while (ptr > begin) {
int val = *(--ptr);
callFunction_asm(val); //possible replacement
}
但即使这是行不通的,谁能告诉我该怎么错在何处。我是新装配的编码。
but even this is not working, can anyone tell where am I going wrong. I am new to assembly coding.
推荐答案
推
把堆栈上的操作,以及递减堆栈指针。
push
puts its operand on the stack, as well as decrementing the stack pointer.
如果你看了堆栈指针加1( 1(SP $)
),你应该看到的值(但如果你想回来,你通常会使用弹出
)。
If you looked at the stack pointer plus 1 (1($sp)
), you should see the value (but if you wanted it back, you'd typically use pop
).
这篇关于内联汇编语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!