_asm 函数,打印“Pow (x) = x^2”

问题描述

我在 VS (C++) 中创建了这段代码

#include<iostream>
using namespace std;
static short arr[10];

void powers() {
    _asm {
        mov ecx,0;
        mov dx,0;
        for:
        mov ax,cx;
        inc ax;
        mul ax;
        mov[arr + 2 * ecx],ax;
        inc ecx;
        cmp ecx,10;
        jl for;
    }
}

现在我想创建另一个打印“Pow (x) = x^2”的函数,我卡在这里

void print_power(unsigned short x) {
   const char* f = "Pow(%d) = %d \n";

    _asm {
             call powers
             push f
             add esp,4
         }
}

当我从“print_power”调用我的“powers”函数时 -> 我的 arr[10] 被 1 到 10 的 ^2 填充 (arr[0] = 1,arr[1] = 4,arr[2] = 9,arr[3] = 16,arr[4] = 25 .....) (我认为)

我希望当我从 main() 调用我的 print_power(x) 函数时,例如 print_power(8) -> 像这样从我的 arr 打印第 8 个元素:“Pow (8) = 81”。

先谢谢你,如果我有一些错误,我也想道歉。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)