In this program we will see how to lower and upper nibbles are masked in 8085.
Write 8085 Assembly language program to mask the upper and lower nibble of an 8-bit number. The number is stored at location 8000H. Lower and Upper nibbles will be stored at location 8001H and 8002H.
The masking is basically ANDing two numbers. When we want to mask the upper nibble of an 8-bit number say 2D (0010 1101), then we will AND with 0F (0000 1111), so we will get 0D (0000 1101). By masking with F0 (1111 0000), the result will be 20 (0010 0000). Now by shifting the upper nibble, we will get 02 (0000 0010).
|F000||21, 00, 80|| ||LXI H,8000H||Initialize HL pair to get number|
|F003||7E|| ||MOV A,M||Take the number from memory to accumulator|
|F004||47|| ||MOV B,A||Store A to B|
|F005||E6, 0F|| ||ANI 0FH||Get the lower nibble by masking upper one.|
|F007||23|| ||INX H||Point to next location|
|F008||77|| ||MOV M,A||Store Lower nibble to memory|
|F009||78|| ||MOV A,B||Take the number from B to A|
|F00A||E6, F0|| ||ANI F0H||Take the upper nibble by masking lower one.|
|F00C||0F|| ||RRC||Rotate acc four times|
|F00D||0F|| ||RRC|| |
|F00E||0F|| ||RRC|| |
|F00F||0F|| ||RRC|| |
|F010||23|| ||INX H||Point to next location|
|F011||77|| ||MOV M,A||Store the upper nibble to memory|
|F012||76|| ||HLT||Terminate the program|