Vous êtes sur la page 1sur 37

TK 2633 Microprocessor & Interfacing

Lecture 2: Introduction to 8085 Assembly Language Programming (2)


Prepared By: Associate Prof. Dr Masri Ayob

Objectives
Explain the various functions of the registers in the 8085 programming model. Define the term flag and explain how the flags are affected. Explain the terms operation code (Opcode) and the operand, and illustrate these terms by writing instructions.

Prepared by: Dr Masri Ayob

Objectives
Classify the instructions in terms of their word size and specify the number of memory registers required to store the instructions in memory. List the five categories of the 8085 instruction set. Define and explain the term addressing mode.

Prepared by: Dr Masri Ayob

Objectives
Write logical steps to solve a simple programming problem. Draw a flowchart from the logical steps of a given programming problem. Translate the flowchart into mnemonics and convert the mnemonics into Hex code for a given programming problem.

Prepared by: Dr Masri Ayob

The 8085 Hardware/Programming Model

A model is a conceptual representation of a real object. The microprocessor can be represented in terms of its hardware (physical electronic components) and a programming model (information needed to write programs).

Prepared by: Dr Masri Ayob

8085 Hardware Model

Prepared by: Dr Masri Ayob

8085 Programming Model

Prepared by: Dr Masri Ayob

8085 Flag Register

Prepared by: Dr Masri Ayob

8085 Hardware Model


Two major segments:
One segment includes the arithmetic/logic unit (ALU) and an 8-bit register called an accumulator, instruction decoder, and flags. The second segment shows 8-bit and 16-bit registers. Both segments are connected with various internal connections called an internal bus. The arithmetic and logical operations are performed in the ALU. Results are stored in the accumulator, and flip-flops, called flags, are set or reset to reflect the results
Prepared by: Dr Masri Ayob 9

8085 Hardware Model


There are three buses:
a 16-bit unidirectional address bus to send out memory addresses; an 8-bit bidirectional data bus, and a control bus to transfer data, and. the control bus for timing signals.
The programming model consist of some segments of ALU and the registers .The model includes six registers,one acumulator,one flag register.In addition to it,it has two 16 bit registers,the sack pointer and the program counter.

Prepared by: Dr Masri Ayob

10

8085 Programming Model


The model includes six 8-bit registers (B, C, D, E, H & L) and they ca be combined as register pairs BC,DE,HL to perform some 16 bit operations.one accumulator, and one flag register. It also has two 16-bit registers:
the stack pointer (SP); the program counter (PC).

Prepared by: Dr Masri Ayob

11

General-purpose Registers
The 8085 has six general-purpose registers to store 8-hit data;
B, C, D, E, H, and L.

They can be combined as register pairs - BC, DE, and HL - to perform some 16-bit operations. The programmer can use these registers to store or copy data into the registers by using data copy instructions.

Prepared by: Dr Masri Ayob

12

Accumulator
The accumulator is an 8-bit register that is part of the arithmetic/logic unit (ALU). This register is used to store 8-bit data and to perform arithmetic and logical operations. The result of an operation is stored in the accumulator. The accumulator is also identified as register A.

Prepared by: Dr Masri Ayob

13

Flags
The ALU includes five flip-flops, which are set or reset after an operation according to data conditions of the result in the accumulator and other registers. They are called Zero (Z), Carry (CY), Sign (S), Parity (P), and Auxiliary Carry (AC) flags;

Prepared by: Dr Masri Ayob

14

Flags
The most commonly used flags are Zero, Carry, and Sign. The microprocessor uses these flags to test data conditions. These flags have critical importance in the decision-making process of the microcessor.
E.g., the instruction JC (Jump On Carry) is implemented to change the sequence of a program when the CY flag is set.

Prepared by: Dr Masri Ayob

15

Flags
The following flags are set or reset after the execution of an arithmetic or logic operation; data copy instructions do not affect any flags. See the instruction set (Appendix F) to find how flags are affected by an instruction.
Z-Zero: The Zero flag is set to 1 when the result is zero; otherwise it is reset. CY - Carry: If an arithmetic operation results in a carry, the CY flag is set; otherwise it is reset.

Prepared by: Dr Masri Ayob

16

Flags
S - Sign: The Sign flag is set if bit D7 of the result = 1; otherwise it is reset. P - Parity: If the result has an even number of 1s, the flag is set; for an odd number of 1s, the flag is reset. AC - Auxiliary Carry: In an arithmetic operation, when a carry is generated by digit D3 and passed to digit D4, the AC flag is set. This flag is used internally for BCD (binary-coded decimal) operations; there is no Jump instruction associated with this flag.

Prepared by: Dr Masri Ayob

17

Example
Instruction:

ADD B
Register contents after instruction:
A B Flag
1001 1010 1000 1001 0010 0011

Register contents before instruction


A B Flag 9A h 89 h 80 h

23 h 89 h 10 h

Note: All flags are modified to reflect the result of the addition.

Flag: S=0, Z=0, AC=1 , P=0 and C=1,


Prepared by: Dr Masri Ayob 18

Program COUNTER (PC) AND STACK POINTER (SP)


These are two 16-bit registers used to hold memory addresses. PC:
The function of the PC is to point to the memory address from which the next byte is to be fetched. When a byte (machine code) is being fetched, the program counter is incremented by one to point to the next memory location.

Prepared by: Dr Masri Ayob

19

Program COUNTER (PC) AND STACK POINTER (SP)


SP:
It points to a memory location in R/W memory, called the stack. The beginning of the stack is defined by loading a 16-bit address in the stack pointer. The PC will automatically update when calling to /returning from Subroutines.

Prepared by: Dr Masri Ayob

20

Stack
The stack is one of the most important things you must know when programming.
Think of the stack as a deck of cards. When you put a card on the deck, it will be the top card. Then you put another card, then another. When you remove the cards, you remove them backwards, the last card first and so on. The stack works the same way, you put (push) words (addresses or register pairs) on the stack and then remove (pop) them backwards. That's called LIFO, Last In First Out.

Prepared by: Dr Masri Ayob

21

Stack
There are instructions that allow you to modify SP contents but you should NOT change the contents of that register if you don't know what you're doing!
PUSH POP

Prepared by: Dr Masri Ayob

22

8085 Instruction Set


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.

Prepared by: Dr Masri Ayob

23

8085 Instruction Set


Can be classified into the following five functional categories:
data transfer (copy) operations, arithmetic operations, logical operations, branching operations, and machine-control operations.

Prepared by: Dr Masri Ayob

24

Data Transfer (copy) Instructions


Copies 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.
The term transfer is misleading; it creates the impression that the contents of a source are destroyed when, in fact, the contents are retained without any modification.

Prepared by: Dr Masri Ayob

25

Data Transfer (copy) Instructions

Prepared by: Dr Masri Ayob

26

Arithmetic Operations
These instructions perform arithmetic operations such as addition, subtraction, increment, and decrement. Addition - Any 8-bit number, or the contents of a register, or the contents of a memory location can be added to the contents of the accumulator and the sum is stored in the accumulator.
No two other 8-bit registers can be added directly (e.g., the contents of register B cannot be added directly to the contents of register C). The instruction DAD is an exception; it adds 16-bit data directly in register pairs.
Prepared by: Dr Masri Ayob 27

Arithmetic Operations
Subtraction - Any 8-bit number, or the contents of a register, or the contents of a memory location can be subtracted from the contents of the accumulator and the results stored in the accumulator. The subtraction is performed in 2s complement, and the results, if negative, are expressed in 2s complement. No two other registers can be subtracted directly.

Prepared by: Dr Masri Ayob

28

Arithmetic Operations
Lncrement/Decrement - The 8-bit contents of a register or a memory location can be incremented or decremented by 1. Similarly, the 16-bit contents of a register pair (such as BC) can be incremented or decremented by I. These increment and decrement operations differ from addition and subtraction in an important way; i.e., they can be performed in any one of the registers or in a memory location.

Prepared by: Dr Masri Ayob

29

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 EXORed 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.

Prepared by: Dr Masri Ayob

30

Logical Operations
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.

Prepared by: Dr Masri Ayob

31

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 programming. These instructions test for a certain condition (e.g., Zero or Carry flag) and alter the program sequence when the condition is met. This set includes an instruction called unconditional jump.

Prepared by: Dr Masri Ayob

32

Branching Operations
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.

Prepared by: Dr Masri Ayob

33

Machine Control Operations


These instructions control machine functions such as Halt, Interrupt, or do nothing.

Prepared by: Dr Masri Ayob

34

Review of the 8085 Operations


In data transfer, the contents of the source are not destroyed; only the contents of the destination are changed.
The data copy instructions do not affect the flags.

Arithmetic and logical operations are performed with the contents of the accumulator, and the results are stored in the accumulator (with some exceptions).
The flags are affected according to the results.

Prepared by: Dr Masri Ayob

35

Review of the 8085 Operations


Any register including memory can be used for increment and decrement. A program sequence can be changed either conditionally or by testing for a given data condition.

Prepared by: Dr Masri Ayob

36

Thank you Q&A

37

Vous aimerez peut-être aussi