Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

190170107144 PRACTICAL:7

a. Write a Program to Find GCD Of Two Numbers Using 8085.

Program:

# ORG 2000H
MVI A,09 // Load first no. in reg.A
MVI B,07 // Load second No. in reg.B
CMP B // Compare B to A
JZ down // True if A=B
JNC shift // True if A>B
MOV C,A // A → C
MOV A,B // A ← B
MOV B,C // C← B
shift:SUB B // A-B → A
CMP B // Compare B to A
JZ move // True if A=B
JNC shift // True if A>B
MOV C,A // A ← C
MOV A,B // A ← B
MOV B,C // C → A
JMP shift // Unconditional Jump
move:MOV A,B // B → A
down:STA F200 // A → [address]
RST 1 // Terminate

Input:

A-09 H, B-07 H

Output:

A- 01 H, F200-01 H

VGEC(CE) 1 MPI
190170107144 PRACTICAL:7

b. Write a Program to Add ‘N’ Two Digit BCD Numbers Using 8085.

Program:

# ORG 2000H
LXI H,F100 // HL &8592; F100
MOV C,M // C &8592;[HL]
MVI D,00 // Clear reg.D
INX H // HL+1 &8594; HL
DCR C // C-1 &8594; C
MOV A,M // M &8594; A
up:INX H // HL+1 &8594; HL
ADD M // M+A &8594;A
DAA // Decimal Adjust After Addition
JNC down // Jump if no carry
INR D // D+1 &8594;D
down:DCR C // C-1 &8594;C
JNZ up // Jump if ZF=0
STA F200 // A &8592;[F200]
RST 1 // Terminate

# ORG F100H // Store inputs at the address


# DB 04,43,77,55,55 // Store bytes in successive locations

Input:

F100-04 H, F101-43 H, F102- 77 H, F103- 55 H, F104- 55 H

Output:

D-02 H, A-30 H

VGEC(CE) 2 MPI
190170107144 PRACTICAL:7

c. Write a program to calculate the length of a string stored at starting location 3050H.
A string is ended with 0DH. Store the length of the string in the accumulator

Program:

LXI A,ODH
MVI H,3050H
INR B:LOOP
CMP M
INX H
JNZ LOOP
MOV A,B
STA 5000H
HLT

Input:

3050H:11H, 3051H:34H ;3052H:0DH

Output:

5000H:03H

VGEC(CE) 3 MPI

You might also like