Reputation: 986
Is there a tutorial somewhere which explains all the intricacies of boolean logic operations which are possible in assembly language. For example, I have no idea what the following assembly code block does:
mov [ebp-8h], 31982853h
mov eax, [ebp+Ch]
shl eax, 8
mov ecx, [ebp+Ch]
shr ecx, 8
or eax, ecx
I understand what the shl, shr and or instructions do but have no idea about their combined result. Can anybody direct me to a tutorial which thoroughly explains boolean logic operations in assembly?
Thanks.
Upvotes: 0
Views: 2996
Reputation: 62106
If the variable at [ebp+Ch]
holds a 16-bit value (i.e. only the 16 least significant bits can be non-zero), then this piece of code efectively swaps its bytes (bits 0 through 7 with bits 8 through 15). However, the result in eax
after or eax, ecx
has to be masked (and
'ed) with 0FFFFh, unless the code that follows uses ax
instead of eax
.
Upvotes: 1
Reputation: 49893
Annotated code:
mov eax, [ebp+Ch] ; grab our 32-bit value
shl eax, 8 ; shift it left 8 bits, so the top 8 bits are shifted out
; and the bottom 8 bits are filled w/ 0
mov ecx, [ebp+Ch] ; grab our 32-bit value again
shr ecx, 8 ; shift this copy right 8 bits, so the bottom 8 bits are
; shifted out and the top 8 bits are filled w/ 0
or eax, ecx ; perform A = A or C for each set of same-aligned bits in
; EAX (A) and ECX (C)
So if the original value was ABCD (each letter being an 8-bit byte), then before the or is performed, EAX would have BCD0 and ECX would have 0ABC.
Upvotes: 3