8085 Instruction Set: Part 2
Branch Instructions
Branch instructions in the 8085 microprocessor allow the program to change its execution sequence. These instructions are crucial for implementing decision-making and loop structures in assembly language programs.
Types of Branch Instructions:
- Unconditional Jump Instructions:
- JMP: Unconditional jump to a specified address.
- JC: Jump if carry flag is set.
- JNC: Jump if carry flag is not set.
- JZ: Jump if zero flag is set.
- JNZ: Jump if zero flag is not set.
- Conditional Jump Instructions:
Opcode Description JC Jump if Carry flag is set JNC Jump if Carry flag is not set JZ Jump if Zero flag is set JNZ Jump if Zero flag is not set JP Jump if Sign flag is not set (positive) JM Jump if Sign flag is set (minus) JPE Jump if Parity flag is set (even parity) JPO Jump if Parity flag is not set (odd parity) - Call Instructions:
- CALL: Unconditional call to a subroutine.
- CC: Call if carry flag is set.
- CNC: Call if carry flag is not set.
- CZ: Call if zero flag is set.
- CNZ: Call if zero flag is not set.
- Return Instructions:
- RET: Unconditional return from a subroutine.
- RC: Return if carry flag is set.
- RNC: Return if carry flag is not set.
- RZ: Return if zero flag is set.
- RNZ: Return if zero flag is not set.
- Compare Instructions:
- CMP: Compares a register/memory with the accumulator.
- CPI: Compares immediate data with the accumulator.
- Rotate Instructions:
- RLC: Rotates the accumulator left through the carry bit.
- RRC: Rotates the accumulator right through the carry bit.
- RAL: Rotates the accumulator left without the carry bit.
- RAR: Rotates the accumulator right without the carry bit.
- Restart Instructions:
- RST n: Calls one of eight subroutines located in the first 64 bytes of memory.
5. Stack, I/O, and Machine Control Instructions
These instructions manage the stack, perform I/O operations, and control various aspects of the microprocessor’s operation.Stack Instructions:
- PUSH rp: Push register pair onto stack.
- POP rp: Pop top of stack to register pair.
- XTHL: Exchange top of stack with HL.
- SPHL: Move HL to stack pointer.
I/O Instructions:
- IN port: Input from I/O port to accumulator.
- OUT port: Output accumulator to I/O port.
Machine Control Instructions:
- HLT: Halt the processor.
- NOP: No operation (used for timing or to replace instructions).
- DI: Disable interrupts.
- EI: Enable interrupts.
- RIM: Read interrupt mask.
- SIM: Set interrupt mask.
Example: Using Branch Instructions
Here’s an example of how branch instructions can be used to create a simple loop:
MVI C, 5 ; Initialize counter
LOOP:
; Your loop body here
DCR C ; Decrement counter
JNZ LOOP ; Jump to LOOP if counter is not zero
; Continue with the rest of the program
This code will execute the loop body 5 times before continuing with the rest of the program.Examples of Logical Instructions
- ANA Instruction:
ANA B
: Performs a bitwise AND operation between the contents of register B and the accumulator.
- XRA Instruction:
XRA C
: Performs a bitwise XOR operation between the contents of register C and the accumulator.
- CMP Instruction:
CMP D
: Compares the contents of register D with the accumulator.
Examples of Branch Instructions
- JMP Instruction:
JMP 2000H
: Jumps unconditionally to the address 2000H.
- JC Instruction:
JC 2500H
: Jumps to the address 2500H if the carry flag is set.
- CALL Instruction:
CALL 3000H
: Calls the subroutine located at address 3000H.
- RET Instruction:
RET
: Returns unconditionally from a subroutine.
Summary
Understanding these instructions is important for effective assembly language programming on the 8085 microprocessor. Branch instructions allow for complex program flow control, while stack and machine control instructions provide essential functionality for managing subroutines, interrupts, and overall program execution.Remember that efficient use of these instructions requires careful consideration of program flow and system resources. Practice and experience will help in choosing the most appropriate instructions for specific programming tasks.
To enhance your understanding and to complete the lab assignment, please see the video lectures below: