Using FASM I'm trying to shift dword with a SHR
instruction which should shift bits to right appending zeroes. Here is the code:
format ELF executable 3
entry start
segment readable executable
start:
cmp byte [counter],0
jz fin
mov eax,4
mov ebx,1
mov ecx,some
mov edx,4
int 0x80 ; write 4 bytes
mov eax,4
mov ebx,1
mov ecx,splitter
mov edx,1
int 0x80 ; write a split byte (0x42)
shr dword [some],4
dec byte [counter]
jmp start
fin:
mov eax,1
xor ebx,ebx
int 0x80
segment readable writeable
some db 0x89,0xAB,0xCD,0xEF
splitter db 0x42
counter db 10
I expected to get something like that: 0x89ABCDEF -> 0x089ABCDE -> 0x0089ABCD -> 0x00089ABC -> 0x000089AB -> 0x0000089A -> 0x00000089 -> 0x00000008 -> 0x00000000
But I get this instead: 0x89ABCDEF -> 0xB8DAFC0E -> 0xABCDEF00 -> 0xDAFC0E00 -> 0xCDEF0000 -> 0xFC0E0000 -> 0xEF000000 -> 0x0E000000 -> 0x00000000
What am I doing wrong?
PS This values were gotten by opening the file in which I redirect the output in hex editor. (It's not the output itself)
Your numbers are stored little endian. http://en.wikipedia.org/wiki/Endianness
To clarify, 0x89ABCDEF is stored as 0xEFCDAB89, so right shift produces 0x0EFCDAB8, which is the bytes you see, in reverse order
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.