01 Programming Part I

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

8085 Assembly Language Programming

1. Subtract two 8-bit number

[8000 H] = 51H

[8001 H] = 19H

Result = 51 H - 19 H -> [8002 H]

-> Source Program:

LDA 8001H ## [A] <- [8001] = 19H

MOV B, A ## [B] <- [A] = 19H

LDA 8000H ## [A] <- [8000] = 51H

SUB B ## [A] <- [A] - [B] =51H - 19H

## [A] <- 38 H

STA 8002 H ## [8002] <- [A] = 38H

HLT

2. Write a program to perform the followings:

I. Load the number 1B H in D register.

II. Load the number B5 H in B register.

III. Increment the content of B register by one.

IV. Decrement the content of D register by one.

V. Subtract the content of D register from the content of B


register

VI. Display the result at OUT Port 03H.

-> Solution:

MVI D, 1B H

MVI B, B5 H

INR B

DCR D

MOV A, B

SUB D

OUT 03 H

HLT

3. Find the content of A, B, D and flag register after the execution


of the program.

-> [A] = ? -> 9C H

[B] = ? -> B6 H

[D] = ? -> 1A H

[Flag] = ? -> 84 H

Solution:

[B] - [C] = B6 H - 1A H

B6 = 1011 0110 -> 1011 0110

1A = 0001 1010 -> 1110 0110

———————————-

[CY] =1 1001 1100 -> [A] = 9C H

Flag: [S] = 1

[Z] = 0

X = 0

[AC] = 0

X = 0

[P] = 1

X = 0

[CY] = 0

[Flag] = 1000 0100 = 84 H

Program Status Word [PSW] -> [A] [FLAG]

-> 9C84 H

Practice Question:
1. Multiplication of two 8 bit numbers.
[4000] = 05H
[4001] = 10H

Store the lower order result at 4002H and higher order result at 4003H
Program:

-> Solution:

0000H: LXI H, 4000H ## Initialize the first memory location to fetch data
0003H: MOV B, M ## Get the first number in B Register [B] <- 05H
0004H: INX H; ## HL = 4001H
0005H: MOV C, M ## Get the second number in C Register [C] <=10H
0006H: MVI A, 00H ## Initialize Accumulator content to 00H
0008H: MVI D, 00H ## D register will be used if the result is more than 8
LOOP: ADD B
JNC NEXT
INR D
NEXT: DCR C
JNZ LOOP
INX H ## HL = 4002
MOV M, A ## [4002] <- [A]
INX H ## HL = 4003
MOV M, D ## [4003] <- [D]
HLT
2. Division of two 8 bit numbers.
[2000] = FFH
[2001] = 05H

Store the remainder result at 2002H and quotient result at 2003H


ALGORITHM:
a. Start the program by loading HL Register Pair with the address of
memory.
b. Move the data to a register (Say B Register)
c. Get the second data and load into accumulator
d. Compare the two number to check the carry
e. If Carry, Store the result in the memory
f. If NOT Carry, subtract the two numbers
g. Increment the value of Register (Say C Register which we need to
initialize to 00H at beginning)
h. Check whether repeated subtraction is over and store the value of
remainder & quotient in memory location
i. Terminate the program.

PROGRAM:
MVI C, 00H ## For quotient
LXI H, 2000H
MOV B, M
INX H
MOV A, M
LOOP: CMP B
JC END
INR C
SUB B
JMP LOOP
END: INX H
MOV M, A
INX H
MOV M, C
HLT
4. Load the bit pattern 8AH in register D and 49H in register E.
Mask all bits except D3 from register D and E. If D3 has logic 08
in both the register then output the result at PORT1.
Solution:
1000 0000 = 80 H -> [D] [D] <- 8A H
0000 1000 = 08H [ANDed] [E] <- 49H
—————————————

0000 0000 = [A] -> [D] 0000 1000 = [A] -> [D]

0100 0010 = 42 H -> [E]


0000 1000 = 08H [ANDed]
—————————————

0000 0000 = [A] 0000 1000 = [A]

ANA D
[Z] SET or RESET
IF [Z] = SET,
OUT PORT1 {NO}
ELSE
OUT PORT1 <- [A]

5. Write an 8085 ASM language program using minimum number


of instructions to add the 16 bit number in BC, DE and HL
registers. Store the 16 bit result in DE registers.
6. Write an 8085 assembly language program, which checks the
number in memory location 8000H. If the number is an even
number, then put 01H in memory location 8100H, otherwise put
00H.
-> ORI 01H
[CY] = SET -> EVEN -> Result 01H

0000 0100 = 04H


0000 0001 -> [ORI with 01H]
————————
0000 0101 Result [Incorrect Method]

-> ANI 01H


[Z] = SET -> EVEN -> Result 01H

0000 0100
0000 0001 -> [ANI with 01H]
————————
0000 0000 Result
Zero Flag is SET when given number is EVEN
Zero Flag is RESET when given number is ODD
Program:
5000: LDA 8000H
5003: ANI 01H
5005: JZ EVEN
5008: MVI A, 00H
500A: JMP ODD
[EVEN]500D: MVI A, 01H
[ODD]500F: STA 8100H
5012: HLT
7. Write a program to count the data byte in memory that equal
to 33H starting at memory location 8000H through 800FH. Place
the count value in B register.

MVI C, OFH # store count in C register

MVI E, 00H

LXI H, 8000H

LOOP: MOV A, M # Initialize count of occurrence of 33h data

CPI 33H # Compare to check accumulator

JNZ NEXT # if no, jump to next address

INR E

JMP END # if yes, increase B resister count by 1

NEXT: INX H # increment of HL resister pair

DCR C # decrement count by 1 in C register

JNZ LOOP

END: MOV B,E

HLT

8. Write a program to sort given 10 numbers from memory
location 4100H in ascending order.
-> Program:
MVI E, 09H
LXI H, 4100H
START: MOV A, M
MVI C, 09H
LOOP: INX H
CMP M [A] < [M] -> CF SET
JC SWAP_SKIP [A] = [M] -> ZF SET
JZ SWAP_SKIP [A] > [M] -> CF & ZF RESET
## SWAPPING FUCNTION ##
MOV A, M
JMP LOOP
NEW MOV D, M
MOV M, A
DCX H
MOV M, D
INX H
JMP LOOP
END HLT
9. The block of data is stored in memory locations from 8000H to
8005H. Transfer the entire block of data to the locations 8080H to
8085H in reverse order.
Data: 22H, A5H, B2H, 99H, 7FH, 37H
Program:
LXI H, 8000H # Read data from memory
LXI D, 8085H # To store data in memory
MVI C, 06H # Use to count 6 memory location
LOOP: MOV A, M
STAX D
INX H
DCX D
DCR C
JNZ LOOP
HLT # Halt the program

10. OVERLAPPING MEMORY BLOCKS


The total FFH {256 Bytes} block of data is stored in memory
locations starting from 8000H. Transfer the entire block of data to
the locations 8050H onwards.
NOTE: Do not shift the block or part of the block anywhere else in the
memory.
Program: LXI H, 80FFH
LXI B, 814FH
MVI D, FFH
LOOP: MOV A,M
STAX B
DCX H
DCX B
DCR D
JNZ LOOP
HLT
11. Search the given byte in the list of 10 numbers stored in the
consecutive memory location and store the address of memory
location if search byte is found in the memory locations 8200H
and 8201H. Assume byte is in the C Register and starting address
of the list is 8000H. If byte is not found store 00 at 8200H and
8201H.

You might also like