mov	eax, edx	

shl eax, 3 ; eax = XYabc 123000
xor edx, eax ; edx = XY 123123
shr eax, 6 ; eax = 0XYabc
xor edx, eax ; edx = XY 123abc


? (i am not sure how to find out the size...)
edit: shl and shr were around the wrong way
Posted on 2003-08-14 21:48:51 by abc123

In this case have to be Md always 11, so that swapping bit fields is much more simple...
In that case,

byte 0xD4, 1000y

xchg ah, al
byte 0xD5, 1000y
add al, 11000000y - 11000y
...should be an eight byte solution (no assembler here).

Sorry, abc123, but that solution does not work.

Please, see these example values:
mov	eax, edx

[COLOR=blue]; EDX = 00011101010y[/COLOR]
shl eax, 3 ; eax = XYabc 123000
[COLOR=blue]; EAX = 11101010000y[/COLOR]
xor edx, eax ; edx = XY 123123
[COLOR=blue]; EDX = 11110111010y[/COLOR]
shr eax, 6 ; eax = 0XYabc
xor edx, eax ; edx = XY 123abc
[COLOR=red]; EDX = 11110100111y (bad result)[/COLOR]
[COLOR=green]; EDX = 11010101y (expected result)[/COLOR]
Posted on 2003-08-15 16:20:09 by bitRAKE
Hi,

BitRake,

You can save another byte :) :




; input al = ?? xyz abc can be written n = 64A + 8B + C
; output = ?? abc xyz can be written n' = 64A + 8C + B = n - 7(B-C)

mov dl, al ; dl = n
db 0D4h, 64 ; ah = 64A, al = 8B + C
db 0D4h, 8 ; ah = B, al = C
sub ah, al ; ah = B - C
mov al, dl ; al = 64A + 8B + C
db 0D5h, -7 ; al = n - 7*(B-C)
Posted on 2003-08-16 08:53:24 by Dr. Manhattan
Dr. Manhattan, very cleaver solution!
Posted on 2003-08-16 12:11:31 by bitRAKE
Greetings bitRAKE and Dr.Manhattan and everyone, I managed to trim two more bytes:

;---------------------------
Input: al = 64A + 8B + C
Output: al = 64A + 8C + B
;---------------------------
mov dl, 8 ; al = 64A + 8B + C
db 0D4h, 64 ; ah = A, al = 8B + C, ax = 256A + 8B + C
shl ah, 1 ; ax = 512A + 8B + C
div dl ; ah = C, al = 64A + B
db 0D5h, 8 ; al = 64A + 8C + B
;---------------------------
Posted on 2003-08-17 19:14:22 by Poimander
Why do you use db? Isn't it possible to encode with instructions?
Posted on 2003-08-17 19:39:04 by comrade
Hello comrade,
The generalized 'D4 ib' and 'D5 ib' versions of the AAM and AAD instructions don't have mnemonics according to the Intel x86 Processor Instruction Set Reference..
Posted on 2003-08-17 19:55:53 by Poimander

Why do you use db? Isn't it possible to encode with instructions?
IIRC, they work with FASM/NASM, but not MASM.

Poimander, I just knew it was too big! :grin:
Wonder how small it can be?
Posted on 2003-08-18 01:00:37 by bitRAKE
Nice ! :)
Posted on 2003-08-18 14:00:23 by Dr. Manhattan
The Svin certainly formulates interesting problems.
Posted on 2003-08-18 21:13:46 by Poimander