Addition of two 16-bit numbers using 8085
Ø An
Assembly Language Program to perform addition of two 16-bit numbers using 8085?
Algorithm
1) Start
the program by loading HL register pair with address of 1st number.
2) Copy
the data to DE register pair.
3) Load
the second number to HL pair.
4) Add
the two register pair contents.
5) Check
for carry.
6) Store
the value of sum and carry in memory locations.
7) Terminate
the program.
Program
MEMORY
|
LABEL
|
MNEMONIC
|
HEX CODE
|
COMMENT
|
4200
|
MVI C,00
|
0E
|
Initialize C a
0
|
|
4201
|
00
|
|||
4202
|
LHLD 4500
|
2A
|
Load address
of 1st number to HL pair
|
|
4203
|
00
|
|||
4204
|
45
|
|||
4205
|
XCHG
|
EB
|
Copy 1st
number to DE pair
|
|
4206
|
LHLD 4502
|
2A
|
Load address
of 2nd number to HL pair
|
|
4207
|
02
|
|||
4208
|
45
|
|||
4209
|
DAD D
|
19
|
Add HL pair
with DE pair
|
|
420A
|
JNC GO
|
D2
|
Jump on no
carry to the label GO
|
|
420B
|
0E
|
|||
420C
|
42
|
|||
420D
|
INR C
|
0C
|
Increment C by
1
|
|
420E
|
GO
|
SHLD 4100
|
22
|
Store HL pair
content to 4100
|
420F
|
00
|
|||
4210
|
41
|
|||
4211
|
MOV A,C
|
79
|
Content of C copied
to A
|
|
4212
|
STA 4102
|
32
|
Store
accumulator content to 4102
|
|
4213
|
02
|
|||
4214
|
41
|
|||
4215
|
HLT
|
76
|
Program ends
|
Observation
Input at 4500 : 0603H
4502 : 0009H
Output at 4100 : 060CH
4102 : 00H
--------------------------------------------------------------------------------------Subtraction of two 16-bit numbers using 8085
Ø An
Assembly Language Program to perform subtraction of two 16-bit numbers using
8085?
Algorithm
1) Start
the program by loading HL register pair with address of 1st number.
2) Copy
the data to DE register pair.
3) Load
the second number to HL pair.
4) Copy
data in register E to Accumulator.
5) Copy
date in register L to register B.
6) Subtract
data in register B from Accumulator.
7) Check
for carry.
8) If
carry is present take 2’s complement of Accumulator.
9) Store
the difference value in the memory location.
10) Copy
data in register D to Accumulator.
11) Subtract
data in register H from Accumulator along with borrow.
12) Check
for carry.
13) If
carry is present take 2’s complement of Accumulator.
14) Store
the difference value and borrow in the memory location.
15) Terminate
the program.
Program
MEMORY
|
LABEL
|
MNEMONIC
|
HEX CODE
|
COMMENT
|
4400
|
LHLD 4600
|
2A
|
Load 1st
numbers address to HL pair
|
|
4401
|
00
|
|||
4402
|
46
|
|||
4403
|
XCHG
|
EB
|
Exchange
between HL and DE pair
|
|
4404
|
LHLD 4602
|
2A
|
Load address
of 2nd number to HL pair
|
|
4405
|
02
|
|||
4406
|
46
|
|||
4407
|
MVI C,00
|
0E
|
Initialize C
as 0
|
|
4408
|
00
|
|||
4409
|
MOV A,E
|
7B
|
Copy content
of E to accumulator
|
|
440A
|
MOV B,L
|
45
|
Copy content
of register L to B
|
|
440B
|
SUB B
|
90
|
Subtract B
from Accumulator
|
|
440C
|
JNC GO
|
D2
|
Jump on no carry
to label GO
|
|
440D
|
11
|
|||
440E
|
44
|
|||
440F
|
CMA
|
2F
|
Compliment
Accumulator content
|
|
4410
|
INR A
|
3C
|
Increment
Accumulator content by 1
|
|
4411
|
GO
|
STA 4300
|
32
|
Store
accumulator content to 4300
|
4412
|
00
|
|||
4413
|
43
|
|||
4414
|
MOV A,D
|
7A
|
Copy content
of D to accumulator
|
|
4415
|
SBB H
|
9C
|
Subtract
content of H from accumulator along with borrow
|
|
4416
|
JNC LABEL
|
D2
|
Jump on no
carry to LABEL
|
|
4417
|
1C
|
|||
4418
|
44
|
|||
4419
|
INR C
|
0C
|
Increment C by
1
|
|
441A
|
CMA
|
2F
|
Compliment
Accumulator content
|
|
441B
|
INR A
|
3C
|
Increment
accumulator content by 1
|
|
441C
|
LABEL
|
STA 4301
|
32
|
Store
accumulator content to 4301
|
441D
|
01
|
|||
441E
|
43
|
|||
441F
|
MOV A,C
|
79
|
Copy carry to
the accumulator
|
|
4420
|
STA 4302
|
32
|
Store the
accumulator content to 4302
|
|
4421
|
02
|
|||
4422
|
43
|
|||
4423
|
HLT
|
76
|
Program ends
|
Observation
Input at 4600 : 080FH
4602 : 0603H
Output at 4300 : 0CH
4301 : 02H
4302 : 00H
------------------------------------------------------------------------------------
No comments:
Post a Comment