Menu Close

Instruction set and programming: UPSC Electrical Engineering Optional PYQ Solutions (2001–2026)

All 44 questions UPSC has asked on instruction set and programming in the Electrical Engineering Optional (Paper II, Microprocessors and Microcomputers) from 2001 to 2026, solved step by step – latest first.

Try them yourself first: the same questions, without solutions, are on our Microprocessors and Microcomputers topic-wise PYQs page. Circuit diagrams have been redrawn from the question papers.

How we check these solutions

These are our own solutions, prepared with AI help. UPSC does not publish official answers. Every solution is checked a second way before it goes up, and says how:

  • ✓ Checked by computer the numbers were worked out again independently in code (SymPy and NumPy: circuit equations, power balance, matrices, integrals).
  • ✓ Answer checked step by step for theory and descriptive questions, every point was checked against the standard theory.

Where a printed question is wrong, unclear or incomplete, we say so and solve the intended version.

Spotted a mistake or a neater method? Tell us in the comments below or through Report an error.

Jump to a question (year · question number):

2026 · 1b 2025 · 1b 2025 · 2b 2025 · 4b(i) 2025 · 4b(ii) 2024 · 1b 2024 · 3c 2024 · 4b 2023 · 1d 2023 · 3b(ii) 2023 · 6b(ii) 2022 · 2b 2021 · 1c 2021 · 5e 2020 · 1b 2020 · 2c 2020 · 3c 2020 · 6c 2019 · 5d 2018 · 2c 2018 · 4c 2018 · 6c 2017 · 7b(i) 2016 · 5c 2016 · 7b(ii) 2015 · 1e 2015 · 4a(i) 2014 · 4b 2014 · 6b 2013 · 1c(ii) 2013 · 6b(ii) 2013 · 7b(ii) 2012 · 1b(i) 2012 · 2c 2012 · 4b 2010 · 1c 2010 · 4b 2009 · 4c 2009 · 6b 2007 · 2a 2004 · 4a 2003 · 3a 2002 · 8a 2001 · 8a

Cover of the UPSC Prelims Topic-wise PYQ book with detailed explanations

From the Optional Province team

Preparing for Prelims too?

Our UPSC Prelims Topic-wise PYQ Book covers every Prelims question with detailed explanations, so you can see exactly where UPSC asks from. Now available as a hard copy and an eBook.

Buy Hard Copy on AmazonBuy eBook (PDF)

Download a free sample

Upon execution of the following routine, find the value stored at location 00FFH. MVI B, 0FH MVI C, ABH MOV A, C ADD B SBI 02H STA 00FFH Also write the status of each flag after completion of execution.

2026 · Paper II · Q1b · 10 marks

Solution

Instruction Effect
MVI B, 0FH B = 0FH
MVI C, ABH C = ABH
MOV A, C A = ABH
ADD B A = ABH + 0FH = BAH. CY = 0; AC = 1 (B + F carries out of bit 3)
SBI 02H A = BAH − 02H − CY = BAH − 02H − 0 = B8H
STA 00FFH memory 00FFH ← B8H

Subtraction in detail. The 8085 subtracts by adding the 2’s complement: BAH+FEH=1B8H. The carry out of bit 7 is 1, so CY = 0 (no borrow). There is a carry out of bit 3 (A + E = 18H), so AC = 1.

[00FFH]=B8H

Flags after execution (A = B8H = 1011 1000)

S Z AC P CY
1 0 1 1 0
  • S = 1: bit 7 is 1.
  • Z = 0: the result is not zero.
  • P = 1: four 1s, even parity.
  • CY = 0: no borrow.
  • AC = 1: as worked out above.

STA does not change the flags.

✓ Checked by computer We ran the routine on an 8085 simulator in Python and read the memory and flags.

↑ Back to the question list

Explain the operation performed by 8085 microprocessor when the following instructions are executed: (i) JMP unconditionally (ii) POP (iii) PUSH (iv) RET (v) STC.

2025 · Paper II · Q1b · 10 marks

Solution

  • (i) JMP addr16 (jump unconditionally). A 3-byte instruction (10 T-states). The 8085 reads the 16-bit address in bytes 2 and 3 and loads it into the program counter. The next instruction is fetched from that address, whatever the flags. No flags are affected.

  • (ii) POP rp (rp = B, D, H or PSW).

    • It copies the byte at the address in SP into the low-order register (C, E, L, or the flags), then increments SP.
    • It copies the byte at the new SP into the high-order register (B, D, H or A), then increments SP again.

    So SP rises by 2. POP PSW restores A and the flags; other POPs leave the flags unchanged.

  • (iii) PUSH rp.

    • It decrements SP and stores the high-order register (B, D, H or A) there.
    • It decrements SP again and stores the low-order register (C, E, L or the flags).

    So SP falls by 2. The register pair is saved on the stack, and no flags change.

  • (iv) RET. Return from subroutine. The two bytes on top of the stack are popped into the PC: the low byte from SP, the high byte from SP + 1. SP increases by 2, and execution continues at the return address saved by the matching CALL.

  • (v) STC. Set carry: CY ← 1. No other flag changes. It is used before CMC to clear the carry, or before RAL, RAR to shift in a 1.

✓ Answer checked step by step Standard result.

↑ Back to the question list

For 8085 microprocessor, write the instructions to perform the following: (i) Set the zero flag when a register pair is used as a down counter (ii) Load the accumulator with the contents of location 2050H, if memory location 2050H contains byte F8H (iii) Load 3AH in memory location 2050H, if registers H and L contain 20H and 50H (iv) Subtract 25H with borrow from accumulator, if the accumulator contains 37H and the borrow flag is set (v) Complement the accumulator, which has data byte 89H.

2025 · Paper II · Q2b · 20 marks

Solution

(i) Zero flag with a register pair as down counter. DCX rp does not affect any flag. So after decrementing, we OR the two halves into the accumulator; Z = 1 when both are zero.

Instruction Comment
LXI B, count load the 16-bit count
LOOP: DCX B BC ← BC − 1 (flags unchanged)
MOV A, C low byte to A
ORA B Z = 1 only if B = C = 00H
JNZ LOOP repeat until BC = 0000H

(ii) LDA 2050H gives A = F8H.

(iii) H = 20H and L = 50H, so HL points to 2050H. MVI M, 3AH stores 3AH at 2050H.

(iv) SBI 25H, with A = 37H and CY = 1: A=37H−25H−1=11H The flags are CY = 0 (no borrow), Z = 0, S = 0, P = 1 (two 1s) and AC = 1.

(v) CMA with A = 89H = 1000 1001 gives A = 0111 0110 = 76H. No flags change.

✓ Checked by computer We ran each case on an 8085 simulator in Python.

↑ Back to the question list

For 8085 microprocessor, write a program to do the following: 1. Clear the accumulator 2. Add 47H (using ADI instruction) 3. Subtract 92H 4. Add 64H 5. Display the results after subtracting 92H and after adding 64H Specify the answer you would expect at the output port. Also give the reason for clearing the accumulator before adding the number 47H directly to the accumulator.

2025 · Paper II · Q4b(i) · 10 marks

Solution

Instruction Comment
XRA A clear A (A = 00H); also clears CY
ADI 47H A = 47H
SUI 92H A = 47H − 92H = B5H, CY = 1 (borrow)
OUT PORT1 display B5H
ADI 64H A = B5H + 64H = 119H, so A = 19H, CY = 1
OUT PORT2 display 19H
HLT stop

Expected outputs

  • After subtracting 92H, the port shows B5H. As a signed number this is −4BH (−75), the correct value of 47H − 92H. CY = 1 shows the borrow.
  • After adding 64H, the port shows 19H, with CY = 1. In two’s complement, −75 + 100 = 25 = 19H: the carry is simply ignored.

Why clear the accumulator first? ADI 47H adds 47H to whatever is already in A. A holds a leftover value from earlier instructions, so without clearing it the result would be wrong. XRA A (or MVI A, 00H) makes A = 0, so that after ADI 47H the accumulator holds exactly 47H. XRA A also resets CY, so no stale carry upsets later instructions.

