Program For 8051 Microcontroller to Unpack A Number

Problem

Write a program for 8051 microcontroller to unpack a number stored in memory location 30h. Store the lower nibble in 31h and higher nibble in 32h.

Algorithm

Step 1: Load the number in accumulator.

Step 2: Mask the lower nibble to unpack.

Step 3: Store the unmasked lower digit in internal memory location.

Step 4: Load the number in accumulator again.

Step 5: Mask the higher nibble to unpack.

Step 6: Rotate 4 times or SWAP.

Step 7: Store the unmasked higher digit in internal memory location.

Step 8: Stop.

Flowchart

flowchart for Program For 8051 Microcontroller to Unpack A Number, 8051 program to unpack a number

Program

MOV A, 30H ; Load the number from 30h in accumulator.

ANL A, #0FH ; AND content of accumulator with 0Fh to mask lower nibble.

MOV 31H, A ; Store the lower digit in 31h memory location.

MOV A, 30H ; Load the number in accumulator again.

ANL A, #0F0H ; AND content of accumulator with 0F0h to mask higher nibble.

SWAP A ; Exchange lower and higher nibble

MOV 32H, A ; Store the higher digit in 32h memory location.

LOOP: AJMP LOOP ; Stop.

Recent posts

Leave a Comment

Your email address will not be published. Required fields are marked *