打印汇编变量C++

发布于 2025-02-03 11:06:00 字数 1078 浏览 2 评论 0原文

大家好! 我正在进行MASM课程,并且开始了这项练习。 我有一个简单的汇编代码:

.386
.model flat,c

.data
    quote   byte    "Machines do feel", 0
    message byte    SIZEOF quote DUP(0),0

.code

start proc
    
    mov esi,0
    mov ecx,SIZEOF quote

LP: 
    mov al,quote[esi]
    mov message[esi],al
    inc esi
    loop LP

    ret

start endp
    end

我想编写一个可以“ printf“变量”消息”的C ++程序。

我该怎么做?

我尝试添加:

mov eax, DWORD ptr [message]

在“ .ASM”文件中以存储消息变量的地址在功能返回的寄存器上,然后我编写了此程序来尝试打印值:

#include <iostream>

extern "C" char *start();

int main(){

    char *message = start();

    for(int i = 0x0; i < sizeof(message)/sizeof(char); i++){
        printf("%s", message[i]);
    }

    return 0x0;
}

但是当我尝试运行它时,我得到了错误:

Unhandled page fault on read access to 6863614D at address 0040162E (thread 0024), starting debugger...
0024:err:seh:start_debugger Couldn't start debugger L"winedbg --auto 32 68" (2)

您能解释一下我如何打印“ .ASM”文件“消息”变量的值? 还可以向我展示不同的方法吗?

非常感谢您,编码不错!

Hello All!
I'm doing a MASM course and I got into this exercise.
I have this simple assembly code:

.386
.model flat,c

.data
    quote   byte    "Machines do feel", 0
    message byte    SIZEOF quote DUP(0),0

.code

start proc
    
    mov esi,0
    mov ecx,SIZEOF quote

LP: 
    mov al,quote[esi]
    mov message[esi],al
    inc esi
    loop LP

    ret

start endp
    end

And I want to write a C++ program that can "printf" the variable "message".

How can I do this?

I tryed to add:

mov eax, DWORD ptr [message]

To the ".asm" file to store the address of the message variable on the register returned by the function and then I wrote this program to try to printf the values:

#include <iostream>

extern "C" char *start();

int main(){

    char *message = start();

    for(int i = 0x0; i < sizeof(message)/sizeof(char); i++){
        printf("%s", message[i]);
    }

    return 0x0;
}

But when I try to run it I get the error:

Unhandled page fault on read access to 6863614D at address 0040162E (thread 0024), starting debugger...
0024:err:seh:start_debugger Couldn't start debugger L"winedbg --auto 32 68" (2)

Can you please explain me how can I print the values of the ".asm" file "message" variable?
And can also show me different methods to do this?

Thank you so much, have a nice coding!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文