Programs on Logical Instructions in 8085 Microprocessor

Following are some of the programs on Logical Instructions in 8085 Microprocessor. You need to learn the instruction set of 8085 in detail before programming.

One program can be performed in multiple ways. Here they are mentioned as Program 1, Program 2 …

Programs Based On Logical Instructions In 8085

1’s Complement of a Number

Find the 1’s complement of a number stored at memory location 1050H and store the complemented number at memory location 1051H.

Program:

LDA 1050H ; Copy the number from memory location 1050H into accumulator.

CMA ; Complement number.

STA 1051H ; Store the result to memory location 1051H

HLT ; Terminate program execution.

Sample Example:

(1050H) = 97H

97H in binary 1001 0111 B

Result = (1051H) = 68H

2’s Complement of a Number

Find the 2’s complement of a number stored at memory location 1050H and store the complemented number at memory location 1051H.

Program 1:

LDA 1050H ; Copy the number from memory location 1050H into accumulator

CMA ; Complement number

ADI 01H ; Add one in the number

STA 1051H ; Store the result

HLT ; Terminate program execution

Program 2:

LDA 1050H ; Copy the number from memory location 1050H into accumulator

CMA ; Complement number

INR A ; Increment the contents of accumulator by 1

STA 1051H ; Store the result

HLT ; Terminate program execution

Sample Example:

(1050H) = 97H

97H in binary 1001 0111 B

Result = (1051H) = 69H

Shifting of Data in 8085

Write a program to shift 8-bit data four bits right. Assume data is in register C.

Program:

MOV A, C ; Copy the number from C to accumulator

RRC ; Rotate contents of accumulator right by 1 bit

RRC

RRC

RRC

MOV C, A ; Store the result in register C

HLT ; Terminate program execution.

Sample Example:

(C) = 6DH

Result = (C) = D6H

Write a program to shift a 16-bit data, 1 bit right. Assume that data is in BC register pair.

MOV A, B ; Copy higher byte from B to accumulator

RAR ; rotate right

MOV B, A ; save the result 1 in register B

MOV A, C ; Copy lower byte from C to accumulator

RAR ; rotate right

MOV C, A ; save the result 2 in register B

HLT ; Terminate program execution.

Sample Example:

(BC) = 2827H

Result 1: (B)=28 becomes (B)=14

Result 2: (C)=27 becomes (B)=13

Result = (BC) =1413H

Pack the Unpacked BCD Numbers in 8085

Pack the two unpacked BCD numbers stored in memory locations 4000H and 4001H and store result in memory location 4300H. Assume the least significant digit is stored at 4000H.

Program:

LDA 4001H ; Get the Most significant BCD digit

RLC ; Rotate the contents of accumulator to left

RLC

RLC

RLC ; Adjust the position of the second digit (57 is changed to 75)

ANI F0H ; Make least significant BCD digit zero (75 changed to 70)

MOV C, A ; store the partial result

LDA 4000H ; Get the lower BCD digit.

ADD C ; Add lower BCD digit

STA 4002H ; Store the result

HLT ; Terminate program execution.

Sample Example:

(4000H) = 05

(4001H) = 02

Result = (4002H) = 25

Unpacking of BCD Numbers in 8085

Two-digit BCD number is stored in memory location 5000H. Unpack the BCD number and store the two digits in memory locations 5001H and 5002H such that memory location 5002H will have lower BCD digit.

Program:

LDA 5000H ; Get the packed BCD number

ANI F0H ; Mask lower nibble (57 changed to 50)

RRC ; Rotate right accumulator

RRC

RRC

RRC ; Adjust higher BCD digit as a lower digit (50 changed to 05)

STA 5001H ; Store the result (higher BCD digit)

LDA 5000H ; Get the original BCD number

ANI 0FH ; Mask higher nibble (57 changed to 07)

STA 5002H ; Store the result (lower BCD digit)

HLT ; Terminate program execution

Sample Example:

(5000H) = 57

Result = (5001H) = 05 and (5002H) = 07

Alter the Flag register in 8085

Write a set of instructions to alter the contents of flag register in 8085.

Program:

PUSH PSW ; Save flags on stack

POP H ; Retrieve flags in register L

MOV A, L ; Copy flags in accumulator

CMA ; Complement accumulator

MOV L, A ; Copy accumulator in register L

PUSH H ; Save on stack

POP PSW ; Back to flag register

HLT ; Terminate program execution.

Sample Example:

PSW = 02H

Result = PSW = D6H

Recent posts

Leave a Comment

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