0% found this document useful (0 votes)
1 views45 pages

Introduction-to-Assembly-Language-Programming-8085 - M2

This document provides an introduction to assembly language programming for the 8085 microprocessor, covering fundamental concepts, architecture, instruction types, and practical programming techniques. It emphasizes the importance of assembly language for understanding computer architecture, optimizing performance, and its historical significance. The document also includes examples of basic operations, data transfer instructions, and arithmetic operations relevant to the 8085 microprocessor.

Uploaded by

arun.sebastian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views45 pages

Introduction-to-Assembly-Language-Programming-8085 - M2

This document provides an introduction to assembly language programming for the 8085 microprocessor, covering fundamental concepts, architecture, instruction types, and practical programming techniques. It emphasizes the importance of assembly language for understanding computer architecture, optimizing performance, and its historical significance. The document also includes examples of basic operations, data transfer instructions, and arithmetic operations relevant to the 8085 microprocessor.

Uploaded by

arun.sebastian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Introduction to Assembly

Language Programming
(8085)
Welcome to the world of assembly language programming for the 8085
microprocessor. This presentation will guide you through the fundamentals
of assembly language, from basic concepts to practical implementation of
various operations including data transfer, arithmetic, logic, branching, and
I/O operations.
What is Assembly Language?
Assembly language is a low-level programming language that
provides a human-readable representation of machine code
instructions. Each assembly instruction has a direct one-to-one
correspondence with specific processor instructions, making it
the closest programming language to the hardware itself.

Unlike high-level languages that abstract away hardware


details, assembly gives programmers precise control over the
processor and memory, allowing for highly optimized code
when efficiency is critical.

Assembly language bridges the gap between human-readable


code and machine language, using mnemonics that represent
binary instruction codes.
Why Learn 8085 Assembly Language?
Foundation for Embedded Systems
Understanding 8085 assembly language provides the fundamental knowledge needed for
embedded and hardware programming, creating a solid base for working with modern
microcontrollers and embedded systems.

Deep Understanding of Computer Architecture


Working with assembly language teaches you how processors function at their core,
revealing the inner workings of instruction execution, memory access patterns, and
register operations.

Optimization Skills
Assembly programming develops critical thinking about resource usage, performance
optimization, and efficient algorithm implementation—skills that translate to any
programming domain.

Historical Significance
The 8085 represents an important milestone in computing history, and understanding it
provides valuable context for the evolution of processor design and computer architecture.
The 8085 Microprocessor Overview

8-bit Processor 74 Instructions

The 8085 processes data in 8-bit The instruction set includes 74 basic
chunks, with an 8-bit data bus for instructions that can perform various
transferring information between operations from simple data moves
components. to complex arithmetic.

The Intel 8085 microprocessor, introduced in


1977, became widely used in early computing
16-bit Address Bus systems, industrial controllers, and educational
environments due to its reliability and
Capable of addressing up to 64K
straightforward architecture.
(2^16) memory locations, providing
flexibility for program and data
storage.
8085 Basic Architecture
Register Structure
The 8085 microprocessor contains several key register
components that form its programming model:

• Six general-purpose 8-bit registers: B, C, D, E, H, and L


• Accumulator (A) - primary register for arithmetic and logic
operations
• Program Counter (PC) - tracks the memory address of the
next instruction
• Stack Pointer (SP) - manages the stack for subroutine calls
and returns

The 8085's architecture revolves around its register set, which


provides temporary storage during program execution. Each
register has specific roles in different instructions, with the
Accumulator serving as the central component for most
operations.
Programming Model of 8085

Register Pairs Flag Register Instruction Register


The 8085 allows registers to be paired (B- The Flag register contains status bits that This special-purpose register temporarily
C, D-E, H-L) to perform 16-bit operations, reflect the result of operations: Zero (Z), holds the current instruction being
expanding its capabilities for addressing Sign (S), Parity (P), Carry (CY), and executed. The instruction decoder then
and data manipulation. This enables Auxiliary Carry (AC). These flags are interprets this data to determine which
handling larger values and addresses crucial for conditional branching and operation to perform and which
than would be possible with 8-bit tracking operation results. components to activate.
operations alone.
Types of 8085 Instructions
Arithmetic
Data Transfer
Perform mathematical operations on data
Move data between registers, memory • ADD, SUB, INR, DCR
locations, and I/O devices
• DAA, ADC, SBB
• MOV, MVI, LDA, STA
• IN, OUT, PUSH, POP Logic
Perform bitwise logical operations

• ANA, ORA, XRA, CMP


I/O & Machine Control • RLC, RRC, RAL, RAR

Interact with external devices and


Branching
control processor state

• Control program flow and execution


IN, OUT, HLT, NOP
• • JMP, JZ, JNZ, JC, JNC
SIM, RIM, EI, DI
• CALL, RET, RST
Instruction Format and Syntax
Assembly Language Structure
Each assembly language instruction follows a standard structure:

• Mnemonic: Short, memorable code (MOV, ADD, JMP)


• Operands: Registers, memory addresses, or values the instruction acts upon
• Comments: Optional explanatory text following a semicolon

Example:

MOV A, B ; Copy contents of register B to accumulator AMVI


The syntax is strict and case-insensitive. Each
C, 5FH ; Load immediate value 5FH into register CLXI H,
instruction must follow the proper format for the
2050H ; Load address 2050H into HL register pair
assembler to correctly translate it into machine
code.
Assembling, Linking, and Executing
Analysis & Design
Understand the problem, develop algorithm and flowchart

Write Assembly Code


Create source code file (.asm) using appropriate syntax and mnemonics

Assemble
Convert assembly code to object code (.obj) using an assembler

Link
Combine object files and resolve references to create executable

Load & Execute


Load program into memory and run on 8085 processor or simulator

Modern development typically uses simulators like GNUSim8085 or 8085sim that combine these steps into a streamlined process, allowing for easier
debugging and execution.
Addressing Modes in 8085
Immediate Addressing
Data is part of the instruction itself

Example: MVI A, 20H (Load 20H directly into register A)

The value 20H is included within the instruction

Register Addressing
Operand is a register

Example: MOV A, B (Copy contents of register B to A)

Both source and destination are registers

Direct Addressing
Memory address is specified in the instruction

Example: LDA 2050H (Load accumulator with contents at address 2050H)

The instruction contains the full address

Indirect Addressing
Address is held in a register pair

Example: MOV A, M (Copy data from memory address in HL to A)

HL register pair points to the memory location

The choice of addressing mode affects instruction size, execution speed, and program flexibility. Efficient programs typically use a strategic
mix of addressing modes based on the task requirements.
Flowchart of Assembly Programming
Flowcharts provide a visual representation of program logic, making it
easier to plan and understand assembly language programs before
coding.
Key flowchart elements for assembly programming:

• Start/End terminals (oval shapes)


• Process boxes for instructions (rectangles)
• Decision diamonds for conditional branching
• Flow arrows indicating execution order
• Input/Output parallelograms

Creating a flowchart before coding helps identify logical errors and


optimize program structure, especially for complex operations that Example: Flowchart for a simple addition program that
may be difficult to visualize directly in assembly code. loads two values into registers, adds them, and stores
the result.
Writing Your First Program
Problem Statement
Add two 8-bit numbers (2H and 3H) and store the result in register C.

Algorithm
1. Load the first number (2H) into register D
2. Load the second number (3H) into register E
3. Move the content of register D to accumulator A
4. Add the content of register E to accumulator A
5. Store the result from accumulator A to register C
6. Halt the processor

This simple program demonstrates the basic structure of


assembly language programming: loading values, performing
an operation, storing the result, and controlling program flow.
Sample Code: Addition Program
Step-by-step Execution:
; Program to add two 8-bit numbers
MVI D, 02H ; Load 02H into register D 1. Register D loaded with value 02H
MVI E, 03H ; Load 03H into register E 2. Register E loaded with value 03H
MOV A, D ; Copy D to accumulator
3. Accumulator A receives value from D (02H)
ADD E ; Add E to accumulator
MOV C, A ; Store result in C 4. ADD instruction performs A + E (02H + 03H = 05H)

HLT ; Halt execution 5. Result (05H) stored in register C


6. Processor halts execution
Program size: 7 bytes
This program demonstrates the core elements of assembly
Memory requirement: Minimal programming: data movement, arithmetic operations, and
program control.
Expected result: Register C contains 05H
Data Transfer Operations Overview
Data transfer operations are the foundation of assembly language
programming. They allow the movement of data between various
components of the microprocessor system:

Between Registers
Transfer data between the processor's internal registers for
immediate processing

To/From Memory
Store results or retrieve data from RAM for longer-term storage

To/From I/O Devices


Communicate with external hardware for input/output operations

Data transfer instructions typically don't modify the data itself, but simply
move it to where it needs to be for processing or storage.
Types of Data Transfer Instructions

Register-to-Register
The MOV instruction transfers data between registers without altering it.

Example: MOV B, C copies the contents of register C to register B.

Register-to-Memory
Store register contents to memory location pointed by HL register pair.

Example: MOV M, A stores accumulator content to memory address in HL.

Immediate Data
Load constants directly into registers.

Example: MVI D, 5FH loads the hexadecimal value 5FH into register D.

Memory-to-Register
Retrieve data from specified memory addresses.

Example: LDA 2050H loads accumulator with contents at memory address 2050H.
MOV Instruction
Register-to-Register Transfer
The MOV instruction is the most fundamental data transfer
operation in 8085 assembly. It copies data between registers
without modifying it.

Format:

Note: The MOV instruction cannot move data:


MOV Destination, Source
• Directly between memory locations
Examples: • From immediate data to memory
• Between two memory locations
MOV B, C ; Copy contents of register C to BMOV
A, H ; Copy contents of register H to AMOV D, For memory-to-memory transfers, you must use the

L ; Copy contents of register L to D accumulator as an intermediate step.

MOV instructions take 1 byte of memory and execute in a


single machine cycle, making them very efficient.
MVI Instruction
Move Immediate Value
The MVI (Move Immediate) instruction loads an immediate constant value
directly into a register or memory location.

Format:

MVI Destination, Data

Examples:
MVI provides the fastest way to initialize registers
MVI A, 5AH ; Load hex value 5AH into accumulator AMVI B, 00H with known values at the beginning of a program
; Clear register B by loading 0MVI M, FFH ; Store FFH at or subroutine. For memory operations, the M
memory location pointed by HL destination refers to the memory location whose
address is in the HL register pair.
MVI instructions require 2 bytes of memory: one for the opcode and one for
the immediate data. They typically execute in two machine cycles.
LDA and STA Instructions
LDA Instruction
Load Accumulator Direct

Loads the accumulator with contents from specified memory address

LDA 2050H ; Load A with byte at 2050H

3-byte instruction (1 opcode + 2 address bytes)

STA Instruction
Store Accumulator Direct

Stores accumulator contents to specified memory address

STA 3000H ; Store A contents to 3000H

3-byte instruction (1 opcode + 2 address bytes)

These instructions provide direct access to any memory location within the 64K
address space without needing to set up register pairs for addressing. They're
commonly used for accessing variables and I/O mapped devices.
LXI and LDAX/STAX Instructions
LXI (Load Register Pair Immediate)

LXI H, 2050H ; Load HL pair with 2050H


LXI B, 3000H ; Load BC pair with 3000H
LXI D, 0FFFH ; Load DE pair with 0FFFH

LXI is a 3-byte instruction that loads a 16-bit immediate value


into a register pair (B-C, D-E, H-L, or SP), enabling operations
with larger values and memory addressing.

LDAX/STAX (Load/Store Accumulator Indirect)

LDAX B ; Load A from address in BC These instructions are particularly useful for:
STAX D ; Store A to address in DE
• Setting up memory pointers

These instructions use register pairs (only B-C or D-E) as • Initializing the stack
pointers to memory locations for indirect addressing • Working with arrays and data tables
operations. • Performing indexed addressing
Data Transfer with I/O Ports

IN Instruction OUT Instruction


Reads data from a specified I/O port into the accumulator. Sends data from the accumulator to a specified I/O port.

IN 07H ; Read from port 07H into A OUT 01H ; Send contents of A to port 01H

Used for receiving data from peripherals like keyboards, sensors, and input switches. Used for transmitting data to peripherals like displays, printers, and control systems.

The 8085 supports 256 possible I/O ports (00H to FFH), providing a standardized way to interact with external devices. These instructions implement the I/O-mapped
architecture, where I/O devices have their own address space separate from memory.
Practical Example: Input/Output Transfer
Reading from Input Port to Memory

; Read from input port 80H and store at memory


location 2050H
LXI H, 2050H ; Load address 2050H into HL
IN 80H ; Read from port 80H into A
MOV M, A ; Store A at memory location in HL
HLT ; Halt program

Outputting from Memory to Port

; Send data from memory location 3000H to output


port 40HLDA 3000H ; Load data from memory
into AOUT 40H ; Output data to port 40HHLT Real-world applications of I/O operations include:
; Halt program
• Reading sensor values in control systems
• Scanning keypads for user input
• Controlling LED displays and indicators
• Interfacing with analog-to-digital converters
Arithmetic Operations Overview
Arithmetic operations in the 8085 are primarily centered around the accumulator (A register) and are essential for performing
calculations in assembly programs. These operations affect the Flag register, particularly the Carry, Zero, Sign, Parity, and Auxiliary
Carry flags.

Addition Operations Subtraction Operations Increment/Decrement


• ADD - Add register/memory to • SUB - Subtract register/memory • INR/DCR - Increment/decrement
accumulator from accumulator register or memory
• ADI - Add immediate to accumulator • SUI - Subtract immediate from • INX/DCX - Increment/decrement
• ADC - Add with carry accumulator register pair
• SBB - Subtract with borrow
Addition and Subtraction Instructions
Addition Instructions

ADD B ; A = A + B
ADD M ; A = A + (HL)
ADI 05H ; A = A + 05H (immediate)

Addition instructions add the content of a register, memory


location, or immediate value to the accumulator and store the
result in the accumulator.

Subtraction Instructions

SUB C ;A = A – C
SUB M ; A = A - (HL) Flag Effects:
SUI 0AH ; A = A - 0AH (immediate)
• Carry (CY): Set if result exceeds 8 bits
• Zero (Z): Set if result is zero
Subtraction instructions subtract the content of a register, memory
• Sign (S): Set if result is negative (bit 7 is 1)
location, or immediate value from the accumulator and store the
result in the accumulator. • Parity (P): Set if result has even parity
• Auxiliary Carry (AC): Set if carry from bit 3 to bit 4
ADC, SBB Instructions
ADC (Add with Carry)

ADC B ; A = A + B + CY
ADC M ; A = A + (HL) + CY
ACI 05H ; A = A + 05H + CY

ADC instructions add the source operand and the carry flag to the accumulator.
They're essential for multi-byte addition when performing calculations with
numbers larger than 8 bits.

SBB (Subtract with Borrow)

SBB C ; A = A - C – CY
SBB M ; A = A - (HL) – CY
SBI 0AH ; A = A - 0AH - CY
Multi-byte Addition Example
SBB instructions subtract the source operand and the carry flag (acting as
borrow) from the accumulator. They're used for multi-byte subtraction. ; Add 16-bit numbers in BC and DE, result in HLMOV A, C ; Get
low byte of first numberADD E ; Add low byte of second
numberMOV L, A ; Store low byte of resultMOV A, B ; Get high
byte of first numberADC D ; Add high byte + carryMOV H, A ;
Store high byte of result
INX, DCX, INR, DCR Instructions
INR DCR INX DCX
(Increment (Decrement (Increment (Decrement
Register/Mem Register/Mem Register Pair) Register Pair)
Increases the Decreases the
ory) ory)
Increases the Decreases the content of a content of a
content of a content of a register pair by 1 register pair by 1
register or register or
memory location memory location INX H ; HL DCX D ; DE
by 1 by 1 = HL + 1INX = DE - 1DCX
INR B ; B DCR C ; C B ; BC = SP ; SP =
= B + 1INR = C - 1DCR BC + 1 SP - 1
M ; (HL) = M ; (HL) =
(HL) + 1 (HL) - 1 Does not affect Does not affect
any flags any flags
Affects all flags Affects all flags
except CY except CY

These instructions are commonly used for loop counters, memory pointers, and array indexing in assembly programs.
DAA: Decimal Adjust Accumulator
Binary Coded Decimal (BCD) Operations
The DAA instruction adjusts the accumulator content after a BCD
addition to ensure the result remains in valid BCD format (each
nibble representing a decimal digit from 0-9).

When to use DAA:

• After performing addition (ADD, ADI, ADC, ACI) on BCD numbers


• To ensure each 4-bit nibble represents a valid decimal digit (0-9)

Example:

MVI A, 28H ; Load 28 BCD (not 28H)MVI B, 47H ; Load


47 BCD (not 47H)ADD B ; A = 28 + 47 = 6FH
The DAA instruction performs the following adjustments:
(invalid BCD)DAA ; Adjust to 75H (valid BCD
for 75) 1. If lower nibble > 9 or AC flag is set, add 06 to accumulator
2. If upper nibble > 9 or CY flag is set, add 60 to accumulator

DAA is essential for calculations involving decimal numbers in


financial, business, and scientific applications where exact decimal
representation is required.
Arithmetic Example: Two-Number Sum with Carry
Problem: Add two 16-bit numbers with carry handling

; Add 16-bit numbers in BC and DE; Store result in HL;


Store carry in A MVI A, 00H ; Clear accumulator
MOV L, A ; Clear L MOV H, A ; Clear H MOV
A, C ; Get low byte of first number ADD E ;
Add low byte of second number MOV L, A ; Store low
byte result MOV A, B ; Get high byte of first
number JNC SKIP ; Jump if no carry from low byte
INR A ; Increment if carry occurredSKIP: ADD D
; Add high byte of second number MOV H, A ; Store
high byte result MVI A, 00H ; Clear A JNC DONE
; Jump if no carry from high byte INR A ; Set
A=1 if carry occurredDONE: HLT ; Halt program

This program demonstrates:

• Multi-byte arithmetic with carry propagation


• Conditional branching based on flag status
• Careful register usage to preserve intermediate values

For larger numbers (24-bit, 32-bit, etc.), the same pattern can be
extended with additional bytes and carry handling.
Logic Operations Overview
Logic operations in the 8085 perform bit-wise manipulation of data, enabling programs to test,
set, clear, or modify individual bits in a byte. These operations are fundamental for tasks like
masking, bit testing, flag checking, and implementing Boolean logic.

Logical Operations
• AND (ANA) - Bitwise AND
• OR (ORA) - Bitwise OR
• XOR (XRA) - Bitwise Exclusive OR

Comparison
• CMP - Compare register/memory with A
• CPI - Compare immediate with A

Rotate Operations
• RLC/RRC - Rotate A left/right
• RAL/RAR - Rotate A through carry

Complement
• CMA - Complement (invert) accumulator
• CMC - Complement carry flag
ANA, XRA, ORA Instructions
Bitwise Logical Operations
ANA (AND with Accumulator)

ANA B ; A = A AND BANA M ; A = A AND (HL)ANI 0FH ; A = A AND


0FH (immediate)

Performs bit-by-bit AND operation. Useful for masking (clearing) bits.

XRA (XOR with Accumulator)

XRA C ; A = A XOR CXRA M ; A = A XOR (HL)XRI 55H ; A = A XOR


55H (immediate)

Performs bit-by-bit XOR operation. Useful for toggling bits and quick zero check. Common Applications:

ORA (OR with Accumulator) • AND: Isolate specific bits (e.g., ANI 0FH masks high nibble)
• OR: Set specific bits (e.g., ORI 80H sets the most significant bit)
ORA D ; A = A OR DORA M ; A = A OR (HL)ORI 80H ; A = A OR • XOR: Toggle bits or check for equality (XRA A clears accumulator)
80H (immediate)
All these operations clear the Carry and Auxiliary Carry flags, and affect Zero, Sign,
and Parity flags based on the result.

Performs bit-by-bit OR operation. Useful for setting bits.


CMP and CPI Instructions
Comparison Operations
CMP (Compare)

CMP B ; Compare A with register BCMP M ; Compare A with memory at (HL)

Compares the content of the accumulator with the specified register or memory location by performing a
subtraction (A - operand) but without storing the result.

CPI (Compare Immediate)

CPI 5AH ; Compare A with immediate value 5AH

Compares the accumulator with an immediate value using the same mechanism.

Flag Effects:

• Zero (Z): Set if A = operand


• Carry (CY): Set if A < operand (unsigned)
• Sign (S): Set if result is negative (A < operand for signed numbers)

Common Compare-and-Branch Patterns:

; Check if A equals BCMP BJZ EQUAL ; Jump if equal; Check if A less than CCMP CJC
LESS ; Jump if carry (A < C); Check if A greater than DCMP DJNZ NOT_EQUAL ; Must be
not equalJNC GREATER ; Jump if no carry (A ≥ D) ; If we get here, A = D
RAL, RAR, RLC, RRC (Rotate)

RLC (Rotate Left Circular) RRC (Rotate Right Circular) RAL (Rotate Left through Carry)
RAR (Rotate Right through Carry)
Rotates all bits in the Rotates all bits in the Rotates all bits in the Rotates all bits in the
accumulator one position to the accumulator one position to the accumulator one position to the accumulator one position to the
left. Bit 7 moves to bit 0 right. Bit 0 moves to bit 7 left through the Carry flag. Bit 7 right through the Carry flag. Bit
position, and also to the Carry position, and also to the Carry goes to Carry, and previous 0 goes to Carry, and previous
flag. flag. Carry goes to bit 0. Carry goes to bit 7.
RLC ; Rotate A left circular RRC ; Rotate A right circularRAL ; Rotate A left RAR ; Rotate A right
through carry through carry

Rotation operations are useful for serial data processing, multiplication/division by powers of 2, and bit manipulation tasks. Only the
Carry flag is affected; other flags remain unchanged.
Practical Logic Example
Example 1: Masking Lower Nibble

; Preserve only the lower nibble (bits 0-3) of AANI 0FH ; A = A AND 00001111b; Result: Upper nibble cleared,
lower nibble unchanged

Example 2: Setting Specific Bits

; Set bits 0 and 7 in accumulatorORI 81H ; A = A OR 10000001b; Result: Bits 0 and 7 are set to 1

Example 3: Checking if Value is Even or Odd

; Test if value in A is odd or evenANI 01H ; Isolate bit 0 (1 for odd, 0 for even)JZ EVEN ; Jump if zero
(bit 0 was 0 = even)JMP ODD ; Otherwise it's odd

Example 4: Toggling All Bits (Complement)

; Invert all bits in accumulatorCMA ; A = NOT A; Example: 01101100 becomes 10010011

Example 5: Swapping Nibbles

; Swap upper and lower nibbles in A; Example: Convert 12H (00010010b) to 21H (00100001b)MOV B, A ; Save a
copyRLC ; Rotate left 4 timesRLCRLCRLC ; Now upper nibble is in lower positionANI 0FH ; Mask to keep only the
moved nibbleMOV C, A ; Save in CMOV A, B ; Restore original valueANI 0FH ; Mask to keep only lower nibbleRLC ;
Rotate left 4 times to move to upper positionRLCRLCRLCORA C ; Combine with saved nibble; Result: Nibbles are
swapped
Branching Operations Overview
Branching operations alter the normal sequential flow of program execution,
allowing for decision-making, loops, and subroutine calls. These instructions
manipulate the Program Counter (PC) to direct execution to different parts
of the program.

Jump Instructions Call & Return


• Unconditional: JMP • CALL, RET - Unconditional
• Conditional: JZ, JNZ, JC, JNC, • Conditional: CZ/RZ,
JP, JM, JPE, JPO CNZ/RNZ, CC/RC, CNC/RNC

Restart
• RST 0 through RST 7
• Single-byte CALL to fixed addresses

Branching instructions are essential for implementing program control


structures like if-then-else statements, loops, and function calls in assembly
language.
JMP, JC, JNC, JZ, JNZ Instructions
Unconditional Jump

JMP LABEL ; Jump to memory address at LABEL

Transfers program execution to the specified address regardless of any conditions.

Conditional Jumps Based on Flags

JZ LABEL ; Jump if Zero flag is set (Z=1)JNZ LABEL ; Jump if Zero flag is not set
(Z=0)JC LABEL ; Jump if Carry flag is set (CY=1)JNC LABEL ; Jump if Carry flag is
not set (CY=0)JP LABEL ; Jump if Sign flag is not set (S=0, positive)JM LABEL ;
Jump if Sign flag is set (S=1, negative)JPE LABEL ; Jump if Parity flag is set (P=1,
even parity)JPO LABEL ; Jump if Parity flag is not set (P=0, odd parity)

Common Usage Patterns:

; If-Then structure CPI 10H ; Compare A with 10H JNZ NOT_EQUAL ; Jump if not equal ;
Code for "then" part JMP ENDIF ; Skip "else" partNOT_EQUAL: ; Code for "else"
partENDIF: ; Continue program; While loopLOOP: ; Loop body DCR B ; Decrement counter
JNZ LOOP ; Repeat if not zero
CALL, RET Instructions
Subroutine Operations
Subroutines are reusable blocks of code that can be called from different parts of a program. They help in
modular programming and code reuse.

CALL Instruction

CALL SUBROUTINE ; Call unconditionallyCZ SUBROUTINE ; Call if Zero flag setCNZ


SUBROUTINE ; Call if Zero flag not setCC SUBROUTINE ; Call if Carry flag setCNC
SUBROUTINE ; Call if Carry flag not set

CALL pushes the return address (PC) onto the stack and jumps to the subroutine address.

RET Instruction

RET ; Return unconditionallyRZ ; Return if Zero flag setRNZ ; Return if


Zero flag not setRC ; Return if Carry flag setRNC ; Return if Carry flag not
set

Subroutine Example:

RET pops the return address from the stack and jumps to that address.
; Main program MVI B, 05H ; Set parameter CALL DOUBLE ; Call subroutine MOV C,
A ; Save result HLT ; Halt; Subroutine to double a valueDOUBLE: MOV A,
B ; Get parameter ADD A ; Double it (A = A + A) RET ; Return
to caller

The stack is a LIFO (Last-In-First-Out) data structure in memory that keeps track of return addresses for
Practical Branching Example
16-bit Addition with Overflow Detection

; Add 16-bit numbers in BC and DE; Result in HL,


overflow indication in ASTART: MOV A, C ; Get low
byte of first number ADD E ; Add low byte of
second number MOV L, A ; Store low byte result
MOV A, B ; Get high byte of first number ADC D
; Add high byte + carry MOV H, A ; Store high
byte result MVI A, 00H ; Default: no overflow
(A=0) JNC NO_OVERFLOW ; Skip if no carry from high byte
MVI A, 01H ; Set overflow indicator (A=1)
NO_OVERFLOW: HLT ; Stop program

This example demonstrates:

• Conditional branching based on the Carry flag


• Multi-byte arithmetic with carry propagation
• Setting a status indicator based on a condition

The JNC instruction creates an efficient branch that only executes the
overflow handling code when necessary, optimizing program execution
for the common case (no overflow).
Looping and Iterative Constructs
Loop Implementation in Assembly
Loops in assembly language are created using a combination of:

