8085 program to show masking of lower and higher nibbles of 8-bit number


In this program we will see how to lower and upper nibbles are masked in 8085.

Problem Statement

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.

Discussion

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).

Input

Address
Data


8000
AB

Flow Diagram

 

Program

Address
HEX Codes
Labels
Mnemonics
Comments
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

Output

Address
Data
8001
0D
8002
02


Updated on: 30-Jul-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements