I would like to ask about process of put instructions into registers. For example: we want to overwrite count '50' into EBX (in ASCII '50' is count '2'). EBX consists of 32 bits. When we put '50' into it, it will be arranged as binary represent, yes? (0000000 | 00000000 | 00000000 | 00110010). Have a right? What happens with bits, when we place a string into register?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
- Null-terminated string, opening file for reading
EAX
holds 32 bits which Intel calls "integer". The programmer - and sometimes the assembler - decides how to interpret these bits. If you loadEAX
with the number 50 (not the string '50')the assembler decides to generate a machine instruction that loads the 50 in a manner, that you can read it as number 50 in a binary system:
Try out, what the assembler does if you feed it with a string:
Output:
NASM stored it backwards in
EAX
. The ASCII of leftmost character is stored in the rightmost byte of EAX, the second-to-last character is to be found in the second byte, and so on. Better to see when those bytes are printed as ASCII characters:Output:
Both programs above show
EAX
in big endian order. This is the order you are familiar with looking at decimal numbers. The most significant digit is left and the least significant digit is right. However,EAX
would be saved in memory or disk in little endian order, starting the sequence from the right with the least significant byte. Looking at the memory with a disassembler or debugger you would see 'F','o','u','r' as well as you had defined it in a.data
section withdb 'Four'
. Therefore you'll get no difference when you load a register with a string, save it to memory and call the write routine of the kernel:Output:
Please note: This behavior is made by the NASM programmers. Other assemblers might have a different behavior.