微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决_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 举报,一经查实,本站将立刻删除。