Reputation: 119
I need write assebler code for write 3 letter's word in minimal cell memory this picture, that illustrated what I need:
I'm starting writing code:
mov eax, dword ptr str[0]
bsr cl, eax
inc cl
shl eax, cl
push eax
//
mov eax, dword ptr str[1]
pop ebx
or eax, ebx
push eax // unshifted
//
mov eax, dword ptr str[2]
bsr cl, eax
inc cl
pop ebx
shl ebx, cl
or eax, ebx
mov result, ebx
But I get -934608896 (00110111101101010000000000000000 after negate)
instead of 1304526 (0100111110011111001110)
Upvotes: 1
Views: 277
Reputation: 39166
The result is in EAX
after the final or eax, ebx
.
Why do you put EBX
in result? Is this the wrong value that you inspect?
This is a code that inserts 3 bitpatterns in the same register:
movzx eax, byte ptr str[0]
movzx ebx, byte ptr str[1]
bsr ecx, ebx
inc ecx
shl eax, cl
or eax, ebx
movzx ebx, byte ptr str[2]
bsr ecx, ebx
inc ecx
shl eax, cl
or eax, ebx
mov result, eax
Upvotes: 5