The 8085 Programming Model
The 8085 Microprocessor
The 8085 is an 8-bit microprocessor made by Intel.
It has:
2
6 general purpose registers An accumulator A flag register A stack pointer A program counter
Accumulator B D H
Flags C E L
Program Counter Stack Pointer
The 8085 Programming Model
The Registers The 6 general purpose registers are 8-bits wide each. They are to be used as needed. They are called B, C, D, E, H, and L. They can be used as 16-bit register pairs: BC, DE, HL.
The accumulator is technically part of the ALU. It is 8-bits wide. It is one of the inputs to every ALU operation. The result of any operation is always stored in it. It is known as Register A.
3
The 8085 Programming Model
The ALU includes five flag flip-flops that are set or reset after an operation.
They are Z (zero), CY (carry), S (sign), P (parity) and AC (Auxiliary Carry). These flags are used when the microprocessor tests for data conditions. These make up the Flags Register.
The 8085 Instructions
Since the 8085 is an 8-bit device it can have up to 28 (256) instructions. However, the 8085 only uses 246 combinations that represent a total of 74 instructions. Most of the instructions have more than one format.
These instructions can be grouped into five different groups: Data Transfer Operations Arithmetic Operations Logic Operations Branch Operations Machine Control Operations
5
Instruction and Data Formats
Each instruction has two parts.
The first part is the task or operation to be performed.
This part is called the opcode (operation code).
The second part is the data to be operated on
Called the operand.
Operand Types
There are different ways for specifying the operand: There may not be an operand (implied operand) CMA The operand may be an 8-bit number (immediate data) ADI 4FH The operand may be an internal register (register) SUB B The operand may be a 16-bit address (memory address) LDA 4000H
Instruction Size
Depending on the operand type, the instruction may have different sizes. It will occupy a different number of memory bytes. Typically, all instructions occupy one byte only. The exception is any instruction that contains immediate data or a memory address. Instructions that include immediate data use two bytes. One for the opcode and the other for the 8-bit data. Instructions that include a memory address occupy three bytes. One for the opcode, and the other two for the 168 bit address.
Instruction with Immediate Date
Operation: Load an 8-bit number into the accumulator.
MVI A, 32
Operation: MVI A Operand: The number 32 Binary Code:
0011 1110 0011 0010
3E 32
1st byte. 2nd byte.
Instruction with a Memory Address
Operation: go to address 2085.
Instruction: JMP 2085
Opcode: JMP Operand: 2085 Binary code:
1100 0011 C3 1000 0101 85 0010 0000 20
10
1st byte. 2nd byte 3rd byte
Addressing Modes
The microprocessor has different ways of specifying the data for the instruction. These are called addressing modes.
The 8085 has four addressing modes: Implied CMA Immediate MVI B, 45 Direct LDA 4000 Indirect LDAX B Load the accumulator with the contents of the memory location whose address is stored in the register pair BC).
11
Data Formats
In an 8-bit microprocessor, data can be represented in one of four formats: ASCII BCD Signed Integer Unsigned Integer. It is important to recognize that the microprocessor deals with 0s and 1s. It deals with values as strings of bits. It is the job of the user to add a meaning to these strings.
12
Data Formats
Assume the accumulator contains the following value: 0100 0001.
There are four ways of reading this value:
It is an unsigned integer expressed in binary, the equivalent decimal number would be 65. It is a number expressed in BCD (Binary Coded Decimal) format. That would make it, 41. It is an ASCII representation of a letter. That would make it the letter A. It is a string of 0s and 1s where the 0th and the 6th bits are set to 1 while all other bits are set to 0.
13
Detailed Review of the 8085 Instruction Set
8085 Instruction Set
The 8085 instructions can be classified as follows:
Data transfer operations
Between registers Between memory location and a register Direct write to a register / memory Between I/O device and accumulator
Arithmetic operations (ADD, SUB, INR, DCR) Logic operations Branching operations (JMP, CALL, RET)
8085 Instruction Types
8085 Instruction Types
8085 Instruction Types
Simple Data Transfer Operations
Examples: MOV MOV MVI B,A C,D D,47 47 4A 16 47 From ACC to REG Between two REGs Direct-write into REG D
Simple Data Transfer Operations
Example: OUT 05 D3 05
Contents of ACC sent to output port number 05.
Simple Memory Access Operations
Simple Memory Access Operations
Arithmetic Operations
Arithmetic Operations
Arithmetic Operations
Arithmetic Operations
Overview of Logic Operations
Logic Operations
Logic Operations
Logic Operations
Logic Operations
The Compare instructions compare the content of an 8-bit value with the contents of the accumulator CMP Compare CPI Compare Using Immediate Data The rotate instructions shift the contents of the accumulator one bit position to the left or right: RLC Rotate Accumulator Left RRC Rotate Accumulator Right RAL Rotate Left Through Carry RAR Rotate Right Through Carry Complement and carry flag instructions: CMA Complement Accumulator CMC Complement Carry Flag STC Set Carry Flag
Branching Operations
Note: This is an unconditional jump operation. It will always force the program counter to a fixed memory address continuous loop !
Branching Operations
Conditional jump operations are very useful for decision making during the execution of the program.
Example
Write a 8085 machine code program:
Read two different memory locations
Add the contents Send the result to output port 02 (display) if there is no overflow Display FF if there is an overflow Stop
Example
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 LDA 2050 3A 50 20 47 3A 51 20 80 D2 YY XX 3E FF D3 02 76
Load contents of memory location 2050 into accumulator
MOV LDA
B,A 2051
Save the first number in B Load contents of memory location 2051 into accumulator
ADD JNC
B XXYY
Add accumulator with B Jump to YYXX if no carry !
MVI
A,FF
Direct write FF into accumulator Display accumulator contents at output port 02 Stop
OUT
HLT
02
Updated Code
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 LDA 2050 3A 50 20 47 3A 51 20 80 D2 13 20 3E FF D3 02 76
Load contents of memory location 2050 into accumulator
MOV LDA
B,A 2051
Save the first number in B Load contents of memory location 2051 into accumulator
ADD JNC
B 2013
Add accumulator with B Jump to 2013 if no carry !
MVI
A,FF
Direct write FF into accumulator Display accumulator contents at output port 02 Stop
OUT
HLT
02