Вы находитесь на странице: 1из 35

Microprocessor System

LECTURE NO: 02

By: Engr. Humair Narejo


Overview Of 8080/8085 Programming
Model
To the programmer, the computer comprises the following parts:
• Memory
• The program counter
• Work registers
• Condition flags
• The stack and stack pointer
• Input/output ports
• The instruction set
Overview Of 8080/8085 Programming
Model
Memory
Since the program required to drive a microprocessor resides 'in memory, all microprocessor
applications require some memory. There are two general types of memory:
read only memory (ROM) and random access memory (RAM).
Program Counter
The program Counter keeps track of the next instruction byte to be fetched from memory (which
may be either ROM or RAM).
Each time It fetches an instruction byte from memory.
the processor increments the program counter by on".
Therefore, the program counter always indicates the next byte to be fetched
Work Registers
The 8080 provides an 8-bit accumulator and six other general purpose work registers.
Programs reference these registers by the letters A (for the accumulator), B, C, D, E, H, and L.
Thus, the Instruction ADD B may be interpreted as 'add the contents of the B register to the
contents of the accumulator.
Some instructions reference a pair of registers as shown in the following:
Symbolic Reference Registers Referenced
B B and C
D D and E
H H and L
PSW Flag
M H and L as a memory reference
Example
The MOV M,C moves a copy of the contents of register C to the memory location specified by
the H and L registers. Notice that this location must be in RAM since data is to be written to
memory,
Condition Flags
The 8080 provides five flip flops used as condition flags.
Certain arithmetic and logical instructions alter one or more of these flags to indicate the result
of an operation.

Your program can test the setting of four of these flags ( sign, zero, auxiliary carry, parity, and
carry.)
This allows you to alter the flow of program execution based on the outcome of a previous
operation.
Condition Flags
Carry Flag
As Its name it implies, the carry flag IS commonly used to Indicate whether an addition causes a 'carry'
into the next higher 01 del' digit. The carry flag IS also used as a 'borrow' flag In subtractions.
Example:
Addition of Two one-byte numbers can produce a carry out of the high-order bit:
Bit Number: AE= +74=
7654 3210
1010 1110
0111 01 00
0010 001 0 = 22 carry flag = 1
An addition that causes a carry out of the high order bit sets the carry flag to 1, an addition that does not
cause a carry resets the flag to zero.
Condition Flags
Sign Flag
Instructions that affect the sign flag set the flag equal to bit 7. A zero In bit 7 indicates a positive
value; a one indicates a negative value.
Condition Flags
Zero Flag
Certain Instructions set the zero flag to one to indicate that the result in the accumulator
contains all zeros. These instructions reset the flag to zero if the result in the accumulator is
other than zero. A result that has a carry and a zero result also sets the zero bit as shown below:
1010 0111
+0101 1001
0000 0000
Carry Flag = 1 Zero Flag = 1
Condition Flags
Parity Flag
Parity IS determined by counting the number of one bits set in the result in the accumulator.
Instructions that affect the parity flag set the flag to one for even parity and reset the flag to
zero to indicate odd parity.
Condition Flags
Auxiliary Carry Flag
The auxiliary carry flag indicates a carry out of bit 3 of the accumulator. You cannot test this flag
directly in your program; it is present to enable the DAA (Decimal Adiust Accumulator) to
perform its function.
The auxiliary carry flag and the DAA instruction allow you to treat the value in the accumulator
as two 4-bit binary coded decimal numbers. Thus, the value 0001 1001 is equivalent to 19. (If
this value is interpreted as a binary number, it has the value 25.)
0001 1001
+00000001
0001 1010 = lA
Stack and Stack Pointer
To understand the purpose and effectiveness of the stack, it is useful to understand the concept
of a subroutine.
Assume that !our program requires a multiplication routine. (Since the 8080 has no multiply
instructions, this can be performed through repetitive addition. For example, 3x4 is equivalent
to 3+3+3+3.)
Assume further that your program needs this multiply routine several times. You can recode this
routine inline each time it is needed, but this can use a great deal of memory. Or, you can code a
subroutine:
The 8080 provides instructions that call and return from a subroutine. When the call instruction
is executed, the address of the next instruction (the contents of the program counter) IS pushed
onto the stack.
Input/Output Ports
The 256 input/output ports provide communication with the outside world of peripheral
devices. The IN and
OUT instructions initiate data transfers.
The IN instruction latches the number of the desired port onto the address bus. As 500n as a
byte of data 15
returned to the data bus latch, it is transferred into the accumulator.
The OUT instruction latches the number of the desired port onto the address bus and latches
the data in the
accumulator onto the data bus.
The 8085 Addressing Modes
The instructions MOV B, A or MVI A, 82H are to copy data from a source into a destination. In
these instructions the source can be a register, an input port, or an 8-bit number (00H to FFH).
Similarly, a destination can be a register or an output port. The sources and destination are
operands. The various formats for specifying operands are called the ADDRESSING MODES. For
8085, they are:
1. Implied addressing.
2. Register addressing.
3. Immediate addressing.
4. Direct addressing.
5. Register Indirect addressing.
Addressing Modes
Implied Addressing:
The addressing mode of certain Instructions is implied by the instruction's function.
For example,
the STC (set carry flag) instruction deals only with the carry flag;
the DAA (decimal adjust accumulator) instruction deals with the accumulator.
Addressing Modes
Register addressing:
Data is provided through the registers.
Example: MOV Rd, Rs
ADD C
ACC 0000 0111 0000 1111 ACC
Before Operation + After Operation
Register C 0000 1000 0 0 - 0 - 1 - 0 Flags
S Z A P C
C
Addressing Modes
Immediate addressing:
Data is present in the instruction.
Load the immediate data to the destination provided.
Example: MVI R,data, ADI C6H(add immediate C6)
ACC 0000 1100 0001 0100 ACC
Before Operation + After Operation
M 0000 1000(C6) 0 0 - 1 - 1 - 0 Flags
S Z A P C
C
Addressing Modes
Direct addressing:
Used to accept data from outside/Memory Location to store in the accumulator
or send the data stored in the accumulator to the outside/ Memory location. LDA 0200H

Op Code 3AH(load A 0201H


Direct) 1111 1111
Low order
1111 1111 0200H Accumulator
byte of add: 0000 0000
High order
byte of add: 0000 0010

Program
Memory 0000 0010 0000 0000
Addressing Modes
Register Indirect addressing:
Register indirect instruction reference memory using the content of a register pair to point to
the address of the operand.
ADD M
ACC 1111 1111 0000 0000 ACC
Before operation + After Operation
0000 0001
Data M(2050H) 0 1 - 1 - 1 - 1 Flags
S Z A P C
HL Pair 2050H C
First Generation Programming Language
The First-Generation Programming Language (1GL) is machine code or machine language.
Machine language is a language which is directly understood by a computer.
It is also called binary language as it is based on 0s or 1s.
Any instruction in machine language is represented in terms of 0’s and 1’s, even the memory
addresses are given in binary mode.
Programs in machine language are very difficult to read and understand as binary codes of each
command cannot easily be remembered.
So it is very difficult and complicated to write the computer program in machine language.
Second Generation Programming
Language
The Second-Generation Programming Language (2GL) is assembly language.
Assembly language was first developed in the 1950s and it is different for different
microprocessors.
It was the first step to improve the computer programming.
For writing the programs in assembly language it is necessary that the programmers should have
the knowledge of machine hardware(Programming Model).
Representation is usually defined by the hardware manufacturer, and is based on abbreviations
(called mnemonics) that help the programmer remember individual instructions, registers, etc.
Second Generation Programming
Language
An opcode is a symbolic name for a single executable machine language instruction,
and there is at least one opcode mnemonic defined for each machine language instruction.
Each instruction typically consists of an operation or opcode plus zero or more operands.
A typical assembly language statement of 8080A or 8085 microprocessor written by the
programmer is given below, which is divided in to four fields namely, Label, Mnemonics or
Operation code (Opcode), Operand and comments.
Label Mnemonics Operand Comments
START: LXI H, 2500 H ; Initialize H-L register pair
Instruction Set Classification
An instruction is a binary pattern designed inside a microprocessor to perform a specific
function.
The entire group of instructions, called the instruction set,
determines what functions the microprocessor can perform.
These instructions can be classified into the following five functional categories:
data transfer (copy) operations,
arithmetic operations,
logical operations,
branching operations,
and machine-control operations.
Data Transfer (Copy) Operations
This group of instructions copy data from a location called a source to another location called a
destination, without modifying the contents of the source. In technical manuals, the term data
transfer is used for this copying function.
Arithmetic Operations
These instructions perform arithmetic operations such as addition, subtraction, increment, and
decrement.
Logical Operations
These instructions perform various logical operations with the contents of the accumulator.
AND, OR Exclusive-OR - Any 8-bit number, or the contents of a register, or of a memory location
can be logically ANDed, Ored, or Exclusive-ORed with the contents of the accumulator. The
results are stored in the accumulator.
Rotate- Each bit in the accumulator can be shifted either left or right to the next position.
Compare- Any 8-bit number, or the contents of a register, or a memory location can be
compared for equality, greater than, or less than, with the contents of the accumulator.
Complement - The contents of the accumulator can be complemented. All 0s are replaced by 1s
and all 1s are replaced by 0s.
Branching Operations
This group of instructions alters the sequence of program execution either conditionally or
unconditionally.
Jump - Conditional jumps are an important aspect of the decision-making process in the
programming. These instructions test for a certain conditions (e.g., Zero or Carry flag) and alter
the program sequence when the condition is met. In addition, the instruction set includes an
instruction called unconditional jump.
Call, Return, and Restart - These instructions change the sequence of a program either by calling
a subroutine or returning from a subroutine. The conditional Call and Return instructions also
can test condition flags.
Instruction Format
An instruction is a command to the microprocessor to perform a given task on a specified data.
Each instruction has two parts: one is task to be performed, called the operation code
(opcode), and the second is the data to be operated on, called the operand.
The operand (or data) can be specified in various ways.
It may include 8-bit (or 16-bit ) data, an internal register, a memory location, or 8-bit (or 16-bit)
address.
In some instructions, the operand is implicit.
Instruction Format
Instruction word size
The 8085 instruction set is classified into the following three groups according to word size:
1. One-word or 1-byte instructions
2. Two-word or 2-byte instructions
3. Three-word or 3-byte instructions
In the 8085, "byte" and "word" are synonymous because it is an 8-bit microprocessor. However,
instructions are commonly referred to in terms of bytes rather than words.
Instruction Format
One-Byte Instructions
A 1-byte instruction includes the opcode and operand in the same byte. Operand(s) are internal
register and are coded into the instruction. For example:
Instruction Format
Two-Byte Instructions
In a two-byte instruction, the first byte specifies the operation code and the second byte
specifies the operand. Source operand is a data byte immediately following the opcode. For
example:
Instruction Format
Three-Byte Instructions
In a three-byte instruction, the first byte specifies the opcode, and the following two bytes
specify the 16-bit address. Note that the second byte is the low-order address and the third byte
is the high-order address. opcode + data byte + data byte

Вам также может понравиться