✓ Checked by computer We ran the program on an 8085 simulator in Python.

↑ Back to the question list

Write the instruction to clear the CY flag to load FFH in register B and increment (B). If the CY flag is set, display 1 at the output port; otherwise, display the contents of register B. Explain your result.

2025 · Paper II · Q4b(ii) · 10 marks

Solution

There is no direct “clear carry” instruction, so we use STC followed by CMC (or simply ORA A, which resets CY without changing A).

Instruction Comment
STC CY = 1
CMC CY = 0 (carry cleared)
MVI B, FFH B = FFH
INR B B = 00H, Z = 1; CY is not affected
JNC SHOW CY = 0, so jump
MVI A, 01H (CY = 1 case)
OUT PORT1 display 01
HLT
SHOW: MOV A, B A = 00H
OUT PORT1 display 00H
HLT

Result. The port shows 00H, not 01.

FFH + 1 rolls over to 00H, which sets Z (and AC). But INR and DCR do not change the carry flag, so CY stays 0, the program takes the “no carry” branch, and it displays the contents of B, which is 00H.

To detect an overflow from a register count, we must test Z, or use ADI 01H on the accumulator, which does set CY.

✓ Checked by computer We ran the program on an 8085 simulator in Python.

↑ Back to the question list

Explain the operation performed by 8085 microprocessor when the following arithmetic instructions are executed: (i) ADD M (ii) ADC M (iii) DAD rp (iv) SBI d8 (v) DCR reg.

2024 · Paper II · Q1b · 10 marks

Solution

  • (i) ADD M. A ← A + [HL]. The byte at the memory address held in HL is added to the accumulator, and the result stays in A. All flags (S, Z, AC, P, CY) are affected. It is 1 byte, 7 T-states (2 machine cycles).
  • (ii) ADC M. A ← A + [HL] + CY. The same as ADD M, but the carry flag is also added. It is used for multi-byte addition. All flags are affected.
  • (iii) DAD rp. HL ← HL + rp (rp = B, D, H or SP). A 16-bit addition of the register pair to HL; the sum is left in HL. Only CY is affected (set on a carry out of bit 15). 1 byte, 10 T-states.
  • (iv) SBI d8. A ← A − d8 − CY. The immediate byte and the borrow are subtracted from A. All flags are affected; CY = 1 means a borrow. 2 bytes, 7 T-states.
  • (v) DCR reg. reg ← reg − 1. S, Z, AC and P are affected, but CY is not. 1 byte, 4 T-states (10 for DCR M).

✓ Answer checked step by step Standard result.

↑ Back to the question list

Write an assembly language program to add two numbers of 8-bit data stored in memory locations 4200H and 4201H and store the result in 4202H and 4203H.

2024 · Paper II · Q3c · 10 marks

Solution

Instruction Comment
LXI H, 4200H HL points to the first number
MOV A, M A = [4200H]
INX H HL = 4201H
ADD M A = A + [4201H]; CY = carry
INX H HL = 4202H
MOV M, A sum (low byte) to 4202H
MVI A, 00H clear A (MVI does not change CY)
ACI 00H A = 0 + 0 + CY, the carry
INX H HL = 4203H
MOV M, A carry to 4203H
HLT stop

Example. [4200H] = 9AH and [4201H] = 7CH give a sum of 116H. So [4202H] = 16H and [4203H] = 01H. With 12H and 34H, the results are 46H and 00H.

✓ Checked by computer We ran the program on an 8085 simulator in Python, with and without a carry.

↑ Back to the question list

Identify and explain briefly the addressing modes of 8085 microprocessor in the given instructions: (i) ADD reg (ii) MOV rd, M (iii) CALL addr 16 (iv) LDA addr 16 (v) CMA.

2024 · Paper II · Q4b · 20 marks

Solution

Instruction Addressing mode Explanation
(i) ADD reg Register The operand is in a register named in the opcode; A ← A + reg
(ii) MOV rd, M Register indirect The source is the memory location whose address is in HL; the destination is a register
(iii) CALL addr16 Immediate (direct) The 16-bit target address is given in the instruction itself (bytes 2 and 3). The return address is pushed using SP (register-indirect write to the stack)
(iv) LDA addr16 Direct The 16-bit address of the operand is in the instruction; A ← [addr16]
(v) CMA Implied (implicit) No operand is given; the instruction works on the accumulator by default

✓ Answer checked step by step Standard result.

↑ Back to the question list

Briefly explain the following logical instructions of 8085 microprocessor: (i) ANA M (ii) XRA M (iii) CMC (iv) STC (v) RRC.

2023 · Paper II · Q1d · 10 marks

Solution

  • (i) ANA M. A ← A AND [HL]. A bit-by-bit AND of the accumulator with the memory byte addressed by HL. S, Z and P are set by the result; CY = 0 and AC = 1. Example: A = 3CH and [HL] = 0FH give A = 0CH.
  • (ii) XRA M. A ← A XOR [HL]. S, Z and P are set by the result; CY = 0 and AC = 0. Example: A = 3CH and [HL] = 0FH give A = 33H. (XRA A clears the accumulator.)
  • (iii) CMC. Complement carry: CY ← NOT CY. Other flags are unchanged.
  • (iv) STC. Set carry: CY ← 1. Other flags are unchanged.
  • (v) RRC. Rotate the accumulator right: each bit moves one place right, D0 goes to both D7 and CY. Only CY is affected. Example: A = 81H gives A = C0H and CY = 1.

✓ Answer checked step by step Standard result.

↑ Back to the question list

Discuss with example how BCD number addition is performed using DAA instruction of 8085 microprocessor.

2023 · Paper II · Q3b(ii) · 10 marks

Solution

BCD addition with DAA. The binary adder in the ALU treats packed BCD bytes as plain binary. So the sum can contain an invalid BCD digit (A–F), or lose 6 in a digit that produced a carry. DAA (decimal adjust accumulator), placed just after ADD, ADC or ADI, corrects A:

  1. If the low nibble > 9, or AC = 1, then 06H is added to A.
  2. If the high nibble > 9 (after step 1), or CY = 1, then 60H is added and CY is set.

The result is a correct 2-digit BCD number in A, and CY holds the hundreds digit.

Example 1: 38 + 45 (BCD)

Step A Note
MVI A, 38H 38H
ADI 45H 7DH low nibble D > 9
DAA 7DH + 06H = 83H 38 + 45 = 83 ✓, CY = 0

Example 2: 77 + 48

Step A Note
ADI 48H BFH both nibbles > 9
DAA BFH + 66H = 125H, so A = 25H, CY = 1 77 + 48 = 125 ✓

Example 3: 99 + 01 gives 9AH. DAA adds 66H, so A = 00H and CY = 1, which represents 100.

DAA works only after addition in the 8085. To subtract in BCD, we add the 10’s complement.

✓ Checked by computer We checked the DAA results for the examples on an 8085 simulator in Python.

↑ Back to the question list

Write an 8085 assembly language program to read and complement the contents of the flag register.

2023 · Paper II · Q6b(ii) · 8 marks

Solution

The flag register cannot be read directly. But PUSH PSW places A and the flags on the stack, from where they can be brought into a register pair.

Instruction Comment
LXI SP, 27FFH initialise the stack (any free RAM)
PUSH PSW [SP−1] ← A, [SP−2] ← flags
POP H L ← flags, H ← A (the flags are now read into L)
MOV A, L A = flag byte
CMA complement all bits
MOV L, A L = complemented flags
PUSH H put back on the stack
POP PSW flags ← complemented byte, A ← original A
HLT

Example. Flags S Z AC P CY = 1 0 1 1 1 (byte 95H) become 0 1 0 0 0. Every one of the five flags is inverted. The unused bit positions do not matter.

✓ Checked by computer We ran the program on an 8085 simulator in Python.

↑ Back to the question list

Explain each step of the assembly language program given below for microprocessor 8085 and calculate the total time taken by the processor in its execution if the processor is working at 3 MHz. (The number of clock cycles for instructions is given in the table for reference): LXI SP, 5000 H; LXI D, 00F9 H; CALL SUBROUTINE 1; HLT; SUBROUTINE 1: DCX D; MOV A, D; ORA E; JNZ SUBROUTINE 1; RET.

Instruction Clock cycle
LXI 10
CALL 18
DCX D 6
MOV A, D 4
ORA E 4
JNZ 7/10 (for Z=1 or 0)
RET 10

2022 · Paper II · Q2b · 20 marks

Solution

Step by step

Instruction Action T-states
LXI SP, 5000H stack pointer = 5000H 10
LXI D, 00F9H DE = 00F9H = 249 (loop count) 10
CALL SUB1 push the return address (address of HLT), PC ← SUB1 18
SUB1: DCX D DE ← DE − 1 (flags unchanged) 6
MOV A, D A = high byte of the count 4
ORA E A = D OR E; Z = 1 only when DE = 0000H 4
JNZ SUB1 if DE ≠ 0, jump back (10 T); else fall through (7 T) 10 / 7
RET pop the return address, back to HLT 10
HLT stop (5)

The subroutine is a delay loop: DE counts down from 249 to 0.

Time

  • The loop body runs 249 times.
  • In 248 of them the jump is taken: 248×(6+4+4+10)=248×24=5952 T.
  • In the last one it is not: 6+4+4+7=21 T.

NT=10+10+18+5952+21+10=6021T-states

At 3 MHz, T=0.333μs: t=60213×106=2.007ms

If HLT (5 T, not in the table) is counted, the total is 6026 T, or 2.009 ms.

✓ Checked by computer We ran the program on an 8085 simulator in Python and counted the T-states.

↑ Back to the question list

Explain the following related to computer programming: (i) Machine Language (ii) Assembly Language (iii) Compiler (iv) Interpreter (v) ASCII.

2021 · Paper II · Q1c · 10 marks

Solution

  • (i) Machine language. Instructions written as binary codes (often shown in hex) that the processor executes directly. For example, 3E 32 means “load 32H into A” in the 8085. It is fast and compact, but hard to write, read and debug, and it is specific to one processor.
  • (ii) Assembly language. A low-level language in which each machine instruction is written as a mnemonic with operands and labels, such as MVI A, 32H. An assembler translates it one-to-one into machine code. It is easier than machine code, but still processor-specific.
  • (iii) Compiler. A program that translates a whole high-level-language program (C, FORTRAN …) into machine code before execution. It produces an object/executable file that runs fast, and reports all errors after compiling.
  • (iv) Interpreter. A program that translates and executes a high-level program one statement at a time, at run time (BASIC, Python). No separate object file is made. Errors are found line by line; it is slower to run but convenient for testing.
  • (v) ASCII. American Standard Code for Information Interchange. A 7-bit code (128 characters) for letters, digits, punctuation and control characters, used to exchange text between computers and peripherals. For example: ‘A’ = 41H, ‘0’ = 30H, carriage return = 0DH.

✓ Answer checked step by step Standard result.

↑ Back to the question list

List the functional classification of 8085 instruction set. Give one example for each class.

2021 · Paper II · Q5e · 10 marks

Solution

Group Purpose Example
1. Data transfer (copy) Copy data between registers, memory and I/O; source unchanged; flags not affected MOV B, A, MVI A, 32H, LDA 2050H, IN 01H
2. Arithmetic Add, subtract, increment, decrement ADD B, SUI 05H, INR C, DAD D
3. Logical AND, OR, XOR, compare, rotate, complement ANA C, XRI 0FH, CMP B, RLC, CMA
4. Branching Change the program sequence: jumps, calls, returns, restarts JMP 2050H, JZ LOOP, CALL 3000H, RET, RST 7
5. Machine control Control processor operation, interrupts and the stack HLT, NOP, EI, DI, SIM, RIM, PUSH B

✓ Answer checked step by step Standard result.

↑ Back to the question list

Explain briefly the following control instructions of 8085 microprocessor: (i) HLT (ii) EI (iii) DI (iv) RIM.

2020 · Paper II · Q1b · 10 marks

Solution

  • (i) HLT. Halt. The processor finishes the current instruction, then stops executing and enters the halt state. The address and data buses are tri-stated. It leaves this state only on a valid interrupt or RESET (HOLD is also acknowledged). 1 byte, 5 T-states.
  • (ii) EI. Enable interrupts. It sets the interrupt-enable flip-flop, so the maskable interrupts (INTR, RST 5.5, 6.5, 7.5) are recognised. They are enabled only after the instruction that follows EI. When an interrupt is accepted the flip-flop is reset, so the service routine must execute EI again.
  • (iii) DI. Disable interrupts. It resets the interrupt-enable flip-flop: all maskable interrupts are ignored. TRAP, which is non-maskable, is not affected.
  • (iv) RIM. Read interrupt mask. It loads A with:
Bit Content
D0–D2 Masks of RST 5.5, 6.5, 7.5
D3 Interrupt-enable flag (IE)
D4–D6 Pending interrupts I5.5, I6.5, I7.5
D7 Serial input data (SID pin)

It is used to check which interrupts are masked or pending, and to read serial data.

✓ Answer checked step by step Standard result.

↑ Back to the question list

(i) Name various registers in 8085 microprocessor. Which of these registers are of 16-bit length? (ii) Explain indirect addressing modes in 8085 microprocessor with suitable example.

2020 · Paper II · Q2c · 10 marks

Solution

(i) Registers of the 8085

  • Accumulator (A), 8-bit. It is one operand of every arithmetic and logic operation and receives the result.
  • General-purpose registers B, C, D, E, H, L, 8-bit. They pair as BC, DE and HL for 16-bit operations. HL is the memory pointer.
  • Flag register, 8-bit. It holds five flags: S, Z, AC, P, CY.
  • Program counter (PC), 16-bit.
  • Stack pointer (SP), 16-bit.
  • Internal registers: instruction register (8-bit), temporary register (8-bit), and the incrementer/decrementer address latch (16-bit).

The 16-bit registers are PC and SP (and the address latch), plus the register pairs BC, DE and HL when used as pairs.

(ii) Indirect addressing in the 8085. The instruction does not hold the operand or its address. It names a register pair that holds the address of the operand in memory.

Example 1: MOV A, M with HL = 2050H copies the byte at memory 2050H into A.

Example 2: LDAX B with BC = 3000H loads A from 3000H. STAX D stores A at the address held in DE.

Other register-indirect instructions include MVI M, data, ADD M, INR M and MOV M, r.

The advantage is that the same instruction can work through a table or array. A loop increments HL with INX H and repeats the same instruction for each element.

✓ Answer checked step by step Standard result.

↑ Back to the question list

(i) For 8085 microprocessor, write a program to do the following: (1) Load the number 30H in register B and 39H in register C (2) Subtract 39H from 30H (3) Display the answer at Port 1 (ii) Find the output displayed at Port 1.

2020 · Paper II · Q3c · 10 marks

Solution

(i) Program

Instruction Comment
MVI B, 30H B = 30H
MVI C, 39H C = 39H
MOV A, B A = 30H
SUB C A = 30H − 39H
OUT PORT1 display the result
HLT stop

(ii) Output. 30H−39H:30H+39H+1=30H+C7H=F7H with no carry out, so CY = 1 (borrow).

Port 1 shows F7H (1111 0111). This is the 2’s complement of 09H, that is, −9: the correct value of 48 − 57. The flags are CY = 1, S = 1, Z = 0, P = 0 (seven 1s) and AC = 0.

✓ Checked by computer We ran the program on an 8085 simulator in Python.

↑ Back to the question list

(i) For an 8085 microprocessor program, the instructions are as follows:

Opcode Operand
MVI B, 91H
MVI C, A8H
MOV A, B
ORA C
OUT Port 1
HLT

Determine the output at Port 1, with the explanation of each statement. (ii) For an 8085 microprocessor program given below

Label Opcode Operand
Loop: MVI B, 64H
NOP
DCR B
JNZ Loop

find the number of times the loop will be executed.

2020 · Paper II · Q6c · 10 marks

Solution

(i)

Instruction Explanation
MVI B, 91H B = 1001 0001
MVI C, A8H C = 1010 1000
MOV A, B A = 91H
ORA C A = 91H OR A8H = 1011 1001 = B9H; CY = AC = 0, S = 1, Z = 0, P = 0
OUT Port 1 B9H appears at Port 1
HLT stop

Output at Port 1: B9H.

(ii) As printed, the label Loop is on MVI B, 64H. So every pass reloads B with 64H, and DCR B only brings it to 63H. Z is never set, and the loop never ends: an endless loop.

The intended program places the label on NOP:

Instruction
MVI B, 64H
Loop: NOP
DCR B
JNZ Loop

B counts down from 64H = 100 to 0, so the loop runs 100 times.

✓ Checked by computer We ran both programs on an 8085 simulator in Python.

↑ Back to the question list

Write an assembly language program using the instruction set of 8085 microprocessor for addition of six bytes of data stored in memory locations starting at 2050H. The carry generated (if any) must be saved in register B. The entire sum must be stored at two memory locations 2070H and 2071H.

2019 · Paper II · Q5d · 10 marks

Solution

Instruction Comment
LXI H, 2050H pointer to the first byte
MVI C, 06H count = 6 bytes
MVI B, 00H carry register = 0
XRA A sum = 0, CY = 0
NEXT: ADD M A = A + byte
JNC SKIP no carry, so skip
INR B count a carry
SKIP: INX H next byte
DCR C one fewer to add
JNZ NEXT repeat for all six
STA 2070H low byte of the sum
MOV A, B
STA 2071H high byte (the carries)
HLT

Check. The bytes A2, FF, 37, 99, 4F, E0 (hex) add to 3A0H. The program leaves B = 03H, [2070H] = A0H and [2071H] = 03H ✓.

✓ Checked by computer We ran the program on an 8085 simulator in Python with six test bytes.

↑ Back to the question list

Write an 8085 microprocessor assembly language program to turn ON an LED connected to bit 4 of the 8155 I/O port B. Use address of port B as 2216.

2018 · Paper II · Q2c · 10 marks

Solution

For an 8155 decoded at 20H–25H, the addresses are:

  • 20H: command/status register
  • 21H: port A
  • 22H: port B
  • 23H: port C
  • 24H, 25H: timer

Port B must first be made an output port: bit 1 (PB) of the command word = 1. The LED on bit 4 is turned on by sending 0001 0000 = 10H.

Instruction Comment
MVI A, 02H command word: port A input, port B output
OUT 20H write to the 8155 command register
MVI A, 10H 0001 0000, only bit 4 = 1
OUT 22H port B: LED on bit 4 lights
HLT

This assumes the LED lights when the port bit is 1 (anode to the port through a resistor, or a non-inverting driver). If the LED is wired active-low, we send EFH instead.

✓ Answer checked step by step Standard result (8155 port addressing).

↑ Back to the question list

Differentiate between the following pairs of instructions: (i) LDA addr and STA addr (ii) LDAX rp and SHLD addr (iii) LDAX rp and STAX rp (iv) RLC and RAL (v) PCHL and SPHL.

2018 · Paper II · Q4c · 10 marks

Solution

Pair First Second
(i) LDA addr / STA addr Load A from memory: A ← [addr]. 3 bytes, 13 T Store A into memory: [addr] ← A. 3 bytes, 13 T
(ii) LDAX rp / SHLD addr Load A from the address held in BC or DE (register indirect); 1 byte, 7 T Store HL into memory (direct): [addr] ← L, [addr+1] ← H; 3 bytes, 16 T
(iii) LDAX rp / STAX rp A ← [rp], with rp = B or D [rp] ← A: the reverse transfer, same register-indirect mode
(iv) RLC / RAL Rotate left: D7 goes to D0 and to CY (8-bit rotation) Rotate left through carry: D7 → CY and old CY → D0 (9-bit rotation)
(v) PCHL / SPHL PC ← HL: jumps to the address in HL SP ← HL: loads the stack pointer from HL (initialises or moves the stack)

None of these affect the flags, except RLC and RAL, which change CY.

✓ Answer checked step by step Standard result.

↑ Back to the question list

Explain five addressing modes of 8085 microprocessor.

2018 · Paper II · Q6c · 10 marks

Solution

  1. Immediate. The data is part of the instruction. Example: MVI B, 3EH (B ← 3EH), LXI H, 2050H, ADI 05H.
  2. Register. The operands are in registers named in the opcode. Example: MOV A, B, ADD C, INR D. These are 1-byte and fast.
  3. Direct. The 16-bit address (or 8-bit port address) of the operand is given in the instruction. Example: LDA 2050H (A ← [2050H]), STA, IN 01H, OUT 02H.
  4. Register indirect. The address of the operand is held in a register pair. Example: MOV A, M (address in HL), LDAX B, STAX D.
  5. Implied (implicit). The operand is implied by the opcode, usually the accumulator. Example: CMA, RLC, DAA, STC.

✓ Answer checked step by step Standard result.

↑ Back to the question list

Cover of the UPSC Mains Topic-wise and Year-wise PYQs book (2013–2026)

From the Optional Province team

Strengthen your GS papers

Our UPSC Mains Topic-wise & Year-wise PYQ Book (2013–2026) maps every GS question to the syllabus, so you know what UPSC asks and how often. Now available as a hard copy and an eBook.

Buy Hard Copy on AmazonBuy eBook (PDF)

Download a free sample

In an 8085 microprocessor, what is the value of stack pointer after the following program is run?

MOV SP, 07FFH
PUSH B
CALL Subroutine
POP B
ADD B
PUSH B
HLT

2017 · Paper II · Q7b(i) · 5 marks

Solution

Note: MOV SP, 07FFH is not a valid 8085 instruction. The intended one is LXI SP, 07FFH. Also, the subroutine is taken to end with RET and to leave the stack balanced.

Instruction SP after
LXI SP, 07FFH 07FFH
PUSH B 07FDH
CALL Subroutine 07FBH inside the subroutine; after RET, 07FDH
POP B 07FFH
ADD B 07FFH (no stack use)
PUSH B 07FDH
HLT 07FDH

SP=07FDH

✓ Checked by computer We traced the stack pointer step by step.

↑ Back to the question list

Write down the ALP (Assembly Language Program) to exchange 10H data bytes stored from memory location 2450H with data bytes stored from memory locations 2480H onwards.

2016 · Paper II · Q5c · 10 marks

Solution

Instruction Comment
LXI H, 2450H HL → first block
LXI D, 2480H DE → second block
MVI C, 10H count = 16 bytes
NEXT: LDAX D A = byte of the second block
MOV B, M B = byte of the first block
MOV M, A second → first
MOV A, B
STAX D first → second
INX H next addresses
INX D
DCR C
JNZ NEXT repeat 16 times
HLT

After execution, 2450H–245FH hold the old contents of 2480H–248FH, and vice versa.

✓ Checked by computer We ran the program on an 8085 simulator in Python and checked all 16 pairs.

↑ Back to the question list

Describe the function of each of the following mnemonics. How many cycles do each of them require for execution and which are the flags affected? Explain. 1. DAD (Double Add) 2. CMC (Complement Carry) 3. LHLD (Load H-L Register Pair Direct) 4. ORI (OR Immediate)

2016 · Paper II · Q7b(ii) · 10 marks

Solution

Mnemonic Function Bytes Machine cycles / T-states Flags
DAD rp HL ← HL + rp (16-bit add) 1 3 MC (fetch + 2 bus-idle) / 10 T CY only
CMC CY ← NOT CY 1 1 MC / 4 T CY only
LHLD addr L ← [addr], H ← [addr+1] 3 5 MC (fetch, 2 reads of the address, 2 reads of data) / 16 T none
ORI d8 A ← A OR d8 2 2 MC (fetch + read) / 7 T S, Z, P by the result; CY = AC = 0

Explanation

  • DAD is the only 16-bit addition. It sets CY on overflow beyond FFFFH. For example, DAD H doubles HL (a shift left).
  • CMC toggles the carry. It is used with STC to clear the carry.
  • LHLD loads a 16-bit pointer stored low byte first; SHLD is its reverse.
  • ORI sets selected bits (for example, ORI 80H sets bit 7). Like all logical instructions, it clears CY.

✓ Answer checked step by step Standard result (8085 instruction set).

↑ Back to the question list

Discussing the issues in memory addressing, explain the five addressing modes used in 8085.

2015 · Paper II · Q1e · 10 marks

Solution

Issues in memory addressing. An instruction needs to say where its operand is. Several things decide how this is done:

  • Size of the address. A full 16-bit address makes the instruction 3 bytes long and needs extra memory-read cycles.
  • Speed. Register operands need no memory access; memory operands cost 3 T-states per byte.
  • Flexibility. To work through arrays and tables, the address must be changeable at run time. A pointer register allows this; a fixed address does not.
  • Code size. Short instructions save memory.

So the 8085 offers several addressing modes, trading length and speed against flexibility.

The five modes

  1. Immediate. The operand is in the instruction (MVI A, 20H, LXI H, 2050H). It is fast and needs no data fetch, but the value is fixed.
  2. Register. The operand is in a register (MOV B, C, ADD D). 1 byte, the fastest.
  3. Direct. A 16-bit address is in the instruction (LDA 2050H, STA, SHLD, IN 80H). The whole memory can be reached, but the instruction is 3 bytes and the address is fixed.
  4. Register indirect. The address is in a register pair (MOV A, M with HL; LDAX B, STAX D). 1 byte, and the address can be changed in a loop with INX, so it is ideal for blocks of data.
  5. Implied. The operand is implied (CMA, RAL, STC, DAA).

✓ Answer checked step by step Standard result.

↑ Back to the question list

Briefly discuss the functional classification of the instruction set, explaining role and format of instructions from each category—data transfer, arithmetic/logic, branch and control.

2015 · Paper II · Q4a(i) · 10 marks

Solution

8085 instructions are 1, 2 or 3 bytes long. The first byte is the opcode; the next bytes, if any, are 8-bit data or a 16-bit address, stored low byte first.

1. Data transfer (copy) group. It copies data from a source to a destination without changing the source. Flags are not affected.

  • Register to register: MOV r1, r2, 1 byte.
  • Immediate: MVI r, d8 (2 bytes), LXI rp, d16 (3 bytes).
  • Memory: MOV r, M; LDA, STA addr (3 bytes); LDAX, STAX rp; LHLD, SHLD.
  • I/O: IN port, OUT port (2 bytes).
  • Exchange: XCHG.

2. Arithmetic group. It adds, subtracts, increments and decrements.

  • ADD r (1 byte), ADI d8 (2 bytes), ADC, SUB, SBB, SUI.
  • INR, DCR, INX, DCX, DAD, DAA.
  • The result goes to A (except INR, DCR, INX, DCX, DAD). All flags are affected, with the exceptions noted earlier.

3. Logical group. It performs AND, OR and XOR (ANA, ORA, XRA and their immediate forms), compare (CMP, CPI), rotate (RLC, RRC, RAL, RAR) and complement (CMA, CMC, STC). Results are in A, and the flags are set accordingly.

4. Branch group. It changes the sequence of execution.

  • Jumps: JMP addr and conditional JZ, JNZ, JC, JNC, JP, JM, JPE, JPO (3 bytes).
  • Calls: CALL, Cxx addr (3 bytes).
  • Returns: RET, Rxx (1 byte).
  • Restarts: RST n (1 byte).
  • Jump to HL: PCHL.

5. Machine control group. It controls the processor itself: HLT, NOP, EI, DI, SIM, RIM, and the stack operations PUSH, POP, XTHL, SPHL (1 byte each).

✓ Answer checked step by step Standard result.

↑ Back to the question list

Describe the various addressing modes in the microprocessor 8085. Give suitable examples for each addressing mode.

2014 · Paper II · Q4b · 10 marks

Solution

Mode How the operand is found Examples
Immediate The data byte or word is in the instruction MVI A, 7FH; LXI H, 2400H; ADI 25H; CPI 0AH
Register The operand is in a register named by the opcode MOV B, C; ADD E; ANA B; INR L
Direct The instruction holds the 16-bit memory address or 8-bit port address LDA 2050H; STA 3000H; LHLD 2100H; IN 05H; OUT 03H
Register indirect A register pair holds the memory address MOV A, M (HL); ADD M; LDAX B; STAX D
Implied / implicit The operand is understood from the opcode (usually A or a flag) CMA; RAL; DAA; STC; RIM

Example contrast: MVI A, 20H puts the number 20H in A. LDA 0020H puts the contents of address 0020H in A. MOV A, M with HL = 0020H does the same through a pointer.

✓ Answer checked step by step Standard result.

↑ Back to the question list

Explain: (i) Direct addressing (ii) Register indirect addressing (iii) Immediate addressing (iv) Register addressing.

2014 · Paper II · Q6b · 20 marks

Solution

  • (i) Direct addressing. The address of the operand is given directly in the instruction. For example, LDA 2050H loads A from memory location 2050H, and STA 3050H stores A there. IN 01H and OUT 02H use an 8-bit direct port address. The instruction is long (3 bytes for memory), but any location can be reached.
  • (ii) Register indirect addressing. The instruction names a register pair that holds the address of the operand. For example, with HL = 2050H, MOV A, M copies [2050H] into A; LDAX B and STAX D use BC and DE. The instruction is short (1 byte), and the address can be changed by INX, DCX, which suits arrays and loops.
  • (iii) Immediate addressing. The operand itself is in the instruction. For example, MVI B, 45H (B ← 45H), ADI 10H and LXI SP, 27FFH. It is used for constants, and no extra memory access is needed for the data.
  • (iv) Register addressing. Both operands are in registers. For example, MOV C, A, ADD B and XRA A. It is 1 byte long and the fastest (4 T-states), because no memory access is needed beyond the opcode fetch.

✓ Answer checked step by step Standard result.

↑ Back to the question list

How can square wave generation with a variable bit rate, be done using the microprocessor? Output should be available on a chosen port, using bit ‘O’.

2013 · Paper II · Q1c(ii) · 5 marks

Solution

Idea. Toggle bit 0 of an output port and wait between toggles. The delay count decides the half-period. To make the bit rate variable, the count is not fixed in the program: it is read from a memory location or an input port (DIP switches) each time.

Half-period: t1/2≈N(T-states per loop)+overheadfclk

Instruction Comment
MVI A, 00H start with bit 0 = 0
TOGGLE: OUT PORT send A to the output port; bit 0 is the square wave
XRI 01H complement bit 0 only
MOV D, A save the output pattern
IN SWITCH read the rate setting (or LDA RATE)
MOV C, A C = delay count N
DELAY: DCR C 4 T
JNZ DELAY 10 T (7 T on exit)
MOV A, D restore the pattern
JMP TOGGLE repeat forever

With N in C, each half-cycle lasts about (14N+46) T-states. At 3 MHz, N = 100 gives about 0.48 ms, so a square wave of about 1.03 kHz appears on bit 0. Changing the switch setting (N = 1 … 255) changes the frequency without changing the program. A 16-bit count in a register pair gives lower frequencies.

✓ Answer checked step by step Standard result (program checked by hand).

↑ Back to the question list

Write 8085 subroutine to transfer 12 bits of data stored in two sequential memory locations to the DAC interface carried out in part (i). Assume that the address of the first byte is stored in the HL pair.

2013 · Paper II · Q6b(ii) · 6 marks

Solution

Assumed interface. The 12-bit DAC is fed by two output latches:

  • port 40H takes bits D7–D0 (the lower 8 bits);
  • port 41H takes bits D11–D8 in its lower nibble.

Data is stored lower byte first: [HL] = low 8 bits, [HL+1] = upper 4 bits.

If the DAC is double-buffered, writing the high nibble last updates the output in one step, so no glitch appears.

Instruction Comment
DAC12: PUSH PSW save A and the flags
MOV A, M lower 8 bits of the data
OUT 40H to the low latch
INX H point to the second byte
MOV A, M upper bits
ANI 0FH keep only D11–D8
OUT 41H to the high latch: the DAC is updated
DCX H restore HL (optional)
POP PSW
RET

If part (i) used other port addresses, only the two OUT operands change.

✓ Answer checked step by step Standard result (port addresses assumed).

↑ Back to the question list

What are the different addressing modes available in 8086? Indicate their features. Write the mnemonics for each of them taking ‘MOV’ as an example. Indicate the symbolic notation also for each of them.

2013 · Paper II · Q7b(ii) · 15 marks

Solution

The 8086 forms an effective address (EA) from a base, an index and a displacement. The physical address is PA=segment×16+EA.

Mode Feature Example (MOV) Symbolic notation
Immediate Data in the instruction MOV AX, 1234H AX ← 1234H
Register Both operands in registers MOV AX, BX AX ← BX
Direct 16-bit EA (displacement) in the instruction MOV AX, [5000H] AX ← [DS:5000H]
Register indirect EA in BX, SI or DI MOV AX, [BX] AX ← [DS:BX]
Based EA = BX or BP + displacement MOV AX, [BX+08H] AX ← [DS:BX+08H]; with BP: [SS:BP+d]
Indexed EA = SI or DI + displacement MOV AX, [SI+20H] AX ← [DS:SI+20H]
Based indexed EA = base + index MOV AX, [BX+SI] AX ← [DS:BX+SI]
Based indexed + displacement EA = base + index + displacement MOV AX, [BX+DI+10H] AX ← [DS:BX+DI+10H]
String SI/DI implied, auto increment/decrement MOVSB [ES:DI] ← [DS:SI]; SI, DI ± 1
Direct I/O port 8-bit port address IN AL, 80H AL ← port 80H
Indirect I/O port port address in DX OUT DX, AL port[DX] ← AL
Relative target = IP + displacement JNZ NEXT IP ← IP + d8/d16

Features

  • The memory modes allow access to variables, arrays (indexed), records (based) and two-dimensional tables (based indexed).
  • BP-based modes default to the stack segment, so procedure parameters on the stack can be reached easily.

✓ Answer checked step by step Standard result.

↑ Back to the question list

This question has the following parts.

(i) In 8085 microprocessor, what is the advantage of multiplexing the address bus with a data bus?

(ii) Write an assembly level program of 8085 microprocessor to exchange the contents of DE register pair with that of HL register pair, using only PUSH-POP instructions.

2012 · Paper II · Q1b(i) · 5 marks · also asked 2012 (Q1b(ii))

Solution

(i) Advantage of multiplexing the address bus with the data bus. The lower 8 address lines and the 8 data lines share the same 8 pins (AD7–AD0). The address is sent in T1 and latched externally using ALE; the same lines then carry data.

  • This saves 8 pins, so the 8085, with a 16-bit address and 8-bit data bus plus serial I/O, interrupts and DMA lines, fits in a 40-pin package.
  • A smaller package is cheaper, and more pins are left for control functions.

The cost is an external latch and slightly slower bus timing.

(ii) Exchange DE and HL using only PUSH and POP

Instruction Stack / effect
PUSH D stack ← DE
PUSH H stack ← HL (on top)
POP D DE ← old HL
POP H HL ← old DE

Check. DE = 1234H and HL = ABCDH become DE = ABCDH and HL = 1234H. SP returns to its original value. (XCHG does the same in one instruction, but the question asks for PUSH and POP only.)

✓ Checked by computer We ran part (ii) on an 8085 simulator in Python.

↑ Back to the question list

For 8085 microprocessor, explain the CALL instruction, showing the details of main memory and stack.

2012 · Paper II · Q2c · 20 marks

Solution

CALL addr16 is a 3-byte, unconditional branch to a subroutine that also saves the return address. It takes 5 machine cycles and 18 T-states: opcode fetch (6T), two memory reads (the address), and two memory writes (to the stack).

Example: the main program has CALL 2070H at 2040H–2042H, and SP = 2400H.

Program memory2040HCDCALL opcode2041H70address low2042H20address high2043H…next instruction (return here)2070H…subroutine starts…20xxHC9RETStack (R/W memory)23FCH23FDH23FEH43PC low23FFH20PC high2400HxxSP after = 23FEHSP before = 2400H① SP − 1 → 23FFH ← 20H (PCH)② SP − 1 → 23FEH ← 43H (PCL)③ PC ← 2070H; RET reverses ① and ②
Example addresses; SP = 2400H before the call. On a phone, swipe sideways to see all of it.

Sequence

  1. M1 (6 T): the opcode CDH is fetched from 2040H. PC becomes 2041H, and SP is decremented to 23FFH during the extra T-states.
  2. M2, M3: the target address 70H and 20H is read from 2041H and 2042H into the internal W and Z registers. PC becomes 2043H, the return address.
  3. M4: the high byte of PC (20H) is written to the stack at 23FFH, and SP becomes 23FEH.
  4. M5: the low byte of PC (43H) is written to 23FEH.
  5. Load PC: PC ← WZ = 2070H. Execution continues in the subroutine. SP = 23FEH.

Return. At the end of the subroutine, RET pops 43H and 20H back into PC (SP returns to 2400H), and the main program resumes at 2043H.

Because the return address is kept on the stack, subroutines can be nested: each CALL pushes, and each RET pops in reverse order. The stack must be initialised (LXI SP) in R/W memory, and must stay balanced (equal PUSH and POP) inside the subroutine.

Conditional calls (CC, CNZ …) behave the same way when the condition is true. When it is false, they take 9 T-states and do not use the stack.

✓ Answer checked step by step Standard result.

↑ Back to the question list

For an 8085 microprocessor, write an assembly level program to transfer the contents of the stack pointer register to the output ports A0 and A1. Write comments with selected instructions.

2012 · Paper II · Q4b · 20 marks

Solution

SP cannot be moved directly to another register. But DAD SP adds SP to HL, so if HL = 0000H first, HL then equals SP.

Instruction Comment
LXI H, 0000H clear HL
DAD SP HL ← HL + SP = SP
MOV A, L low byte of SP
OUT A0H to output port A0
MOV A, H high byte of SP
OUT A1H to output port A1
HLT

Check. With SP = 27F3H, the ports show F3H (A0) and 27H (A1). DAD changes only CY; SP itself is unchanged.

✓ Checked by computer We ran the program on an 8085 simulator in Python.

↑ Back to the question list

Write an 8085 assembly level program for designing the following system: When a coin is inserted and when it is valid, port 1 gives code FFH. If it is valid, check whether the request is for tea or coffee at port 2. 04H code at port 2 is the request for tea and 40H code at port 2 is the request for coffee. Open the valve for liquid to come out with 04H code for tea and 40H code for coffee at port 3. These codes at port 3 are to be used for valve operation. When port 4 gives code 00H, valve is to be closed with code FFH. Repeat process can start with a new coin. If coin is invalid, 00 indication at port 5 is to be given and the instruction for inserting a new coin can be given. Write comments in the selected lines of the program.

2010 · Paper II · Q1c · 20 marks

Solution

Port use (as given)

Port Use
1 (input) FFH = valid coin
2 (input) 04H = tea, 40H = coffee
3 (output) valve codes: 04H tea / 40H coffee open, FFH close
4 (input) 00H = cup full / stop
5 (output) 00H = invalid coin, insert a new coin
Instruction Comment
START: IN 01H read the coin status
CPI FFH valid coin?
JNZ INVALID no, so signal at port 5
WAIT: IN 02H read the request
CPI 04H tea?
JZ OPEN
CPI 40H coffee?
JZ OPEN
JMP WAIT no valid request yet, keep reading
OPEN: OUT 03H A = 04H or 40H opens the right valve
CHECK: IN 04H read the stop signal
CPI 00H
JNZ CHECK wait until port 4 = 00H
MVI A, FFH
OUT 03H close the valve
JMP START ready for a new coin
INVALID: MVI A, 00H
OUT 05H “invalid coin, insert a new coin”
JMP START

Checks.

  • A valid coin with tea gives 04H, then FFH at port 3.
  • A valid coin with coffee gives 40H, then FFH.
  • An invalid coin gives 00H at port 5.

The flow is: read the coin, validate it, read the request, open the valve, wait for the stop signal, close the valve, and repeat.

✓ Checked by computer We ran the program on an 8085 simulator in Python for a valid coin with tea, a valid coin with coffee, and an invalid coin.

↑ Back to the question list

Explain the similarities and differences between: (i) JUMP and CALL instructions (ii) STA and STAX instructions.

2010 · Paper II · Q4b · 20 marks

Solution

(i) JMP and CALL

  • Similarities:
    • both are 3-byte branch instructions with a 16-bit target address;
    • both load the PC with that address;
    • both have conditional forms (JZ, CZ …);
    • neither affects the flags.
  • Differences:
JMP addr CALL addr
Transfers control permanently; no return Transfers to a subroutine and returns with RET
Does not use the stack Pushes the return address (PC) onto the stack; SP decreases by 2
10 T-states, 3 machine cycles 18 T-states, 5 machine cycles
No stack needs to be set up SP must point to valid R/W memory

(ii) STA and STAX

  • Similarities: both store the accumulator in memory, and neither affects the flags or changes A.
  • Differences:
STA addr16 STAX rp
Direct addressing: the address is in the instruction Register indirect: the address is in BC or DE
3 bytes, 13 T-states (4 machine cycles) 1 byte, 7 T-states (2 machine cycles)
The address is fixed when the program is written The address can change at run time (INX), which suits blocks of data

✓ Answer checked step by step Standard result.

↑ Back to the question list

(i) Sixteen bytes of data are stored in memory locations 7000 H to 700F H. Copy the data to locations A00F to A000 H such that the byte at 7000 H is copied at A00F H, the byte at 7001 H is copied at A00E H and so on. (ii) Describe the flags of 8085 microprocessor.

2009 · Paper II · Q4c · 20 marks

Solution

(i) Reverse copy

Instruction Comment
LXI H, 7000H source pointer (forward)
LXI D, A00FH destination pointer (backward)
MVI C, 10H 16 bytes
NEXT: MOV A, M read a source byte
STAX D store at the destination
INX H source + 1
DCX D destination − 1
DCR C count down
JNZ NEXT
HLT

[7000H] goes to A00FH, [7001H] to A00EH, … and [700FH] to A000H ✓.

(ii) Flags of the 8085. The flag register is SZ×AC×P×CY(D7…D0)

Flag Set to 1 when
S, sign bit 7 of the result is 1 (negative in 2’s complement)
Z, zero the result is zero
AC, auxiliary carry there is a carry from bit 3 to bit 4 (used internally by DAA; not testable by jumps)
P, parity the result has an even number of 1s
CY, carry an addition carries out of bit 7, or a subtraction or compare borrows

The flags are set by arithmetic and logical instructions; data-transfer instructions do not change them. Conditional jumps, calls and returns test S, Z, P and CY.

✓ Checked by computer We ran part (i) on an 8085 simulator in Python and checked all 16 bytes.

↑ Back to the question list

(i) Write a segment of 8085 Assembly language program to execute the instruction NOP 1000 times. (ii) In I/O mapped I/O mode of 8085, how many maximum input devices and maximum output devices can be connected? What will be their addresses? (iii) Which flags are set or reset by the following instructions? (a) INX B (b) CALL < address > (c) MOV A, B.

2009 · Paper II · Q6b · 20 marks

Solution

(i) NOP 1000 times. 1000 = 03E8H, so a 16-bit counter is needed.

Instruction Comment
LXI B, 03E8H count = 1000
LOOP: NOP
DCX B (no flags affected)
MOV A, C
ORA B Z = 1 when BC = 0
JNZ LOOP

The NOP is executed exactly 1000 times. The loop takes 28,007 T-states, about 9.34 ms at 3 MHz.

(ii) I/O-mapped I/O. IN and OUT carry an 8-bit port address, so up to 28 = 256 input and 256 output devices can be connected.

  • Their addresses are 00H to FFH.
  • The port address appears on both A7–A0 and A15–A8 during the I/O cycle.
  • Input and output ports with the same number are separate, because they use IOR and IOW.

(iii) Flags affected

    1. INX B: none. 16-bit increments do not affect any flag; even FFFFH → 0000H does not set Z.
    1. CALL address: none.
    1. MOV A, B: none. Data transfers do not change the flags.

✓ Checked by computer We counted the NOPs and T-states on an 8085 simulator in Python.

↑ Back to the question list

What is the difference between a microcomputer and a micro-process? What type of data is stored in the memory of a microcomputer? How much memories can a typical 8-bit micro-process access? What are the condition flags and why are they important? Write the advantage of the indexed address mode compared to the direct addressing mode. Draw the time diagram of out instruction for 8085 micro-process.

2007 · Paper II · Q2a · 20 marks

Solution

Microcomputer and microprocessor. A microprocessor is only the CPU on a single chip: ALU, registers, and timing and control. It cannot work alone. A microcomputer is a complete computer built around a microprocessor: CPU + memory (ROM, RAM) + I/O ports, joined by the system buses. (A microcontroller puts all of these on one chip.)

Data in memory. The memory stores:

  • binary words that are either instructions (opcodes and operands of the program);
  • data: numbers, characters (ASCII), addresses, and the stack.

The memory itself does not distinguish them. A byte is treated as an instruction when it is fetched in an opcode-fetch cycle.

Memory of an 8-bit microprocessor. A typical 8-bit microprocessor such as the 8085 has a 16-bit address bus, so it can access 216 = 65,536 bytes (64 KB) of memory.

Condition flags. These are flip-flops set or reset by the result of arithmetic or logic operations. In the 8085 they are:

  • S (sign);
  • Z (zero);
  • AC (auxiliary carry);
  • P (parity);
  • CY (carry).

They matter because conditional jumps, calls and returns (JZ, JC, JNZ, CP …) test them. That is how the program makes decisions, runs loops and does multi-byte arithmetic.

Indexed addressing compared with direct addressing. In direct addressing, the full address is a fixed part of the instruction (LDA 2050H), so reaching another element needs a different instruction. In indexed addressing, the effective address is a base plus the contents of an index register. So:

  • the same instruction, inside a loop, can step through a whole table or array just by incrementing the index register;
  • programs are shorter and can be relocated;
  • the instruction can be shorter, since only a small displacement is stored.

Timing diagram of the OUT instruction. OUT port takes opcode fetch (4T), memory read of the port address (3T), then I/O write (3T). The figure is drawn for OUT FFH stored at 4048H.

M1: opcode fetchM2: memory readM3: I/O writeT1T2T3T4T1T2T3T1T2T3CLKA15–A840H40HFFH (port)AD7–AD048HD3H49HFFHFFHData from AALEIO/MS1, S01, 11, 00, 1RDWR
Opcode fetch, memory read of the port address, then I/O write. On a phone, swipe sideways to see all of it.

In the I/O write cycle, IO/M = 1. The 8-bit port address appears on both A15–A8 and AD7–AD0. The accumulator contents go out on the data bus while WR is low.

✓ Answer checked step by step Standard result.

↑ Back to the question list

Justify that the stack and subroutine offer a great deal of flexibility in writing programs. Point out the differences between stack pointer and program counter, PUSH and POP, CALL and RET. Give examples for each. Write a program to add two numbers which generate the carry over, store the carry over in memory locations XX50 and XX60 in 8085 microprocessor.

2004 · Paper II · Q4a · 20 marks

Solution

Flexibility of the stack and subroutines

  • Subroutines. A task needed many times (delay, code conversion, display) is written once and called from anywhere. This saves memory and makes programs modular, easy to test and easy to change.
  • The stack. It saves return addresses automatically. This allows nesting (a subroutine calling another), and even recursion and interrupts.
  • Saving registers. PUSH and POP save and restore registers inside a subroutine, so the caller’s data is not lost.
  • Passing parameters. Parameters can be passed in registers, in memory, or on the stack.

Differences

Stack pointer (SP) Program counter (PC)
Points to the top of the stack (R/W memory) Points to the next instruction byte to fetch
Changed by PUSH, POP, CALL, RET, LXI SP Incremented after each fetch; loaded by JMP, CALL, RET
Example: LXI SP, 27FFH Example: JMP 2050H sets PC = 2050H
PUSH rp POP rp
SP − 1 ← high, SP − 2 ← low; SP decreases by 2 low ← [SP], high ← [SP + 1]; SP increases by 2
Example: PUSH B saves BC Example: POP B restores BC
CALL addr RET
Pushes PC (the return address) and jumps to addr Pops the return address into PC
3 bytes, 18 T 1 byte, 10 T

Program. We read “XX50 and XX60” as: the sum goes to XX50 and the carry to XX60. We take XX = 20H, so these are 2050H and 2060H, with the two numbers at 2040H and 2041H.

Instruction Comment
LDA 2040H first number
MOV B, A
LDA 2041H second number
ADD B A = sum, CY = carry
STA 2050H store the sum
MVI A, 00H clear A (CY unchanged)
RAL A = 0000 000CY
STA 2060H store the carry
HLT

Check. C5H + 7AH = 13FH gives [2050H] = 3FH and [2060H] = 01H. If the carry should go to both locations, add STA 2050H after RAL and keep the sum elsewhere.

✓ Checked by computer We ran the addition program on an 8085 simulator in Python.

↑ Back to the question list

Discuss briefly the architecture of 8086 microprocessor with special reference to the following (i) Memory organization (ii) Register structure (iii) Addressing modes.

2003 · Paper II · Q3a · 20 marks

Solution

The 8086 is a 16-bit processor with a 20-bit address bus (1 MB) and a 16-bit data bus. It is divided into a bus interface unit (BIU) and an execution unit (EU), which work in parallel: the BIU prefetches up to 6 instruction bytes into a queue while the EU executes. This is a simple form of pipelining.

Bus interface unit (BIU)Segment registersCS DSSS ESIP (instruction ptr)Σ addressadder20-bit physicaladdressBus control logicInstruction queue (6 bytes, FIFO) — prefetchMultiplexed busAD15–AD0, A19–A16Execution unit (EU)General registersAX = AH | ALBX = BH | BLCX = CH | CLDX = DH | DLPointer & indexSP BPSI DIALU (16-bit)Flag register(9 flags)EU control(decodes fromthe queue)opcodes16-bit data / offsets
The BIU prefetches into the queue while the EU executes. On a phone, swipe sideways to see all of it.

(i) Memory organisation

  • 1 MB, byte-addressable, 00000H–FFFFFH.

  • Two banks for the 16-bit data bus:

    • the even bank on D7–D0, selected by A0 = 0;
    • the odd bank on D15–D8, selected by BHE = 0.

    A word at an even address is transferred in one bus cycle; at an odd address it needs two.

  • Segmentation: four 64 KB segments (code, data, stack, extra) are addressed through CS, DS, SS and ES. The physical address is PA=segment×16+offset.

  • Reserved areas: 00000H–003FFH holds the interrupt vector table (256 × 4 bytes). FFFF0H is the reset address (CS = FFFFH, IP = 0000H).

(ii) Register structure (all 16-bit)

  • General purpose: AX (accumulator), BX (base), CX (count), DX (data). Each splits into 8-bit halves: AH/AL, BH/BL, CH/CL, DH/DL.
  • Pointer and index: SP (stack pointer), BP (base pointer), SI (source index), DI (destination index).
  • Segment: CS, DS, SS, ES.
  • Instruction pointer: IP.
  • Flag register: 9 flags.
    • 6 status flags: CF, PF, AF, ZF, SF, OF.
    • 3 control flags: TF (trap/single step), IF (interrupt enable), DF (string direction).

(iii) Addressing modes

Mode Example Operand
Immediate MOV AX, 1234H data in the instruction
Register MOV AX, BX in a register
Direct MOV AX, [5000H] at DS:5000H
Register indirect MOV AX, [BX] at DS:BX (also SI, DI)
Based MOV AX, [BX+08H] DS:(BX + disp); with BP, SS is the segment
Indexed MOV AX, [SI+10H] DS:(SI + disp)
Based indexed MOV AX, [BX+SI] DS:(BX + SI)
Based indexed with displacement MOV AX, [BX+DI+20H] DS:(BX + DI + disp)
String MOVSB DS:SI → ES:DI, with auto increment/decrement by DF
I/O port IN AL, 80H / IN AL, DX direct or DX-indirect port
Relative (branch) JNZ label IP + 8/16-bit displacement

✓ Answer checked step by step Standard result.

↑ Back to the question list

First manually place 00s in the accumulator and all general purpose registers. Then write a programme which will (i) place the hex number FE in the accumulator. (ii) copy the contents of the accumulator ‘A’ into register ‘B’ (iii) copy the contents of the accumulator ‘A’ into register ‘C’ (iv) stop. Show the programme in 8085 mnemonics.

2002 · Paper II · Q8a · 20 marks

Solution

Manually clearing the registers. On a trainer kit, the registers are examined and set to 00 through the keypad (“Examine Register” key) before running. Alternatively, a program can do it with XRA A, MOV B, A … MOV L, A.

Program

Address Code Mnemonic Comment
2000H 3E FE MVI A, FEH (i) A ← FEH
2002H 47 MOV B, A (ii) B ← A
2003H 4F MOV C, A (iii) C ← A
2004H 76 HLT (iv) stop

After execution, A = B = C = FEH, and D, E, H and L remain 00. No flags are changed.

✓ Checked by computer We ran the program on an 8085 simulator in Python.

↑ Back to the question list

(i) If the program counter is always one count ahead of the memory location from which the machine code is being fetched, how does the microprocessor change the sequence of program execution with a jump instruction? (ii) List the sequence of memory transfers required to process an indirect-addressing mode instruction, when the instruction is a control type (for example Jump Unconditionally). How many memory cycles are needed?

2001 · Paper II · Q8a · 20 marks

Solution

(i) Changing the sequence with a jump. While an instruction is fetched, the PC is incremented, so it always points to the next byte. Normally this gives sequential execution. A jump instruction, JMP 2050H (C3 50 20), works like this:

  1. The opcode C3H is fetched; PC is incremented.
  2. The two address bytes 50H and 20H are read into the internal temporary registers (W, Z). PC is incremented past them.
  3. At the end of the instruction, the PC is loaded with the 16-bit address from W and Z, overwriting the incremented value.

The next fetch therefore comes from 2050H. In a conditional jump, the load happens only if the condition is true; otherwise the incremented PC is kept.

(ii) Memory transfers for an indirect jump. In indirect addressing, the instruction holds the address of a memory location that contains the target address. For a byte-organised machine like the 8085, with a 3-byte instruction “JMP indirect, addr”:

Cycle Transfer
1 Read the opcode from [PC]
2 Read the low byte of the pointer address from [PC+1]
3 Read the high byte of the pointer address from [PC+2]
4 Read the low byte of the target from [pointer]
5 Read the high byte of the target from [pointer+1], then PC ← target

So 5 memory (read) cycles are needed: 3 for the instruction and 2 for the indirect address. No data operand is fetched, because the “operand” of a jump is the address itself.

In a word-organised machine with one-word instructions and addresses, this reduces to 2 memory references: fetch the instruction, then read the effective address.

The 8085 has no memory-indirect jump. Its nearest equivalent is PCHL (PC ← HL), which needs only the opcode fetch.

✓ Answer checked step by step Standard result.

↑ Back to the question list

More on Microprocessors and Microcomputers

Questions: UPSC Civil Services (Main) Examination, Electrical Engineering Paper II, 2001–2026. Solutions: Optional Province. Found an error? Tell us.

Spotted an error? Tell us.

We classify every PYQ with care, but mistakes can slip in. If a question is in the wrong topic, has a typo, the wrong year, or is missing, let us know. We review every report and update the page.

Report an Error
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted