Assembly language - Why are characters stored in register as little endian?

岁酱吖の 提交于 2020-01-06 05:30:18

问题


I am new to assembly language. I am trying the below code and as you can see the below code.

bits 64
global _start
section .text
_start:

        mov rcx, 1234567890
        xor rcx, rcx
        mov rcx, 'wxyz'

        mov rax, 60
        mov rdi, 0 
        syscall

I would like to know why digits are stored as Big endian in register and characters are stored in registers as Little-endian

Below screenshots are from the debugger.

I thought only in the memory, data is stored as Little endian. But I don't understand why the characters are stored as Little endian in the register. Kindly let me know.

Thank you.


回答1:


Speaking about CPU registers' endianness doesn't make much sense because addresses are not assigned to the particular bytes that made up the registers, i.e.: there is no byte order to be considered.

That is, for example al is the lowest byte of rax, and ah the second lowest. With this in mind, what is the address of al and ah? Is ah's address higher or lower than al address? They don't have (memory) addresses associated, and therefore there is no byte order at all to consider.

What is relevant is how those bytes are stored into memory (e.g.: by means of a mov instruction). The endianness determines that. For a little-endian machine, the lowest byte of the register will be placed at the lowest address of the destination operand, for a big-endian machine at the highest address. The endianness is similarly relevant for loading a memory operand into a register.

In short, in order to speak about endianness there must be a kind of mapping between bytes' significance and the highness of their corresponding addresses.



来源:https://stackoverflow.com/questions/48645360/assembly-language-why-are-characters-stored-in-register-as-little-endian

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!