Q.3. Write an assembly language to subtract two 8-bit numbers without borrow.
Solution:
AIM: To write a program that subtract two 8- bit numbers.
Requirements: i) 8085 Microprocessor kit / 8085 Simulator
ii) (0 –5v) DC Battery
Algorithm:
Step1: Start the microprocessor.
Step2: Load the first 8-bit data into accumulator.
Step3: Load the second 8-bit data into register B
Step4: Subtract the two 8-bit data.
Step5: Store the result from accumulator to the specified memory location.
Step6: Stop the program execution.
Flow Chart:
STRAT
Load the 1st number in A
Load 2nd number in B
Subtract B from A
STORE the result in 8050
END
Main Program:
MVI A, 04
MVI B, 03
SUB B
STA 8050
HLT
Result after Assembling:
Address OP Code
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
Final Result: 8050 =
Conclusion: Hence the two 8-bit data was being added using 8085 microprocessor
and result was verified.
Q.4. Write an assembly language program to subtract two 8- bit data values stored in
memory location 8050 and 8051 and store the result of subtraction in memory location
8052 and borrow (if any) in memory location 8053.
Solution:
AIM: To write a program that subtract two 8- bit numbers with borrow.
Requirements: i) 8085 Microprocessor kit / 8085 Simulator
ii) (0 –5v) DC Battery
Algorithm:
Step1: Start the microprocessor.
Step2: Initialize C register as zero to store borrow.
Step3: Load the first 8-bit data from memory location into accumulator.
Step4: Copy content of accumulator to register B.
Step5: Load the second 8-bit data into accumulator from memory location.
Step6: Subtract the two 8-bit data and check for carry.
Step7: Jump to step 10, if no carry.
Step 8: calculate the 2’s complement of the result, if carry is there
Step9: Increment carry if it is there.
Step10:Store the result of subtraction from accumulator to the specified
memory location.
Step11: Store the value of carry from accumulator to memory location
Step12: Stop the program execution.
Flow-Chart
STRAT
Initialize the carry as zero
Load the 1st 8-bit data from
memory to accumulator
Transfer the first 8-bit number to register B
Load 2nd 8-bit number from memory to
accumulator
Subtract B from A
Check
for carry
No
Yes
Calculate the 2’s complement of
accumulator, if carry is there
Increment carry by 1
STORE the result from
accumulator to memory location
Move the content of carry into accumulator
Store the carry from accumulator to memory
location
END
Main Program:
MVI C,00
LDA 8050
MOV B,A
LDA 8051
SUB B
JNC LOOP
CMA
INR A
INR C
LOOP: STA 8052
MOV A,C
STA 8053
HLT
Result after Assembling:
Address OP Code
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
800A
800B
800C
800D
800E
800F
8010
8011
8012
8013
8014
8015
8016
8017
8050
8051
8052
8053
Hence successfully subtracted two 8 bits numbers with consideration of borrow.