Professional Documents
Culture Documents
Question 1:
Write an assembly language program (ALP) in 8085 to add two sixteen bit numbers.
Algorithm:
For FFFF + FFFF, carry will be generated.
Initialise registers C and D to 00.
Access the lower eight bytes of the two numbers and add them. Store carry (if any) in C.
Store this sum.
Add the higher eight bytes. Store carry (if any) in D.
Add the carry stored in C. If there is a carry , store in D. Carry will be generated in this step or
in the above step. NOT in both.
Store the sum and the carry
Program Code:
Label
Address
8000
8001
8002
L1
L2
L3
8003
8004
8005
8006
8007
8008
8009
800A
800B
800C
800D
800E
800F
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
801A
801B
801C
801D
801E
801F
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
802A
802B
Result
Contents of utilised memory locations and the registers after execution of the program are as follows:
Table 2: Memory contents
Memory Locations Content Memory Locations
8500
FF
8501
8502
FF
8503
8504
FE
8505
8506
01
Content
FF
FF
FF
Discussion
The program adds two sixteen bit numbers and stores the result to specified memory location.
Question 2:
Make a copy of your program
Algorithm:
Load the 16 bit memory addresses as data in the D,E register, H,L register pair.
Compare the memory content of the register H,L pair with HLT (DF)
If comparison is found then zero flag will be set and finish the program.
Else exchange the memory contents in the registers.
Then again go to the first program
Program Code:
Label
L1
L2
Address
8200
8201
8202
8203
Opcode
3A
00
82
4F
8204
11
8205
8206
00
89
8207
21
8208
8209
00
80
820A
MOV
C,A
LXI
D,8900
LXI
H,8000
7E
MOV
A,M
820B
B9
CMP
820C
820D
820E
CA
17
80
JMP
L2
820F
EB
XCHG
8210
8211
77
EB
MOV
XCHG
8212
13
INXD
8213
23
INXH
8214
8215
8216
8217
CA
0A
80
76
JMP
M,A
L1
HLT
Comments
Load data to Accumulator
Copy contents of A to C
Load data from address to register pair D,E
Result
Contents of utilised memory locations and the registers after execution of the program are as follows:
Table 5: Memory contents
Memory Locations Content Memory Locations
8900
16
8901
8902
0E
8903
8904
3A
8905
8906
85
8907
8908
3A
8909
890A
85
890B
890C
D2
890D
890E
80
890F
8910
32
8911
8912
85
8913
8914
01
8915
8916
47
8917
8918
03
8919
891A
80
891B
891C
1F
891D
891E
14
891F
8920
D2
8921
8923
80
8924
8925
05
8926
8927
7A
8928
8929
06
892A
892B
DF
Content
00
00
00
47
02
80
10
OC
04
3A
85
3A
85
D2
80
81
24
32
85
32
85
Question 3:
Write an assembly language program (ALP) in 8085 to subtract two sixteen bit numbers.
Algorithm:
First subtract the lower bits of the 16 bit digit.
Get the lower bit in the accumulator and in a resister(B) from two memory locations.
Subtract contents of the B from A
If no carry is generated after subtraction take 2s complement.
Else save the data in some memory location
Now get the higher bits of data in accumulator and in resister(B) from the next two memory
location.
Subtract the contents of B and borrow from the accumulator.
Again check for carry.
If no carry is generated after subtraction take 2s compliment and save the data to a memory
address.
Else save the answer to a memory address.
By help of another resister(D) show that the result is negative.
Program Code:
Label
Address
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
900A
900B
900C
900D
900E
900F
9010
9011
9012
L1
9013
9014
8015
9016
9017
9018
9019
901A
901B
901C
901D
901E
901F
9020
9021
9022
9023
9024
L2
9025
9026
9027
9028
9029
902A
902B
902C
Result
Contents of utilised memory locations and the registers after execution of the program are as follows:
Table 8: Memory contents
Memory Locations Content Memory Locations
8500
FF
8501
8502
FF
8503
8504
FE
8505
8506
01
Content
FF
FF
FF
Discussion
The program subtracts two sixteen bit numbers using 2s compliment method and stores the result to
specified memory location.