You are on page 1of 9

Microprocessor Programs

Multiplication of Two 4 bit Numbers

XRA A
LXI H, 2100
MOV B,M
INX H
L1: ADD M
DCR B
JNZ L1
STA 2102
HLT

Multiplication of Two 8-bit Numbers

XRA A
MOV B,A
LXI H, 1100
MOV C,M
INX H
L2: ADD M
JNC L1
INR B
L1: DCR C
JNZ L2
INX H
MOV M,A
INX H
MOV A,B
MOV M,A
HLT

Addition Of Two Numbers:

LDA 4150
MOV B,A
LDA 4151
ADD M
STA 4152
HLT
Addition Of Two no(method 2)

LXI H,2050
MOV A,M
INX H
ADD M
INX H
MOV A,B
HLT

Subtraction of Two no

LDA 4150
MOV B,A
LDA 4151
SUB B
STA 4152
HLT
Method 2 : Subtraction of Two No

LXI H,2050
MOV A,M
INX H
SUB M
INX H
MOV M,A
HLT

Biggest of Numbers

LXI H,4150
MOV C,M
INX H
MOV A,M
LOP: INX H
CMP M
JNC LOP1
MOV A,M
LOP1 DCR C
JNZ LOP
MOV M,A
HLT

Smallest of the No:

LXI H,4150
MOV C,M
LOOP: INX H
MOV A,M
INX H
CMP M
JC LOOP1
MOV A,M
LOOP1:DCR C
JNZ LOOP
MOV M,A
HLT

Division

XRA A
MOV C,A
LXI H,4150
MOV B,M
INX H
MOV A,M
P1: SUB B
JC L1
INC C
JMP P1
L1: ADD B
STA 4153
MOV AMC
STA 4152
HLT

Block Transfer

LXI H,2100
LXI D,2200
MVI C,0A
L1: MVI A,M
STAX D
INX H
INX D
DCR C
JNZ L1
HLT
RST 7

Ascending Order

LXI H,4150
MOV C,M
L1: MOV B,C
INX H
MOV A,M
PUSH H
DCR B
JZ LA1
L2: INX H
CMP M
JC L3
MOV D,A
MOV A,M
MOV M,D
L3: DCR B
JNZ L2
POP H
MOV M,A
DCR C
JMP L1
LA1: HLT

Decending Order:

LXI H,4150
MOV C,M
L1: MOV B,C
INX H
MOV A,M
PUSH H
DCR B
JZ LA1
L2: INX H
CMP M
JNC L3
MOV D,A
MOV A,M
MOV M,D
L3: DCR B
JNZ L2
POP H
MOV M,A
DCR C
JMP L1
HLT

Binary To BCD

LXI H,2101
MVI C,04
AGAIN: ORA M
DCR C
JZ FINISH
RLC
FINISH: INX H
JMP AGAIN
INX H
CPI OA
JC RESULT
MVI A,EE
RESULT: MOV M,A
MOV M,C
HLT

BCD To Binary

MVI D,08
LXI H,2100
MVI C,04
MOV B,M
AGAIN: MOV A,B
INX H
ANA D
JZ LOOP
MVI A,01
LOOP: MOV M,A
MOV A,D
RRC
MOV D,A
DCR C
JNZ AGAIN
HLT
Decimal to Hexa

XRA A
MOV C,A
LXI H,2100
MOV B,M
L1: ADI 64
JNC L2
INR C
DCR B
L2: JNZ L1
MOV D,A
INX H
MOV B,M
XRA A
ADI 0A
L3: DCR B
JNZ L3
INX H
ADD M
ADD D
JNC L4
INR C
L4: INX H
MOV M,C
INX H
MOV M,A
HLT

Hexa Decimal to Decimal

LXI H,4150
LXI B,0000
MOV A,M
SUI 64
JC L2
INR B
JMP L1
ADI 64
SUI OA
JC L4
INR C
MOV M,B
MOV B,A
MOV A,C
RLC
RLC
RLC
RLC
ADD B
INX H
MOV M,A
HLT
Sample Programs

1) TO ADD TWO 8-BIT DATA

LDA 000
MOV B,A
LDA 001
MVI C,00
ADD B
JNC AHEAD
INR C
[lab1] STA 002
MOV A,C
STA 003
HLT

Here, 000 -> 1st Operand 001 -> 2nd Operand


003 -> Sum 004 -> Carry
----------------------------------------------------------------

2) TO ADD TWO 8-BIT DATA PRESENT IN THE MEMORY

LXI H,000
MVI C,OO
MOV A,M
INX H
ADD M
JNC LAB1
INR C
[LAB1] INX H
MOV M,A
INX H
MOV M,C
HLT

Here, 000 -> 1st Operand 001 -> 2nd Operand


003 -> Sum 004 -> Carry
----------------------------------------------------------------

3) TO ADD TWO 16-BIT DATA

LHLD 000
XCHG
LHLD 002
XRA A
DAD D
JNC LAB1
INR A
[LAB1] SHLD 004
STA 006
HLT

Here, 000 & 001 -> 1st Operand 002 & 003 -> 2nd Operand
004 & 005 -> Sum 006 -> Carry
-----------------------------------------------------------------