例如,用户输入01010101
,程序将其拆分为01 01 01 01
,以读取为分配给特定常量的单独值。
我知道需要从32位寄存器中移出/拉出值并进行屏蔽,但我不知道该怎么做。
答案 0 :(得分:0)
使用AND
屏蔽掉位,SHR
将位移位到右侧
MOV dl, 0b01010101
AND dl, 0b00000001 ;dl now equals 1
MOV al, 0b01010101
AND al, 0b00000100 ;al now equals 0b00000100 = 4
SHR al, 2 ;al now equals 1
答案 1 :(得分:0)
您可以使用位运算符“AND”来执行此操作。
现在假设您将原始“01011100”存储在寄存器AH中,并且您希望将其分成“01”,“01”,“11”,“00”并将它们分别存储在BH,BL,CH,CL中
你可以这样做:
MOV BH AH ;now the BH is 01011100 ,just like AH
AND BH 0B11000000 ;since "a AND b" equals 1 only when both a and b equal 1 ,so the first two bit of AH will be the same as that of BH, and the other six bit will be 0 because one of the operand is 0 . In this way you can split it.
你可以用同样的方式完成剩下的工作:
MOV BL AH ;now the BL is 01011100 ,just like AH
AND BL 0B00110000 ;now BL is 00010000
MOV CH AH ;now the CH is 01011100 ,just like AH
AND CH 0B00001100 ;now the CH is 00001100
MOV CL AH ;now the CL is 01011100 ,just like AH
AND CL 0B00000011 ;now the DH is 00000000