1. Counter initialization
2. Loop body instructions
3. Counter modification (increment/decrement)
4. Conditional branch back to loop start

Common loop patterns include:

• Count-controlled loops (fixed number of iterations)


• Condition-controlled loops (while/until specific condition)
• Data-dependent loops (processing arrays until sentinel value)

Count-down Loop Example:

; Sum numbers from 1 to N (N in B) MVI A, 00H ; Initialize sum to 0 MOV C, B ; Copy


counter to C LOOP: ADD C ; Add current count to sum DCR C ; Decrement counter
JNZ LOOP ; Repeat until counter = 0 STA 2050H ; Store final sum HLT ; Halt
program
Restart and Trap Instructions
RST (Restart) Instructions TRAP and Interrupts
The 8085 provides eight 1-byte CALL instructions to fixed memory locations: The 8085 supports hardware interrupts that can trigger specific routines:

• TRAP: Highest priority, non-maskable interrupt


RST 0 0000H
• RST 7.5, 6.5, 5.5: Maskable interrupts with decreasing priority
RST 1 0008H • INTR: General-purpose maskable interrupt

RST 2 0010H When an interrupt occurs, the processor:

1. Completes the current instruction


RST 3 0018H
2. Saves the Program Counter on stack
RST 4 0020H 3. Jumps to the interrupt service routine
4. Returns using RET when service is complete
RST 5 0028H

RST 6 0030H

RST 7 0038H

RST instructions are efficient single-byte calls to predefined memory locations, often used for
common routines or interrupt handling.
I/O and Machine Control
Operations Overview
I/O and machine control operations allow the 8085 to interact with external devices and
manage the processor's internal state. These instructions provide mechanisms for data
exchange with peripherals and control over the processor's execution mode.

I/O Operations
IN and OUT instructions facilitate data exchange with external devices through
dedicated I/O ports, allowing the processor to read sensors, control displays, and
communicate with other hardware components.

Processor Control
Instructions like HLT (Halt), NOP (No Operation), and DI/EI (Disable/Enable
Interrupts) manage the processor's execution state, providing control over
program flow and interrupt handling.

Interrupt Management
SIM (Set Interrupt Mask) and RIM (Read Interrupt Mask) instructions provide
software control over the 8085's interrupt system, allowing programs to
selectively enable or disable specific interrupt sources.
IN, OUT Instructions for I/O
Input/Output Port Operations
The 8085 uses a separate address space for I/O devices, allowing for up to 256 input
ports and 256 output ports (addresses 00H to FFH).

IN Instruction

IN port_address ; Read from port to A ; Example: Read switch


statusIN 30H ; Read from port 30H into A

The IN instruction reads a byte from the specified port and places it in the accumulator.
This is used to get data from external devices like switches, keypads, ADCs, or
communication interfaces.

OUT Instruction

I/O Mapping Techniques:


OUT port_address ; Write from A to port ; Example: Control LED
displayMVI A, 7FH ; Pattern for LED displayOUT 40H ; Send 1. I/O-Mapped I/O: Uses separate address space and IN/OUT instructions
to port 40H
2. Memory-Mapped I/O: Treats devices as memory locations using standard
memory instructions

The 8085's architecture supports both approaches, with I/O-mapped I/O being more

The OUT instruction sends the content of the accumulator to the specified port, allowing efficient for simple devices and Memory-mapped I/O providing more flexibility for

control of external devices like LEDs, displays, motors, or communication interfaces. complex peripherals.
SIM, RIM Instructions
Interrupt Mask Control
The 8085 provides special instructions to manage its interrupt system:

SIM (Set Interrupt Mask)

This instruction allows software to:

• Enable/disable RST 7.5, 6.5, and 5.5 interrupts individually


• Reset pending RST 7.5 interrupt
• Send serial data output (SOD)

; Disable RST 7.5, enable RST 6.5 and 5.5MVI A, 08H ; Set bit 3, clear bits 0-2SIM
; Set interrupt mask

RIM (Read Interrupt Mask)


The accumulator bit format for SIM instruction:
This instruction reads:
• Bit 0: RST 7.5 mask (1=masked)
• Current interrupt mask status • Bit 1: RST 6.5 mask (1=masked)
• Pending interrupt flags • Bit 2: RST 5.5 mask (1=masked)
• Serial data input (SID) • Bit 3: Mask set enable (1=set masks)
• Bit 4: RST 7.5 flip-flop reset
RIM ; Read interrupt status into AANI 07H ; Mask to check interrupt • Bit 6: SOD data value
enable bitsCPI 07H ; Check if all interrupts are maskedJZ ALL_MASKED
• Bit 7: SOD output enable

