TK 2633 Microprocessor & Interfacing

27
Room: E-3-31 Phone: 03-8921 6726 [email protected] Dr Masri Ayob Dr Masri Ayob TK 2633 TK 2633 Microprocessor & Microprocessor & Interfacing Interfacing Lecture 1: Introduction to Lecture 1: Introduction to 8085 Assembly Language 8085 Assembly Language Programming (1) Programming (1)

description

TK 2633 Microprocessor & Interfacing. Lecture 1: Introduction to 8085 Assembly Language Programming (1). Objectives. Explain the various functions of the registers in the 8085 programming model. Define the term flag and explain how the flags are affected. - PowerPoint PPT Presentation

Transcript of TK 2633 Microprocessor & Interfacing

Page 1: TK 2633 Microprocessor & Interfacing

Room: E-3-31

Phone: 03-8921 6726

[email protected]

Dr Masri AyobDr Masri Ayob

TK 2633TK 2633Microprocessor & Interfacing Microprocessor & Interfacing

Lecture 1: Introduction to 8085 Lecture 1: Introduction to 8085 Assembly Language Programming Assembly Language Programming

(1)(1)

Page 2: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 22

ObjectivesObjectives

Explain the various functions of the registers in the 8085 Explain the various functions of the registers in the 8085 programming model.programming model.

Define the term flag and explain how the flags are affected.Define the term flag and explain how the flags are affected. Explain the terms operation code (Opcode) and the Explain the terms operation code (Opcode) and the

operand, and illustrate these terms by writing instructions.operand, and illustrate these terms by writing instructions. Classify the instructions in terms of their word size and Classify the instructions in terms of their word size and

specify the number of memory registers required to store specify the number of memory registers required to store the instructions in memory.the instructions in memory.

List the five categories of the 8085 instruction set.List the five categories of the 8085 instruction set. Define and explain the term addressing mode. Define and explain the term addressing mode.

Page 3: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 33

ObjectivesObjectives

Write logical steps to solve a simple Write logical steps to solve a simple programming problem.programming problem.

Draw a flowchart from the logical steps of a Draw a flowchart from the logical steps of a given programming problem.given programming problem.

Translate the flowchart into mnemonics and Translate the flowchart into mnemonics and convert the mnemonics into Hex code for a convert the mnemonics into Hex code for a given programming problem. given programming problem.

Page 4: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 44

The 8085 Hardware/Programming ModelThe 8085 Hardware/Programming Model

A model is a conceptual representation of A model is a conceptual representation of a real object. a real object.

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

Page 5: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 55

8085 Hardware Model8085 Hardware Model

Page 6: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 66

8085 Programming Model8085 Programming Model

Page 7: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 77

8085 Flag Register8085 Flag Register

Page 8: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 88

8085 Hardware Model8085 Hardware Model

Two major segments:Two major segments: One segment includes the arithmetic/logic unit (ALU) One segment includes the arithmetic/logic unit (ALU)

and an 8-bit register called an accumulator, and an 8-bit register called an accumulator, instruction decoder, and flags.instruction decoder, and flags.

The second segment shows 8-bit and 16-bit registers.The second segment shows 8-bit and 16-bit registers. Both segments are connected with various internal Both segments are connected with various internal

connections called an internal bus. connections called an internal bus. The arithmetic and logical operations are performed in The arithmetic and logical operations are performed in

the ALU. Results are stored in the accumulator, and the ALU. Results are stored in the accumulator, and flip-flops, called flags, are set or reset to reflect the flip-flops, called flags, are set or reset to reflect the results results

Page 9: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 99

8085 Hardware Model8085 Hardware Model

There are three buses: There are three buses: a 16-bit unidirectional address bus to send out a 16-bit unidirectional address bus to send out

memory addresses;memory addresses;an 8-bit bidirectional data bus, and a control an 8-bit bidirectional data bus, and a control

bus to transfer data, and.bus to transfer data, and. the control bus for timing signals. the control bus for timing signals.

Page 10: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1010

8085 Programming Model8085 Programming Model

The model includes six 8-bit registers (B, The model includes six 8-bit registers (B, C, D, E, H & L), one accumulator, and one C, D, E, H & L), one accumulator, and one flag register.flag register.

It also has two 16-bit registers: It also has two 16-bit registers: the stack pointer (SP);the stack pointer (SP); the program counter (PC). the program counter (PC).

Page 11: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1111

General-purpose RegistersGeneral-purpose RegistersThe 8085 has six general-purpose The 8085 has six general-purpose

registers to store 8-hit data; registers to store 8-hit data; B, C, D, E, H, and L.B, C, D, E, H, and L.

They can be combined as register pairs - They can be combined as register pairs - BC, DE, and HL - to perform some 16-bit BC, DE, and HL - to perform some 16-bit operations. operations.

The programmer can use these registers The programmer can use these registers to store or copy data into the registers by to store or copy data into the registers by using data copy instructions.using data copy instructions.

Page 12: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1212

AccumulatorAccumulator

The accumulator is an 8-bit register that is The accumulator is an 8-bit register that is part of the arithmetic/logic unit (ALU). part of the arithmetic/logic unit (ALU).

This register is used to store 8-bit data and This register is used to store 8-bit data and to perform arithmetic and logical to perform arithmetic and logical operations. operations.

The result of an operation is stored in the The result of an operation is stored in the accumulator. accumulator.

The accumulator is also identified as The accumulator is also identified as register A. register A.

Page 13: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1313

FlagsFlags

The ALU includes five flip-flops, which are set or reset The ALU includes five flip-flops, which are set or reset after an operation according to data conditions of the after an operation according to data conditions of the result in the accumulator and other registers. result in the accumulator and other registers.

They are called Zero (Z), Carry (CY), Sign (S), Parity (P), They are called Zero (Z), Carry (CY), Sign (S), Parity (P), and Auxiliary Carry (AC) flags; and Auxiliary Carry (AC) flags;

The most commonly used flags are Zero, Carry, and The most commonly used flags are Zero, Carry, and Sign. The microprocessor uses these flags to test data Sign. The microprocessor uses these flags to test data conditions.conditions.

These flags have critical importance in the decision-These flags have critical importance in the decision-making process of the microcessor.making process of the microcessor. E.g., the instruction JC (Jump On Carry) is implemented to E.g., the instruction JC (Jump On Carry) is implemented to

change the sequence of a program when the CY flag is set. change the sequence of a program when the CY flag is set.

Page 14: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1414

FlagsFlags The following flags are set or reset after the execution of an The following flags are set or reset after the execution of an

arithmetic or logic operation; arithmetic or logic operation; data copy instructions do not data copy instructions do not affect any flagsaffect any flags. See the instruction set (Appendix F) to find . See the instruction set (Appendix F) to find how flags are affected by an instruction.how flags are affected by an instruction. Z-Zero: The Zero flag is set to 1 when the result is zero; otherwise it Z-Zero: The Zero flag is set to 1 when the result is zero; otherwise it

is reset.is reset. CY - Carry: If an arithmetic operation results in a carry, the CY flag CY - Carry: If an arithmetic operation results in a carry, the CY flag

is set; otherwise it is reset.is set; otherwise it is reset. S - Sign: The Sign flag is set if bit DS - Sign: The Sign flag is set if bit D77 of the result = 1; otherwise it is of the result = 1; otherwise it is

reset.reset. P - Parity: If the result has an even number of 1s, the flag is set; for 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.an odd number of 1s, the flag is reset. AC - Auxiliary Carry: In an arithmetic operation, when a carry is AC - Auxiliary Carry: In an arithmetic operation, when a carry is

generated by digit Dgenerated by digit D33 and passed to digit D and passed to digit D44, the AC flag is set. This , the AC flag is set. This flag is used internally for BCD (binary-coded decimal) operations; flag is used internally for BCD (binary-coded decimal) operations; there is no Jump instruction associated with this flag.there is no Jump instruction associated with this flag.

Page 15: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1515

ExampleExample

Instruction: ADD B

Register contents before instruction

9A h

89 h

A

B

80 hFlag

Register contents after instruction:

23 h

89 h

A

B

10 hFlag

1 0 0 1 1 0 1 01 0 0 0 1 0 0 1

0 0 1 0 0 0 1 1

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

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

Page 16: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1616

Program COUNTER (PC) AND STACK Program COUNTER (PC) AND STACK POINTER (SP) POINTER (SP)

These are two 16-bit registers used to hold memory These are two 16-bit registers used to hold memory addresses.addresses.

PC:PC: The function of the PC is to point to the memory address from The function of the PC is to point to the memory address from

which the next byte is to be fetched. which the next byte is to be fetched. When a byte (machine code) is being fetched, the program When a byte (machine code) is being fetched, the program

counter is incremented by one to point to the next memory counter is incremented by one to point to the next memory location.location.

SP:SP: It points to a memory location in R/W memory, called the stack.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 The beginning of the stack is defined by loading a 16-bit address

in the stack pointer. in the stack pointer. The PC will automatically update when calling to /returning from The PC will automatically update when calling to /returning from

Subroutines.Subroutines.

Page 17: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1717

StackStack The stack is one of the most important things you must The stack is one of the most important things you must

know when programming. know when programming. Think of the stack as a deck of cards. When you put a card on 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 the deck, it will be the top card. Then you put another card, then another. another.

When you remove the cards, you remove them backwards, the When you remove the cards, you remove them backwards, the last card first and so on. last card first and so on.

The stack works the same way, you put The stack works the same way, you put (push)(push) words words (addresses or register pairs) on the stack and then remove (addresses or register pairs) on the stack and then remove (pop)(pop) them backwards. them backwards.

That's called LIFO, That's called LIFO, Last In First OutLast In First Out.. There are instructions that allow you to modify SP There are instructions that allow you to modify SP

contents but youcontents but you should NOT change the contents of should NOT change the contents of that register if you don't know what you're doing!that register if you don't know what you're doing! PUSH PUSH POP POP

Page 18: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1818

8085 Instruction Set8085 Instruction Set

An instruction is a binary pattern designed An instruction is a binary pattern designed inside a microprocessor to perform a inside a microprocessor to perform a specific function. specific function.

The entire group of instructions, called the The entire group of instructions, called the instruction set, determines what functions instruction set, determines what functions the microprocessor can perform. the microprocessor can perform.

Page 19: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 1919

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

8085 Instruction Set8085 Instruction Set

Page 20: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 2020

Copies data from a location called a Copies data from a location called a source to another location, called a source to another location, called a destination, without modifying the contents destination, without modifying the contents of the source. of the source.

In technical manuals, the term data In technical manuals, the term data transfer is used for this copying function. transfer is used for this copying function. The term transfer is misleading; it creates the The term transfer is misleading; it creates the

impression that the contents of a source are impression that the contents of a source are destroyed when, in fact, the contents are destroyed when, in fact, the contents are retained without any modification. retained without any modification.

Data Transfer (copy) InstructionsData Transfer (copy) Instructions

Page 21: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 2121

Data Transfer (copy) InstructionsData Transfer (copy) Instructions

Page 22: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 2222

Arithmetic OperationsArithmetic Operations These instructions perform arithmetic operations such as addition, These instructions perform arithmetic operations such as addition,

subtraction, increment, and decrement.subtraction, increment, and decrement. Addition - Any 8-bit number, or the contents of a register, or the 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 contents of a memory location can be added to the contents of the accumulator and the sum is stored in the accumulator. accumulator and the sum is stored in the accumulator. No two other 8-bit registers can be added directly (e.g., the contents of 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 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 instruction DAD is an exception; it adds 16-bit data directly in register pairs.pairs.

Subtraction - Any 8-bit number, or the contents of a register, or the 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 contents of a memory location can be subtracted from the contents of the accumulator and the results stored in the accumulator. the accumulator and the results stored in the accumulator. The subtraction is performed in 2’s complement, and the results, if The subtraction is performed in 2’s complement, and the results, if

negative, are expressed in 2’s complement. No two other registers can be negative, are expressed in 2’s complement. No two other registers can be subtracted directly.subtracted directly.

lncrementfDecrement - The 8-bit contents of a register or a memory lncrementfDecrement - The 8-bit contents of a register or a memory location can be incremented or decremented by 1.location can be incremented or decremented by 1. Similarly, the 16-bit contents of a register pair (such as BC) can be Similarly, the 16-bit contents of a register pair (such as BC) can be

incremented or decremented by I. These increment and decrement incremented or decremented by I. These increment and decrement operations differ from addition and subtraction in an important way; i.e., 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. they can be performed in any one of the registers or in a memory location.

Page 23: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 2323

Logical OperationsLogical Operations These instructions perform various logical operations with These instructions perform various logical operations with

the contents of the accumulator.the contents of the accumulator. AND, OR, Exclusive-OR - Any 8-bit number, or the AND, OR, Exclusive-OR - Any 8-bit number, or the

contents of a register, or of a memory location can be contents of a register, or of a memory location can be logically ANDed, ORed, or EXORed with the contents of logically ANDed, ORed, or EXORed with the contents of the accumulator. the accumulator. The results are stored in the accumulator.The results are stored in the accumulator.

Rotate - Each bit in the accumulator can be shifted either Rotate - Each bit in the accumulator can be shifted either left or right to the next position.left or right to the next position.

Compare - Any 8-bit number, or the contents of a register, Compare - Any 8-bit number, or the contents of a register, or a memory location can be compared for equality, or a memory location can be compared for equality, greater than, or less than, with the contents of the greater than, or less than, with the contents of the accumulator.accumulator.

Complement - The contents of the accumulator can be Complement - The contents of the accumulator can be complemented; all 0s are replaced by 1s and all 1s are complemented; all 0s are replaced by 1s and all 1s are replaced by 0s.replaced by 0s.

Page 24: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 2424

Branching OperationsBranching Operations This group of instructions alters the sequence of This group of instructions alters the sequence of

program execution either conditionally or program execution either conditionally or unconditionally:unconditionally: Jump - Conditional jumps are an important aspect of Jump - Conditional jumps are an important aspect of

the decision-making process in programming. These the decision-making process in programming. These instructions test for a certain condition (e.g., Zero or instructions test for a certain condition (e.g., Zero or Carry flag) and alter the program sequence when the Carry flag) and alter the program sequence when the condition is met. condition is met.

This set includes an instruction called unconditional jump.This set includes an instruction called unconditional jump. Call, Return, and Restart -These instructions Call, Return, and Restart -These instructions

change the sequence of a program either by change the sequence of a program either by calling a subroutine or returning from a calling a subroutine or returning from a subroutine. subroutine. The conditional Call and Return instructions also can The conditional Call and Return instructions also can

test condition flags.test condition flags.

Page 25: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 2525

Machine Control OperationsMachine Control OperationsThese instructions control machine These instructions control machine

functions such as Halt, Interrupt, or do functions such as Halt, Interrupt, or do nothing. nothing.

Page 26: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 2626

Review of the 8085 Operations Review of the 8085 Operations In data transfer, the contents of the source are not In data transfer, the contents of the source are not

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

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

Any register including memory can be used for Any register including memory can be used for increment and decrement.increment and decrement.

A program sequence can be changed either A program sequence can be changed either conditionally or by testing for a given data conditionally or by testing for a given data condition.condition.

Page 27: TK 2633 Microprocessor & Interfacing

Prepared by: Dr Masri AyobPrepared by: Dr Masri Ayob - TK2123 - TK2123 2727

Thank youThank youQ&AQ&A