修改字符数组,修改的部分显示出来向后 [英] Modifying a character array, the modified part shows up backwards

查看:170
本文介绍了修改字符数组,修改的部分显示出来向后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习汇编,我试图修改一个字符数组。

I have just started learning assembly, and I am trying to modify a character array.

这是我的组装code:

This is my assembly code:

.data
data byte 'Five', 0
.code 
    Asm proc
        lea rax, data
        mov dword ptr[rax], 'Four'
        ret
    Asm endp
end 

和我的C ++ code:

And my C++ code:

#include <stdio.h>
#include <conio.h>
// external function
extern "C" char* Asm();
// main function
int main()
{
    printf(Asm());
    _getch();
}

当我注释掉 MOV DWORD PTR [RAX],四,其结果是在控制台打印:十一五的。但是,上述code取消注释,结果是ruoF的,而不是什么,我希望它是,这显然是的的。

When I comment out mov dword ptr[rax], 'Four', the result is that the console prints: "Five". But, with the above code uncommented, the result is "ruoF", instead of what I expected it to be, which is obviously "Four".

这是怎么回事?我怎样才能获得文本的正确方向输出,无需做一些廉价的解决方法是这样的:<?code> MOV DWORD PTR [RAX],ruoF

Why is this happening? How can I get the text to output in the correct direction without having to do some cheap workaround like this: mov dword ptr[rax], 'ruoF'?

推荐答案

您可以使用:

mov   ebx,'Four'
bswap ebx
mov   [rax],ebx

或者,在支持 movbe 英特尔凌动处理器(可与确认CPUID ):

Or, on Intel Atom processors that support movbe (can be confirmed with cpuid):

mov   ebx,'Four'
movbe [rax],ebx

这篇关于修改字符数组,修改的部分显示出来向后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