How to mirror bytes without using other registers?

Say I have this byte in AL: 01100001 After applying the mirror function, I want the byte to be 10000110.

All the ideas that I came up with, I should use other registers, but I'm curious if there is a way to reflect a byte without using any other register?

+4
source share
1 answer

Option "storage by immediate code":

mirror_bits:
    ; handle bits 0 and 7
    TEST    al,0x81
    JPE     bits07same
    XOR     al,0x81
bits07same:
    ; handle bits 1 and 6
    TEST    al,0x42
    JPE     bits16same
    XOR     al,0x42
bits16same:
    ; handle bits 2 and 5
    TEST    al,0x24
    JPE     bits25same
    XOR     al,0x24
bits25same:
    ; handle bits 3 and 4
    TEST    al,0x18
    JPE     bits34same
    XOR     al,0x18
bits34same:
    RET

EDIT: About my comment on the question and the general answer, is there any way.

. 8- 8- , - " ", , ( " ", ).

, al ( rip eflags, 99% ), "" .

turing-, /, , = > QED.

"" , swap-.

-, .. test al,0x01 jz bit_0_clear ; else bit_0_set branch follows ( /reset , , )... ( , ), .

, ", ", " ". , value = . "" , , xor .

, , , , (, , " " ), test + jpe) , .

, , , :))) (-, - , , , , /, x86 ++. , , ).

+9

Source: https://habr.com/ru/post/1669798/


All Articles