of_bit_mirror: mov cx, dx test bx, bx jnz .large cmp dx, byte 64 jb .normal .large: xor bx, bx ; mirror count 64 or higher: xor dx, dx ; all 32 bits mirrored with (nonexistent) zero bits retn .normal: mov dx, word [hhvar] mov bx, word [hhvar+2] cmp cl, 1 jbe .ret ; mirror count one or zero, return input --> push si push di push cx mov di, -1 mov si, di .loopmask: shl di, 1 rcl si, 1 loop .loopmask ; create mask of bits not involved in mirroring and si, bx and di, dx ; get the uninvolved bits pop cx push si push di ; save them xor si, si xor di, di ; initialize mirrored register .loop: shr bx, 1 rcr dx, 1 ; shift out of original register's current LSB rcl di, 1 rcl si, 1 ; into other register's current LSB loop .loop pop dx pop bx ; restore uninvolved bits or bx, si or dx, di ; combine with mirrored bits pop di pop si .ret: retn