MoV Al, 3ah; raw data
MoV cl, 4; I = 4
CMP Cl, 6; I <= 6
JG exit; exit if the value is greater
MoV BL, 3; mask with 0011 = 3
Shl bl, Cl; locate the desired mask based on the CL value to obtain the required mask.
And Al, BL; logically intercept the value of 1
Not BL;
And [mem], BL; clear the bits except I + 1
Or [mem], Al; and write I + 1 bit to Mem
This is the csdn compilation forum.Delphiguy ()Algorithm
My algorithm is
MoV Al, 3ah; raw data
MoV BL, 4; I = 4
Cmp bl, 6
JG exit
Cmp bl, 0
JZ num_i0;
Cmp bl, 1
JZ num_i1
Cmp bl, 2
JZ num_i2
Cmp bl, 3
JZ num_i3
Cmp bl, 4
JZ num_i4
Cmp bl, 5
JZ num_i5
Cmp bl, 6
JZ num_i6
JMP numout
Num_i0:
And Al, 03 h
JMP numout
Num_i1:
And Al, 06 h
JMP numout
Num_i2:
And Al, 0ch
JMP numout
Num_i3:
And Al, 18 h
JMP numout
Num_i4:
And Al, 30 h
JMP numout
Num_i5:
And Al, 60 h
JMP numout
Num_i6:
And Al, 0c0h
Numout: mov [mem], Al
The calculated mask of the algorithm does not have the calculated relative mask.