📝 Progams on addition and subtraction in 8085 Microprocessor (26 MCQs)
Eight-Bit Addition and Subtraction Using the Accumulator
8085 addition and subtraction programs use the accumulator and general-purpose registers to perform arithmetic on eight-bit operands. ADD and SUB process register or memory data, while ADI and SUI use immediate values. The arithmetic result is retained in the accumulator, and the flag register records conditions including zero, sign, parity, auxiliary carry and carry or borrow.
Operand Loading and Register Selection
Operands can be obtained from direct memory locations, general-purpose registers or immediate instruction bytes. MOV transfers values between registers, while LDA retrieves a byte from a specified memory address. The accumulator is selected as the destination because standard 8085 addition and subtraction instructions operate through it.
Carry, Borrow and Eight-Bit Arithmetic Results
ADD generates a carry when the unsigned sum exceeds FFH, whereas SUB sets the carry flag when subtraction requires a borrow. ADC includes the previous carry in addition, and SBB includes it in subtraction. These instructions allow multi-byte arithmetic to be implemented through successive eight-bit operations.
Program for Addition and Subtraction of Two Memory Values
Store operands at 2050H and 2051H. For addition, execute LDA 2050H, MOV B,A, LDA 2051H, ADD B and STA 2052H. For subtraction, load 2050H into B and 2051H into C, transfer B into A, execute SUB C and STA 2053H. The subtraction calculates the first operand minus the second.
Extending Arithmetic to Sixteen-Bit Calculations
The 8085 supports sixteen-bit addition using DAD with BC, DE, HL or SP as the source pair. Larger arithmetic operations can also be performed by processing low-order bytes first and propagating carry or borrow into higher-order calculations. This combines the ALU, register pairs and carry flag for extended numerical processing.
Misconceptions About Addition and Subtraction Results
'SUB B calculates B minus accumulator' reverses the operand order because the operation calculates accumulator minus B. 'ADD changes the source register' is incorrect because the accumulator receives the result. 'A zero result always means there was a carry' is incorrect because zero and carry represent different conditions.
Arithmetic Program Tracing and Carry-Borrow Questions
Practise calculating eight-bit sums and differences in hexadecimal and binary. Identify the result location and determine whether CY indicates carry or borrow. Trace ADI, ACI, SUI and SBI instructions, and distinguish results that fit within one byte from operations requiring additional storage or multiple-byte arithmetic.
8085 Arithmetic and Status Flag Terminology
- ADD - Adds an operand to accumulator.
- SUB - Subtracts an operand from accumulator.
- ADC - Adds operand and carry.
- SBB - Subtracts operand and borrow.
- Carry - Indicates an unsigned addition carry.
- Borrow - Indicates an unsigned subtraction underflow.
📝 All Progams on addition and subtraction in 8085 Microprocessor MCQs
Q1. What is the hexadecimal opcode for the 8085 LDA instruction that loads the accumulator from a memory address?
📖 Explanation: The correct opcode is 3A because the LDA instruction is defined to use that machine code. Option 32 belongs to the STA instruction, 76 is the HLT instruction, and 00 corresponds to NOP, none of which load data into the accumulator. Knowing the exact opcode is essential when writing or debugging low‑level code, as an incorrect opcode would cause the processor to execute a different operation, leading to faulty program behavior.
Q2. What operation does the CMA instruction perform on the accumulator?
📖 Explanation: CMA stands for Complement Accumulator, which flips each bit of the accumulator, producing the one's complement. Increment would be done by INR, rotation left by RLC, and no operation is NOP. Understanding this behavior lets a programmer create bit‑wise negations or prepare data for two‑complement subtraction, which is a common step in arithmetic algorithms implemented on the 8085.
Q3. Which register pair is targeted by the LXI instruction when loading a 16‑bit immediate value?
📖 Explanation: LXI loads a 16‑bit constant directly into a register pair. When the operand specifies H and L, the instruction loads the immediate value into the HL pair, which is frequently used as a memory pointer. B‑C and D‑E are also valid pairs for LXI, but they are not the default for most data‑movement tasks. The Stack Pointer is not a register pair for LXI, making option C the correct choice.
Q4. Why does the 8085 architecture often use the accumulator as the target for arithmetic instructions?
📖 Explanation: Most arithmetic mnemonics such as ADD, SUB, INR, DCR, and DAA are defined to work directly on the accumulator, eliminating the need to specify a destination operand. This design simplifies instruction encoding and speeds up execution. The other statements are false: the 8085 has several registers, cannot hold 32‑bit values, and its speed is comparable to other registers. Using the accumulator aligns with the processor’s built‑in instruction set.
Q5. How does the SUB instruction differ from the SUI instruction?
📖 Explanation: SUB subtracts the contents of a specified register or memory location from the accumulator, requiring the operand to be a register name or M. SUI, on the other hand, subtracts an 8‑bit immediate constant supplied in the instruction itself. The other options invert this relationship or claim they are identical, which is incorrect. Recognizing this difference is key when choosing the appropriate instruction for fixed versus variable subtractions.
Q6. What is the effect of executing the DAA instruction after adding two BCD numbers?
📖 Explanation: DAA stands for Decimal Adjust Accumulator; after a binary addition of two BCD digits, it adds 6 to the low nibble if needed and also adjusts the high nibble, ensuring the result is a proper BCD value. It does not clear the carry flag, increment the accumulator arbitrarily, or rotate bits. This adjustment is crucial in financial applications where decimal accuracy must be preserved after each addition.
Q7. Why must the carry flag be cleared before performing a subtraction using the SBB instruction?
📖 Explanation: SBB subtracts the source operand and the carry flag from the accumulator, effectively performing a borrow if the flag is set. If the flag is not cleared, an unintended borrow will be introduced, corrupting the result. The instruction does not ignore the flag, nor does it affect the zero flag directly. Properly managing the carry flag ensures accurate multi‑byte subtraction, which is common in larger arithmetic routines.
Q8. In a program that adds two 8‑bit numbers stored at 2000H and 2001H and stores the 9‑bit result at 2002H and 2003H, why is it necessary to use the RRC instruction after the addition?
📖 Explanation: After adding the two bytes, the carry flag may contain the ninth bit of the sum. RRC rotates the accumulator right, moving the carry flag into bit 7 of the accumulator, which can then be stored as the high byte of the 9‑bit result. Rotating left would move bits in the opposite direction, and clearing the accumulator or resetting the zero flag would lose the carry information, making the result incorrect.
Q9. How does the XCHG instruction facilitate subtraction of two 16‑bit numbers?
📖 Explanation: XCHG exchanges the contents of the HL and DE register pairs. By moving one of the 16‑bit operands into HL, the programmer can then use the SUB or SBB instruction, which operates on the accumulator and HL, to perform the subtraction. The other options describe unrelated operations; XCHG does not multiply nor clear flags. This swapping technique simplifies multi‑byte arithmetic without additional memory moves.
Q10. Explain why using immediate addressing (e.g., MVI) for constants inside a loop can increase execution time compared to using register‑indirect addressing.
📖 Explanation: When a constant is loaded with MVI inside a loop, the processor must fetch the opcode and the immediate operand each time, adding extra fetch cycles. Using a register‑indirect mode, such as loading the constant once into a register and then using MOV or ADD M, eliminates repeated operand fetches, thereby reducing total execution time. The other statements either misstate the effect on cycles or describe unrelated behaviors.
Q11. If a programmer wants to add the contents of memory location 3000H directly to the accumulator, which instruction should be used?
📖 Explanation: The correct instruction is ADD M, which adds the byte pointed to by the HL register pair to the accumulator. To use it, HL must first be loaded with 3000H, after which ADD M accesses that address. ADI uses an immediate operand, not a memory address; ADD 3000H is not a valid mnemonic, and LDA merely loads the accumulator without performing addition.
Q12. To store the 1's complement of the byte at 2500H into 2501H, which sequence of instructions is correct?
📖 Explanation: Loading the original byte with LDA, applying CMA to invert each bit, and then storing the result with STA correctly produces the one's complement at the target address. INR would increment the value, DAA adjusts for BCD, and RRC rotates bits, none of which generate a true one's complement. This sequence directly implements the logical NOT operation required in many digital signal processing tasks.
Q13. Which of the following instruction sequences will correctly add the bytes at 4000H and 4001H and store the 16‑bit sum at 4002H (low) and 4003H (high)?
📖 Explanation: The correct sequence loads the first operand, adds the second, moves the result to a temporary register (B), rotates right to capture the carry into the high‑order bit, and then stores the low and high bytes at the specified addresses. Option A lacks handling of the high byte, Option B stores bytes in the wrong order, and Option C misplaces the rotate operation. Proper handling of the carry ensures the full 16‑bit sum is recorded.
Q14. Suppose the accumulator contains 0x9A and the carry flag is set. After executing the DAA instruction, what will be the accumulator value and the carry flag status?
📖 Explanation: DAA adjusts the accumulator to a valid BCD result after a binary addition. With 0x9A and a prior carry, DAA adds 0x66, producing 0x00 and setting the carry flag to indicate an overflow into the next decimal digit. The other options either leave the accumulator unchanged or misrepresent the carry flag, which would lead to incorrect decimal calculations in applications such as financial data processing.
Q15. In a loop that repeatedly subtracts the value at memory location 5000H from the accumulator until the zero flag is set, which instruction should be used to test for zero after each subtraction?
📖 Explanation: JZ (Jump if Zero) branches when the zero flag is set, indicating that the accumulator result has become zero and the loop should terminate. JNZ would continue the loop when zero is set, which is opposite of the requirement. JC and JNC test the carry flag, not the zero flag, and would not correctly detect a zero result. Using JZ ensures the loop stops precisely when the subtraction yields zero.
Q16. A student writes a program to add three bytes stored at 6000H, 6001H, and 6002H, storing the 16‑bit sum at 6003H (low) and 6004H (high). Which register should be used to hold the high byte during the addition?
📖 Explanation: The HL pair is commonly used as a 16‑bit register, with H holding the high‑order byte. By accumulating the low byte in the accumulator and transferring any carry into H, the program can maintain the full 16‑bit result. Registers B and D are 8‑bit and not paired for high‑order storage, while L is typically used for the low byte. Selecting H aligns with standard 8085 conventions for multi‑byte arithmetic.
Q17. Consider a routine that adds two 16‑bit numbers located at (3000H,3001H) and (3002H,3003H) using the ADD and ADC instructions. If the initial carry flag is unknown, which instruction must be executed before the first ADD to guarantee a correct result?
📖 Explanation: Clearing the carry flag with CLC ensures that the first ADD does not incorporate an unintended carry, which would corrupt the lower‑order sum. Setting the carry or rotating bits would introduce errors, and NOP would leave the flag unchanged. Properly initializing the flag is essential in multi‑byte addition, especially when the routine may be called from different parts of a program where the flag state is unpredictable.
Q18. A program uses the SUB instruction to subtract the content of memory location 7000H from the accumulator, then uses the CMA instruction. What overall arithmetic operation has been performed on the original accumulator value?
📖 Explanation: SUB first computes (A − M), and CMA then flips all bits of that result, which is equivalent to taking the one's complement of the difference. This sequence does not produce a two's complement result (which would require an additional increment), nor does it simply negate the original value or increment it. Understanding this combination helps when designing custom arithmetic logic that requires bitwise inversion after subtraction.
Q19. In an 8085 program, the programmer wants to compute (A − B) where A and B are stored at 8000H and 8001H respectively, and store the 9‑bit result (including borrow) at 8002H (low) and 8003H (high). Which combination of instructions correctly handles the borrow?
📖 Explanation: SBB subtracts the source operand and the carry flag from the accumulator, so clearing the carry beforehand ensures that only the intended borrow is captured. After the subtraction, the carry flag contains the borrow, which can be rotated into the high byte with RRC if needed. The other options either misuse instructions (CMP compares without subtraction) or fail to correctly propagate the borrow, leading to an inaccurate 9‑bit result.
Q20. If the accumulator contains 0xFF and the instruction ADI 0x01 is executed, what will be the contents of the accumulator and the status of the zero flag?
📖 Explanation: Adding 0x01 to 0xFF produces 0x00 with a carry out, and the zero flag is set because the result is zero. The accumulator does not become 0x01, and the zero flag is not cleared. Recognizing this behavior is vital when implementing loops that rely on zero detection after arithmetic operations, such as checksum calculations.
Q21. Which of the following correctly describes the effect of the INR instruction on the carry flag?
📖 Explanation: INR increments a register or memory location by one but does not affect the carry flag, preserving its previous state. This distinguishes it from instructions like ADD or DAA that may modify the carry. The other options incorrectly claim that INR manipulates the flag, which would lead to erroneous flag‑dependent logic if assumed otherwise.
Q22. A programmer needs to add three BCD digits stored consecutively at 9000H, 9001H, and 9002H, producing a BCD result in the accumulator. Which sequence of instructions ensures correct BCD addition?
📖 Explanation: Adding each BCD digit with ADD and immediately applying DAA adjusts the accumulator after each step, keeping the intermediate results valid BCD values. Applying DAA only at the end would not correct intermediate overflows, and using DAA before addition or CMP does not perform addition at all. Proper intermediate adjustment is essential in applications like digital clocks where each digit must remain a valid BCD representation.
Q23. In the 8085 instruction set, which mnemonic is used to load the accumulator directly from a 16‑bit memory address?
📖 Explanation: LDA (Load Accumulator) fetches the byte located at the specified 16‑bit address and places it into the accumulator. LDAX works with register indirect addressing, MOV transfers data between registers or between a register and memory, and STA stores the accumulator content to memory. Selecting LDA is necessary when the programmer knows the exact address of the operand, such as reading sensor data stored at a fixed location.
Q24. When implementing subtraction of two 8‑bit numbers using the two's complement method, why is it necessary to complement the subtrahend and then add 1 before adding to the minuend?
📖 Explanation: Complementing the subtrahend produces its one's complement; adding 1 converts it to the two's complement, which represents the negative of the original number. Adding this negative value to the minuend yields the subtraction result. Simply inverting bits does not produce a correct negative number, and the zero or carry flags are side effects, not the purpose of the operation. Mastery of two's complement is fundamental for implementing subtraction without a dedicated subtract instruction.
Q25. Which flag indicates an overflow after an addition operation in the 8085?
📖 Explanation: The carry flag is set when an addition generates a carry out of the most significant bit, indicating that the unsigned result exceeds 8 bits—an overflow condition for unsigned arithmetic. The zero flag signals a zero result, the sign flag reflects the most significant bit of the result, and the parity flag indicates even or odd parity. Recognizing the carry flag’s role helps designers detect overflow in calculations such as address arithmetic.
Q26. A loop copies a block of 10 bytes from source address 0xA000 to destination address 0xB000 using the LXI, MOV, and INX instructions. Which register pair should be used for the source pointer to minimize instruction count?
📖 Explanation: Using the HL register pair for the source pointer allows direct memory access with the MOV M instruction, which moves data between the accumulator and the memory location addressed by HL. This reduces the need for extra register transfers compared to BC or DE, which would require additional instructions to move data to/from the accumulator. The stack pointer (SP) is reserved for stack operations and not suitable for general data copying, making HL the optimal choice.