Modifying a character array, the modified part sho

2019-08-05 15:34发布

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

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 

And my C++ code:

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

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".

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'?

1条回答
男人必须洒脱
2楼-- · 2019-08-05 16:13

You can use:

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

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

mov   ebx,'Four'
movbe [rax],ebx
查看更多
登录 后发表回答