``````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
...should be an eight byte solution (no assembler here).

Sorry, abc123, but that solution does not work.

``````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