Md.
Mobinul Hoque
Department of Biomedical Engineering
Islamic University, Bangladesh
Assembly language
Registers of 8085 Microprocessor
1. General Purpose Registers
• The 8085 has six general purpose registers: B, C, D, E, H, L.
• Each register is 8-bit wide.
• They can be used individually (e.g., MOV B, A) or in pairs (BC, DE, HL) to store 16-bit
data.
Register Use
B, C, D, E General storage during program execution.
H, L Often used as memory pointers (together form HL pair).
Example: If HL = 2050H, then MOV A, M means data from memory location 2050H is
moved into accumulator.
2. Flag Register
• It is a special 8-bit register, but only 5 bits are used as flags.
• Each flag shows the result of an arithmetic or logic operation.
Flags in 8085:
1. S (Sign flag) → Set if MSB (bit-7) of result = 1 (negative number).
2. Z (Zero flag) → Set if result = 0.
3. AC (Auxiliary Carry) → Set if carry is generated from D3 → D4 (used in BCD
arithmetic).
4. P (Parity flag) → Set if result has even number of 1s, reset for odd.
5. CY (Carry flag) → Set if carry/borrow out of bit-7.
Flag Condition (Set = 1) Example
S Result negative (MSB = 1) 1001 0100
Z Result = 00H 0000 0000
AC Carry from bit 3 to bit 4 BCD ops
P Even parity (2,4,6… 1s) 1010 0100
CY Carry out from MSB 1111 1111 + 1
Sign (S) Flag in 8085
• The Sign flag indicates whether the result of an operation is positive or negative.
• In 8085, numbers are represented in 2’s complement form:
o If MSB (bit-7) = 0 → the number is positive
o If MSB (bit-7) = 1 → the number is negative
So,
• If the result’s MSB = 1, the Sign flag (S) is set (S=1).
• If the result’s MSB = 0, the Sign flag (S) is reset (S=0).
Example 1: Positive result
A = 0000 0101 (05h → decimal 5)
+ B = 0000 0011 (03h → decimal 3)
-----------------
Result = 0000 1000 (08h → decimal 8)
• MSB = 0
• So, S = 0 (positive number)
Example 2: Negative result
A = 1111 0000 (F0h → decimal -16 in 2’s complement)
+ B = 1111 1000 (F8h → decimal -8 in 2’s complement)
-----------------
Result = 1110 1000 (E8h → decimal -24 in 2’s complement)
• MSB = 1
• So, S = 1 (negative number)
Auxiliary Carry (AC) Flag in 8085
• The AC flag is bit 4 (D3 → D4 transition) specific.
• It is set (=1) when there is a carry from the lower nibble (lower 4 bits, D0–D3) to the
upper nibble (higher 4 bits, D4–D7) during an arithmetic operation (like addition or
subtraction).
• Otherwise, it is reset (=0)
Why it matters?
• In BCD (Binary-Coded Decimal) arithmetic, each nibble (4 bits) represents a decimal
digit (0–9).
• When adding two BCD digits, if the lower nibble generates a carry into the upper nibble,
the AC flag helps detect this.
• Later, the DAA (Decimal Adjust Accumulator) instruction uses the AC flag to adjust
the result into a valid BCD number.
Example
Suppose we add two 8-bit numbers:
A = 0011 1001 (39h → decimal 57)
+ B = 0000 1001 (09h → decimal 9)
-----------------
Result = 0100 0010 (42h → decimal 66)
• Look at the lower nibble: 1001 (9) + 1001 (9) = 1 0010 (18 decimal)
• That generates a carry from bit D3 to D4.
• So, AC = 1.
• D0 D1 D2 D3 D4 D5 D6 D7
Parity (P) Flag in 8085
• The Parity flag checks whether the result of an operation contains an even or odd
number of 1s in its 8-bit binary form.
• If the number of 1s is even → P = 1 (set)
• If the number of 1s is odd → P = 0 (reset)
Example 1: Even parity
Result = 0010 1100 (2Ch → decimal 44)
Number of 1s = 3
• 3 is odd, so P = 0 (reset)
Example 2: Odd parity
Result = 0011 1100 (3Ch → decimal 60)
Number of 1s = 4
• 4 is even, so P = 1 (set)
Carry (CY) Flag in 8085
• The Carry flag is set when an arithmetic operation generates a carry out of the MSB
(bit-7) in addition, or a borrow into bit-7 in subtraction.
• Otherwise, it is reset (=0).
So,
• Addition → CY = 1 if result > 255 (8-bit overflow)
• Subtraction → CY = 1 if a borrow is required
Example 1: Carry in Addition
A = 1111 1111 (FFh → decimal 255)
+ B = 0000 0001 (01h → decimal 1)
Result = 1 0000 0000 (100h → decimal 256)
• 9th bit (carry out of bit-7) = 1
• So, CY = 1
Example 2: No Carry in Addition
A = 0000 1111 (0Fh → decimal 15)
+ B = 0000 0001 (01h → decimal 1)
-----------------
Result = 0001 0000 (10h → decimal 16)
• No carry beyond bit-7
• So, CY = 0
Example 3: Borrow in Subtraction
A = 0000 0100 (04h → decimal 4)
- B = 0000 1000 (08h → decimal 8)
-----------------
Result=1111 1100 (FCh → decimal -4 in 2’s complement)
• Borrow is needed → CY = 1
Addressing Modes in 8085 Microprocessor
Definition:
Addressing mode specifies the way in which the operand (data) is selected for an instruction.
1. Immediate Addressing Mode
• Data is given in the instruction itself.
• Example: MVI A, 32H → Load accumulator with 32H. A=32H
3 2
0011 0010
(00-FF) H- 8bit
(0000-FFFF)H-16 bit
2. Register Addressing Mode
• Operand is in one of the registers.
• Example: MOV A, B → Copy contents of register B into accumulator (A).
3. Direct Addressing Mode
• Address of data is given directly in the instruction.
• Example: LDA 2500H → Load accumulator with the data from memory location 2500H.
[2500- 32H]
4. Indirect Addressing Mode
• Address of data is given indirectly through a register pair (HL, DE, or BC).
• Example: MOV A, M → Copy data from memory location pointed by HL pair into
accumulator.
5. Implicit (Implied) Addressing Mode
• Operand is not specified, it is implied in the instruction.
• Example: CMA → Complement the accumulator (no operand needed).
Types of Instruction Sets in 8085
1. Data Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Branching Instructions
5. Control Instructions
8085 Data Transfer Instructions
Purpose: Move or copy data between registers, memory, and I/O devices.
No arithmetic or logical operation is performed.
1. MOV – Move Data
• Operation: Copy data from source to destination register.
• Example:
• MOV A, B ; Copy contents of B into A B=12 h,,, A=B=12
DS
2. MVI – Move Immediate
• Operation: Load a register or memory location with an 8-bit immediate value.
• Example:
• MVI A, 32H ; Load 32H into accumulator
3. LXI – Load Register Pair Immediate
• Operation: Load 16-bit data into a register pair (BC, DE, HL).
• Example:
• LXI H, 2050H ; Load HL pair with 2050H
2050
2051
12 34
4. LDA – Load Accumulator Direct
• Operation: Load accumulator with data from a specific memory location.
• Example:
• LDA 2500H ; Load A with contents of memory 2500H
5. STA – Store Accumulator Direct
• Operation: Store accumulator content into a specific memory location.
• Example:
• STA 2600H ; Store contents of A into memory 2600H
6. LHLD – Load H and L Direct
• Operation: Load HL pair directly from a memory location (16-bit).
• Example:
• LHLD 3000H ; L = [3000H], H = [3001H]
7. SHLD – Store H and L Direct
• Operation: Store HL pair into memory (16-bit).
• Example:
• SHLD 3100H ; Store L at 3100H and H at 3101H
8. LDAX – Load Accumulator Indirect
• Operation: Load accumulator from memory pointed by BC or DE.
• Example:
• LDAX B ; Load A from memory address in BC pair
9. STAX – Store Accumulator Indirect
• Operation: Store accumulator into memory pointed by BC or DE.
• Example:
• STAX D ; Store A at memory address in DE pair
10. XCHG – Exchange H and L with D and E
• Operation: Swap HL pair with DE pair.
• Example:
• XCHG ; Swap H ↔ D, L ↔ E
8085 Arithmetic Instructions
Purpose: Perform arithmetic operations on data in registers or memory.
1. ADD – Add Register to Accumulator
• Operation: Add contents of a register to accumulator (A = A + R).
• Example:
• ADD B ; A = A + B
2. ADI – Add Immediate to Accumulator
• Operation: Add an 8-bit immediate value to accumulator.
• Example:
• ADI 05H ; A = A + 05H
3. SUB – Subtract Register from Accumulator
• Operation: Subtract contents of a register from accumulator (A = A – R).
• Example:
• SUB C ; A = A – C
4. SUI – Subtract Immediate from Accumulator
• Operation: Subtract an 8-bit immediate value from accumulator.
• Example:
• SUI 0AH ; A = A – 0AH
5. INR – Increment Register/Memory by 1
• Operation: Add 1 to a register or memory location.
• Example:
• INR B ; B = B + 1
6. DCR – Decrement Register/Memory by 1
• Operation: Subtract 1 from a register or memory location.
• Example:
• DCR M ; Memory[HL] = Memory[HL] – 1
• DCR B ; B=B-1
• Example: B=03H------- B=02H
7. INX – Increment Register Pair by 1
• Operation: Add 1 to a 16-bit register pair (BC, DE, HL, SP).
• Example:
• INX H ; HL = HL + 1
8. DCX – Decrement Register Pair by 1
• Operation: Subtract 1 from a 16-bit register pair.
• Example:
• DCX D ; DE = DE – 1
9. DAA – Decimal Adjust Accumulator
• Operation: Adjust accumulator for BCD addition result.
• Example:
• DAA ; Corrects A after BCD addition
8085 Logical Instructions
Purpose: Perform logical operations on data in the accumulator or memory.
1. CMA – Complement Accumulator
• Operation: Replace A with its 1’s complement (flip all bits).
• Example:
• CMA ; A = ~A
A= 11111
A’=00000
2. CMC – Complement Carry
• Operation: Complement the carry flag (CY = ~CY).
• Example:
• CMC ; CY = ~CY
3. STC – Set Carry
• Operation: Set the carry flag (CY = 1).
• Example:
• STC ; CY = 1
4. RLC – Rotate Accumulator Left
• Operation: Rotate accumulator left; MSB → LSB & Carry.
• Example:
• RLC ; Rotate A left
5. RRC – Rotate Accumulator Right
• Operation: Rotate accumulator right; LSB → MSB & Carry.
• Example:
• RRC ; Rotate A right
6. RAL – Rotate Accumulator Left through Carry
• Operation: Shift A left; CY → LSB, MSB → CY.
• Example:
• RAL
RAL B; B= 00101111,,,, B=01011110
Carry=0 ,,, Carry=0
RAL C;
C= 01101101, carry=1
C’= 11011011 Carry’=0
7. RAR – Rotate Accumulator Right through Carry
• Operation: Shift A right; CY → MSB, LSB → CY.
• Example:
• RAR
8. ANA – AND Register/Memory with Accumulator
• Operation: A = A AND R (logical AND).
• Example:
• ANA B ; A = A & B
A= 1011
B= 0101
AB=0001
9. ANI – AND Immediate with Accumulator
• Operation: A = A AND immediate value.
• Example:
• ANI 0FH ; A = A & 0FH
10. ORA – OR Register/Memory with Accumulator
• Operation: A = A OR R (logical OR).
• Example:
• ORA C ; A = A | C
11. ORI – OR Immediate with Accumulator
• Operation: A = A OR immediate value.
• Example:
• ORI 03H ; A = A | 03H
12. XRA – XOR Register/Memory with Accumulator
• Operation: A = A XOR R (logical XOR).
• Example:
• XRA D ; A = A ^ D
13. XRI – XOR Immediate with Accumulator
• Operation: A = A XOR immediate value.
• Example:
• XRI 0AH ; A = A ^ 0AH
14. CMP – Compare Accumulator with Register/Memory/Immediate
• Operation: Subtract operand from A without storing result; sets flags.
• Example:
CMP B ; Compare A with B
8085 Branching Instructions
Purpose: Change the flow of program execution based on conditions or unconditionally.
1. JMP – Unconditional Jump
• Operation: Jump to a specified memory address unconditionally.
• Example:
• JMP 2050H ; Jump to address 2050H
2. JC – Jump if Carry
• Operation: Jump to a specified address if Carry flag (CY) = 1.
• Example:
• JC 3000H ; Jump to 3000H if CY = 1
3. JNC – Jump if No Carry
• Operation: Jump if Carry flag (CY) = 0.
• Example:
• JNC 3000H
4. JZ – Jump if Zero
• Operation: Jump if Zero flag (Z) = 1.
• Example:
• JZ 2050H
5. JNZ – Jump if Not Zero
• Operation: Jump if Zero flag (Z) = 0.
• Example:
• JNZ 2050H
6. JP – Jump if Positive
• Operation: Jump if Sign flag (S) = 0 (result positive).
• Example:
• JP 2050H
7. JM – Jump if Minus
• Operation: Jump if Sign flag (S) = 1 (result negative).
• Example:
• JM 2050H
8. CALL – Call Subroutine
• Operation: Jump to a subroutine at a specified address and save return address on the
stack.
• Example:
• CALL 4000H ; Call subroutine at 4000H
9. CC – Call if Carry
• Operation: Call subroutine if CY = 1.
• Example:
• CC 4000H
10. CNC – Call if No Carry
• Operation: Call subroutine if CY = 0.
• Example:
• CNC 4000H
11. CZ – Call if Zero
• Operation: Call subroutine if Z = 1.
• Example:
• CZ 4000H
12. CNZ – Call if Not Zero
• Operation: Call subroutine if Z = 0.
• Example:
• CNZ 4000H
13. RET – Return from Subroutine
• Operation: Return to the instruction following the last CALL.
• Example:
• RET
14. RC – Return if Carry
• Operation: Return from subroutine if CY = 1.
• Example:
• RC
15. RNC – Return if No Carry
• Operation: Return from subroutine if CY = 0.
• Example:
• RNC
8085 Control Instructions
Purpose: Control the operations of the processor, including execution flow, interrupts, and
processor state.
1. NOP – No Operation
• Operation: Do nothing for one machine cycle.
• Example:
• NOP
2. HLT – Halt
• Operation: Stop the processor until a reset occurs.
• Example:
• HLT
3. DI – Disable Interrupts
• Operation: Disable all maskable interrupts.
• Example:
• DI
4. EI – Enable Interrupts
• Operation: Enable all maskable interrupts.
• Example:
• EI
5. RIM – Read Interrupt Mask
• Operation: Read the status of interrupt lines and masks into accumulator.
• Example:
• RIM
6. SIM – Set Interrupt Mask
• Operation: Set interrupt masks and control serial output data.
• Example:
SIM