These instructions provide software control over hardware interrupts, enabling


robust real-time systems and interrupt-driven I/O.
HLT, NOP, DI, EI, CMA Instructions

HLT (Halt) NOP (No Operation) DI (Disable Interrupts)


Stops program execution and puts the processor in Performs no operation but consumes one machine Disables all maskable interrupts (RST 7.5, 6.5, 5.5,
HALT state until an interrupt occurs. cycle. Used for timing delays or creating space for and INTR). TRAP remains active as it's non-
future code patches. maskable.
HLT ; Halt the processor DI ; Disable interrupts
NOP ; No operation (do nothing)
The processor remains in low-power mode with the
PC pointing to the instruction following HLT.

EI (Enable Interrupts) CMA (Complement Accumulator)


Enables all maskable interrupts that aren't Inverts all bits in the accumulator (1's complement).
individually masked by SIM instruction.
CMA ; Complement A (flip all bits)
EI ; Enable interrupts
Example: 01101100 becomes 10010011

These instructions provide essential control over processor operation, interrupt handling, and bit manipulation. They're often used in critical sections of code,
power management, timing sequences, and logical operations.
Machine Control Example
Input Processing with Controlled Shutdown

; Read input from port 80H until a specific value (FFH) is received; Process each valid
input and output result to port 40H; Gracefully shut down the system when doneSTART: EI
; Enable interrupts for external events WAIT_LOOP: IN 80H ; Read from
input port CPI FFH ; Is it the termination value? JZ SHUTDOWN ; If yes, prepare
to shut down ; Process the input value CPI 80H ; Check if value > 80H JNC
LARGE ; Jump if value is large ; Process small values ADD A ; Double the
value JMP OUTPUT ; Go to output section LARGE: ANI 0FH ; Mask to get lower
nibble only OUTPUT: OUT 40H ; Output the processed value JMP WAIT_LOOP ;
Continue waiting for inputSHUTDOWN: DI ; Disable interrupts before halting
MVI A, 00H ; Clear accumulator OUT 40H ; Turn off all outputs HLT ;
Halt the processor

This example demonstrates:

• Proper initialization with EI to enable interrupt-driven operation


• Continuous I/O polling with conditional processing
• Decision-making based on input values
• Graceful shutdown sequence with proper cleanup
• Use of DI to prevent interrupts during shutdown
• HLT to stop processor operation in a controlled manner

This pattern is common in embedded control systems where the processor must manage external devices and
respond to termination conditions.
Debugging and Common Errors
Assembler Errors
• Invalid mnemonics or operands
• Incorrect addressing modes
• Undefined labels or symbols
• Improper syntax in directives

Example: Using MOVE instead of MOV

Logic Errors
• Incorrect algorithm implementation
• Improper loop termination conditions
• Off-by-one errors in counting
• Stack overflow/underflow

Example: Using JZ when JNZ was needed

Data Errors
• Improper initialization of registers/memory
• Overwriting critical data accidentally
• Using incorrect constants or immediate values
• Confusing hexadecimal and decimal values

Example: Using MVI A, 10 (decimal) instead of MVI A, 10H (hex)

Flag Management Errors


• Forgetting flag affects from instructions
• Not checking correct flags after operations
• Instructions changing flags unexpectedly
• Relying on flags across multiple operations

Example: Assuming carry flag remains set after an AND operation

Debugging assembly programs typically involves using simulators with features like register viewing, memory inspection, breakpoints, and step-by-
step execution to trace program flow and identify issues. Tools like GNUSim8085 provide these capabilities for 8085 assembly debugging.
Conclusion & Further Resources
Key Takeaways Recommended Resources
Throughout this presentation, we've explored the fundamental aspects of 8085 To continue your learning journey with 8085 assembly:
assembly language programming:
• Books: "Microprocessor Architecture, Programming and Applications with the 8085"
• Data Transfer Operations: MOV, MVI, LDA, STA, LDAX, STAX, IN, OUT by Ramesh Gaonkar
• Arithmetic Operations: ADD, SUB, INR, DCR, ADC, SBB, DAA • Simulators: GNUSim8085, 8085sim, Virtual 8085
• Logic Operations: ANA, ORA, XRA, CMP, RLC, RRC, RAL, RAR • Practice Projects:
• Branching Operations: JMP, conditional jumps, CALL, RET, RST • LED display controllers
• I/O and Machine Control: IN, OUT, HLT, NOP, DI, EI, SIM, RIM • Simple calculators
• Digital clock implementation
Understanding these operations provides a solid foundation for embedded systems
programming, hardware interfacing, and low-level software development. • Data sorting and searching algorithms

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy