I am given a question in which I have to write a program such that the last bit of the offset address of the first segment becomes the first bit of the offset address of the second segment. For example if I am given ABCDH then the offset address of the second address should be DCBAH. I am just focusing on the swapping of the offset address and am ignoring the base address for now:
MOV AX,ABCDH
ROR AX,16 ; this will rotate the value of AX 16 times
Now we have CDABH. Now I want to swap the position of D and C. I am stuck at this point. Will I use SAR command?
The
AXregister holds 16 bits. When you rotate these 16 bits 16 times you get the same value that you started with!So you want to go from ABCDh to DCBAh.
The
AXregister is subdivided in 2 halves. The low half is namedALand the high half is namedAH. You can operate on these halves independently.The instruction
mov ax, 0ABCDhputs the value 0ABh inAHand puts the value 0CDh inAL.Now finally
AX=0DCBAh.All of the above deals with 4-bit quantities. We call these nibbles.
You can write your hexadecimal value 0ABCDh using the binary representation like 1010101111001101b. You can see that there are 16 bits.
Aligned groups of bits have special names: