# Assembly Languages (8085, 8086 & RISC): Registers, Flags, T-States, Interrupts & Traces
Exam: UGC NET Computer Science & Applications (Code 87) (UGC NET CS)
Subject: Unit 3: Programming in C, C++, Java, JavaScript & Assembly
Canonical URL: https://gateandnet.com/exams/ugc-net-cs/programming-languages/assembly-8085-8086-risc-instructions-and-interrupts

> 8085 flag byte [S,Z,X,AC,X,P,X,CY], instruction byte sizes & T-states (MVI, LXI, LDA, STA, LHLD, CALL), hardware interrupt priority & vector addresses (TRAP 0024H), 8086 20-bit physical addressing, and RISC assembly.

## 1. Intel 8085 Architecture, Flag Register & Subtle Instruction Traps

- **8085 Bus Widths:** **8-bit Data Bus** (multiplexed `AD0–AD7`), **16-bit Address Bus** $\implies 2^{16} = 64\text{ KB}$ addressable memory, **16-bit `SP` and `PC`**, six 8-bit general registers paired as `(B,C), (D,E), (H,L)` plus 8-bit Accumulator `A`.
- **5 Active Flags in 8-Bit Flag Register `[S | Z | - | AC | - | P | - | CY]`:** Sign (`D7`), Zero (`Z=1` when result is `00H`), Auxiliary Carry (`D3 -> D4`, used for BCD `DAA`), Parity (`P=1` for **even** number of `1`s), Carry (`CY`).

| 8085 Instruction | Byte Length | Addressing Mode | Machine Cycles / T-States | Subtle Flag / Execution Trap |
| :--- | :---: | :--- | :---: | :--- |
| `MOV A, B` | 1 Byte | Register | 1 MC / 4T | **Zero flags affected!** |
| `MVI A, 32H` | 2 Bytes | Immediate | 2 MC / 7T | Zero flags affected |
| `LXI H, 2050H` | 3 Bytes | Immediate (16-bit) | 3 MC / 10T | Loads `L=50H, H=20H` |
| `LDA 2050H` / `STA 2050H` | 3 Bytes | Direct | 4 MC / **13T** | Opcode(4T)+Low(3T)+High(3T)+Mem R/W(3T) |
| `INR B` / `DCR B` | 1 Byte | Register | 1 MC / 4T | Updates S, Z, AC, P — **DOES NOT affect CY!** |
| `INX H` / `DCX H` | 1 Byte | Register Pair | 1 MC / **6T** | **Affects NO flags at all!** (Loop trap!) |
| `CALL addr16` | 3 Bytes | Direct | 5 MC / **18T** | Opcode fetch is **6T**, pushes PC onto stack |

> [!TRAP]
> **Classic UGC NET 8085 Loop Trap:**
> ```asm
> LXI B, 0100H
> LOOP: DCX B
> JNZ LOOP
> ```
> How many times does `LOOP` execute? **Depends ONLY on previous Zero flag (either $1$ time or $\infty$ infinite loop)!** Why? Because **`DCX B` does NOT update ANY flag** (including `Z`)! To test `BC == 0`, you must write `MOV A, B` followed by `ORA C` before `JNZ LOOP`!

## 2. 8085 Hardware Interrupt Priority & Triggering

| Interrupt | Priority | Maskable? | Trigger Type | Vector Address |
| :--- | :---: | :---: | :--- | :---: |
| **`TRAP`** (`RST 4.5`) | **1 (Highest)** | ❌ **Non-Maskable (NMI)** | **Both Edge AND Level** | `0024H` |
| **`RST 7.5`** | 2 | ✅ Maskable | **Rising Edge** triggered (latched) | `003CH` |
| **`RST 6.5`** | 3 | ✅ Maskable | High Level triggered | `0034H` |
| **`RST 5.5`** | 4 | ✅ Maskable | High Level triggered | `002CH` |
| **`INTR`** | 5 (Lowest) | ✅ Maskable | Level triggered (**Non-vectored**, external `INTA`) | Supplied externally |

## 3. Load-Store RISC Assembly (MIPS / RISC-V) in GATE COA

In RISC load-store ISAs, arithmetic instructions operate **exclusively on registers**; only `LW` (Load Word) and `SW` (Store Word) access memory:
```asm
# Compute A[i] = A[i] + k  (s0 = base of int A[], s1 = i, s2 = k)
SLLI t0, s1, 2      # t0 = i * 4 (byte offset for 4-byte int)
ADD  t1, s0, t0     # t1 = &A[i]
LW   t2, 0(t1)      # t2 = Mem[t1 + 0]  <-- Load-Use RAW hazard if next instr uses t2 immediately!
ADD  t2, t2, s2     # t2 = A[i] + k     (requires 1 stall bubble even with forwarding!)
SW   t2, 0(t1)      # Mem[t1 + 0] = t2
```

## Solved Practice Questions & PYQs

### [UGC NET CS June 2023 | MCQ]
In an **Intel 8086** microprocessor, if the Code Segment register is `CS = 348AH` and the Instruction Pointer is `IP = 4214H`, what is the **20-bit physical memory address** of the next instruction fetched?
**Correct Answer:** A
**Solution:** Physical Address $= (\text{CS} \times 10\text{H}) + \text{IP} = \texttt{348A0H} + \texttt{04214H} = \mathbf{\texttt{38AB4H}}$.

### [UGC NET CS Dec 2024 | MCQ]
In the Intel **8085** microprocessor, which hardware interrupt has the **highest priority**, is **Non-Maskable (NMI)**, and what is its hexadecimal vector jump address?
**Correct Answer:** B
**Solution:** **`TRAP`** (`RST 4.5`) is the highest-priority non-maskable interrupt (requires both edge and high level) and vectors to $4.5 \times 8 = 36_{10} = \mathbf{\texttt{0024H}}$.

### [UGC NET CS 2021 | MCQ]
How many **Machine Cycles** and **T-States** are required by the 8085 microprocessor to fetch and execute the 3-byte instruction **`STA 4050H`**?
**Correct Answer:** B
**Solution:** `STA 4050H`: Opcode Fetch (`4T`) + Low-Byte Read (`3T`) + High-Byte Read (`3T`) + Memory Write (`3T`) $= \mathbf{4}$ **Machine Cycles** and $4 + 3 + 3 + 3 = \mathbf{13\text{ T-States}}$.
