37
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 (2) Programming (2)

TK 2633 Microprocessor & Interfacing

  • Upload
    colton

  • View
    64

  • Download
    3

Embed Size (px)

DESCRIPTION

TK 2633 Microprocessor & Interfacing. Lecture 1: Introduction to 8085 Assembly Language Programming (2). Instruction, Data Format, And Storage. Instruction is a command to the microprocessor to perform a given task on specified data. Each instruction has two parts: - PowerPoint PPT Presentation

Citation preview

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

(2)(2)

Page 2: TK 2633 Microprocessor & Interfacing

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

Instruction, Data Format, And StorageInstruction, Data Format, And Storage

Instruction is a command to the microprocessor to Instruction is a command to the microprocessor to perform a given task on specified data.perform a given task on specified data.

Each instruction has two parts: Each instruction has two parts: one is the task to be performed, called the operation one is the task to be performed, called the operation

code (op-code), code (op-code), the second is the data to be operated on, called the the second is the data to be operated on, called the

operand. operand. The operand (or data) can be specified in various ways. The operand (or data) can be specified in various ways. It may include 8-bit (or 16-bit) data, an internal register, a It may include 8-bit (or 16-bit) data, an internal register, a

memory location, or an 8-bit (or 16-bit) address. In some memory location, or an 8-bit (or 16-bit) address. In some instructions, the operand is implicit. instructions, the operand is implicit.

Page 3: TK 2633 Microprocessor & Interfacing

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

In the 8085, “byte” and “word” are In the 8085, “byte” and “word” are synonymous because it is an 8-bit synonymous because it is an 8-bit microprocessor.microprocessor.

However, instructions are commonly However, instructions are commonly referred to in terms of bytes rather than referred to in terms of bytes rather than words.words.1-byte instructions1-byte instructions2-byte instructions2-byte instructions3-byte instructions 3-byte instructions

Instruction, Data Format, And StorageInstruction, Data Format, And Storage

Page 4: TK 2633 Microprocessor & Interfacing

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

1-byte instructions1-byte instructions

It includes the opcode and the operand in It includes the opcode and the operand in the same byte. For example: the same byte. For example:

Page 5: TK 2633 Microprocessor & Interfacing

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

2-byte instructions2-byte instructions

The first byte specifies the operation code and The first byte specifies the operation code and the second byte specifies the operand. For the second byte specifies the operand. For example:example:

Page 6: TK 2633 Microprocessor & Interfacing

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

3-byte instructions3-byte instructions The first byte specifies the operation code and the following two The first byte specifies the operation code and the following two

bytes specify the 16-bit address.bytes specify the 16-bit address. The second byte is the low-order address and the third byte is the The second byte is the low-order address and the third byte is the

high-order address. high-order address. For example:For example:

Page 7: TK 2633 Microprocessor & Interfacing

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

Addressing ModesAddressing Modes

Instructions can be categorized according Instructions can be categorized according to their method of addressing the hardware to their method of addressing the hardware registers and/or memory. registers and/or memory. Implied AddressingImplied Addressing Register AddressingRegister Addressing Immediate AddressingImmediate AddressingDirect AddressingDirect AddressingRegister Indirect AddressingRegister Indirect AddressingCombined Addressing ModesCombined Addressing Modes. .

Page 8: TK 2633 Microprocessor & Interfacing

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

Implied AddressingImplied Addressing

The addressing mode of certain instructions The addressing mode of certain instructions is implied by the instruction’s function.is implied by the instruction’s function.For example:For example:

the STC (set carry flag) instruction deals only with the STC (set carry flag) instruction deals only with the carry flagthe carry flag

the DAA (decimal adjust accumulator) instruction the DAA (decimal adjust accumulator) instruction deals with the accumulator. deals with the accumulator.

Page 9: TK 2633 Microprocessor & Interfacing

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

Register AddressingRegister Addressing

Quite a large set of instructions call for register Quite a large set of instructions call for register addressing. addressing.

We must specify one of the registers A through E, H or L We must specify one of the registers A through E, H or L as well as the operation code. as well as the operation code.

The accumulator is implied as a second operand. The accumulator is implied as a second operand. For example, the instruction CMP E may be interpreted as For example, the instruction CMP E may be interpreted as

'compare the contents of the E register with the contents of the 'compare the contents of the E register with the contents of the accumulator.accumulator.

Most of the instructions that use register addressing deal Most of the instructions that use register addressing deal with 8-bit values. with 8-bit values.

However, a few of these instructions deal with 16-bit However, a few of these instructions deal with 16-bit register pairs. register pairs. For example, the PCHL instruction exchanges the contents of the For example, the PCHL instruction exchanges the contents of the

program counter with the contents of the H and L registers.program counter with the contents of the H and L registers.

Page 10: TK 2633 Microprocessor & Interfacing

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

Immediate AddressingImmediate Addressing

These instructions have data assembled as a part These instructions have data assembled as a part of the instruction itself. of the instruction itself. For example, the instruction CPI 'C' may be interpreted For example, the instruction CPI 'C' may be interpreted

as ‘compare the contents of the accumulator with the as ‘compare the contents of the accumulator with the letter C. letter C.

When assembled, this instruction has the hexadecimal value When assembled, this instruction has the hexadecimal value FE43. FE43.

Hexadecimal 43 is the internal representation for the letter C.Hexadecimal 43 is the internal representation for the letter C. When this instruction is executed, the processor fetches the When this instruction is executed, the processor fetches the

first instruction byte and determines that it must fetch one more first instruction byte and determines that it must fetch one more byte. byte.

The processor fetches the next byte into one of its internal The processor fetches the next byte into one of its internal registers and then performs the compare operation.registers and then performs the compare operation.

Page 11: TK 2633 Microprocessor & Interfacing

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

Direct AddressingDirect Addressing

These instructions require three bytes of These instructions require three bytes of storage: one for the instruction code, and storage: one for the instruction code, and two for the 16-bit address.two for the 16-bit address.

Example:Example:JMP 1000JMP 1000HH causes a jump to the hexadecimal causes a jump to the hexadecimal

address 1000address 1000HH by replacing the current by replacing the current

contents of the PC with the new value 1000contents of the PC with the new value 1000H.H.

Page 12: TK 2633 Microprocessor & Interfacing

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

Register Indirect AddressingRegister Indirect Addressing

These instructions reference memory via a These instructions reference memory via a register pair.register pair.

For example: For example: MOV M,CMOV M,C moves the contents of the C register into the moves the contents of the C register into the

memory address stored in the H and L register memory address stored in the H and L register pair. pair.

The instruction The instruction LDAX BLDAX B loads the loads the accumulator with the byte of data specified accumulator with the byte of data specified by the address in the B and C register pair by the address in the B and C register pair ..

Page 13: TK 2633 Microprocessor & Interfacing

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

Combined Addressing ModesCombined Addressing Modes

Some instructions use a combination of Some instructions use a combination of addressing modes. addressing modes. A CALL instruction, for example, combines A CALL instruction, for example, combines

direct addressing and register indirect direct addressing and register indirect addressing.addressing.

The direct address in a CALL instruction The direct address in a CALL instruction specifies the address of the desired subroutine; specifies the address of the desired subroutine;

the register indirect address is the stack the register indirect address is the stack pointer. The CALL instruction pushes the pointer. The CALL instruction pushes the current contents of the program counter into the current contents of the program counter into the memory location specified by the stack memory location specified by the stack pointer. pointer. ..

Page 14: TK 2633 Microprocessor & Interfacing

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

Timing Effects of Addressing ModesTiming Effects of Addressing Modes

Addressing modes affect both the amount of time required Addressing modes affect both the amount of time required for executing an instruction and the amount of memory for executing an instruction and the amount of memory required for its storage. required for its storage.

For example, instructions that use implied or register For example, instructions that use implied or register addressing, execute very quickly since they deal directly addressing, execute very quickly since they deal directly with the processor’s hardware or with data already present with the processor’s hardware or with data already present in hardware registers. in hardware registers. Most important, however is that the entire instruction can be Most important, however is that the entire instruction can be

fetched with a single memory access. The number of memory fetched with a single memory access. The number of memory accesses required is the single greatest factor in determining accesses required is the single greatest factor in determining execution timing.execution timing.

More memory accesses require more execution time. More memory accesses require more execution time. A CALL instruction for example, requires five memory accesses: A CALL instruction for example, requires five memory accesses:

three to access the entire instruction and two more to push the three to access the entire instruction and two more to push the contents of the program counter onto the stack. contents of the program counter onto the stack.

Page 15: TK 2633 Microprocessor & Interfacing

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

Data FormatData Format

The 8085 is an 8-bit microprocessor, and it The 8085 is an 8-bit microprocessor, and it processes only binary numbers. processes only binary numbers.

We need to code binary numbers into different We need to code binary numbers into different media. media.

Common codes and data formats are ASCII, Common codes and data formats are ASCII, BCD, signed integers, and unsigned integers:BCD, signed integers, and unsigned integers: ASCII Code - 7-bit alphanumeric code that represents ASCII Code - 7-bit alphanumeric code that represents

decimal numbers, English alphabets, and nonprintable decimal numbers, English alphabets, and nonprintable characters such as carriage return. Extended ASCII is characters such as carriage return. Extended ASCII is an 8-bit code. an 8-bit code.

BCD Code - Binary-coded decimal; it is used for BCD Code - Binary-coded decimal; it is used for decimal numbers. decimal numbers.

Page 16: TK 2633 Microprocessor & Interfacing

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

Data FormatData Format

Signed Integer - A signed integer is either a positive Signed Integer - A signed integer is either a positive number or a negative number. number or a negative number. In an 8-bit processor, the most significant digit, D7, is used for the In an 8-bit processor, the most significant digit, D7, is used for the

sign; 0 represents the positive sign and I represents the negative sign; 0 represents the positive sign and I represents the negative sign. sign.

The remaining seven bits, D6—D0, represent the magnitude of an The remaining seven bits, D6—D0, represent the magnitude of an integer. Therefore, the largest positive integer that can be integer. Therefore, the largest positive integer that can be processed by the 8085 at one time is 0111 1111 (7FH); the processed by the 8085 at one time is 0111 1111 (7FH); the remaining Hex numbers, 80H to FFH, are considered negative remaining Hex numbers, 80H to FFH, are considered negative numbers. numbers.

Unsigned Integers - An integer without a sign can be Unsigned Integers - An integer without a sign can be represented by all the 8 bits in a microprocessor register.represented by all the 8 bits in a microprocessor register. Therefore, the largest number that can be processed at one time is Therefore, the largest number that can be processed at one time is

FFFFHH. . However, this does not imply that the 8085 microprocessor is However, this does not imply that the 8085 microprocessor is

limited to handling only 8-bit numbers. Numbers larger than 8 bits limited to handling only 8-bit numbers. Numbers larger than 8 bits (such as 16-bit or 24-bit numbers) are processed by dividing them (such as 16-bit or 24-bit numbers) are processed by dividing them in groups of 8 bits.in groups of 8 bits.

Page 17: TK 2633 Microprocessor & Interfacing

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

How To Write, Assemble, And ExecuteHow To Write, Assemble, And Executea Simple Programa Simple Program

A program is a sequence of instructions A program is a sequence of instructions written to tell a computer to perform a written to tell a computer to perform a specific function. specific function.

The instructions are selected from the The instructions are selected from the instruction set of the microprocessor. instruction set of the microprocessor.

To write a program:To write a program:divide a given problem in small steps in terms divide a given problem in small steps in terms

of the operations the 8085 can perform;of the operations the 8085 can perform; then translate these steps into instructions.then translate these steps into instructions.

Page 18: TK 2633 Microprocessor & Interfacing

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

Example: Writing a simple programExample: Writing a simple program

PROBLEM STATEMENTPROBLEM STATEMENTWrite instructions to load the two hexadecimal Write instructions to load the two hexadecimal

numbers 32H and 48H in registers A and B, numbers 32H and 48H in registers A and B, respectively. respectively.

Add the numbers, and display the sum at the Add the numbers, and display the sum at the LED output port PORT.LED output port PORT.

Page 19: TK 2633 Microprocessor & Interfacing

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

Example: Writing a simple programExample: Writing a simple program

PROBLEM ANALYSISPROBLEM ANALYSIS1. Load the numbers in the registers.1. Load the numbers in the registers.2. Add the numbers.2. Add the numbers.3. Display the sum at the output port PORT.3. Display the sum at the output port PORT.

Page 20: TK 2633 Microprocessor & Interfacing

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

Example: Writing a simple programExample: Writing a simple program

Page 21: TK 2633 Microprocessor & Interfacing

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

Example: Writing a simple programExample: Writing a simple program

ASSEMBLY LANGUAGE PROGRAMASSEMBLY LANGUAGE PROGRAM To write an assembly language program, we need to To write an assembly language program, we need to

translate the blocks shown in the flowchart into 8085 translate the blocks shown in the flowchart into 8085 operations and then, subsequently, into mnemonics. operations and then, subsequently, into mnemonics.

By examining the blocks, we can classify them into By examining the blocks, we can classify them into three types of operations: Blocks 1 and 3 are copy three types of operations: Blocks 1 and 3 are copy (data transfer) instruction. (data transfer) instruction.

Block 2 is an arithmetic operation; Block 2 is an arithmetic operation; Block 4 is a machine-control operation. Block 4 is a machine-control operation. To translate these steps into assembly and machine To translate these steps into assembly and machine

languages, we should review the instruction set. languages, we should review the instruction set.

Page 22: TK 2633 Microprocessor & Interfacing

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

Example: Writing a simple programExample: Writing a simple program

Page 23: TK 2633 Microprocessor & Interfacing

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

Example: Writing a simple programExample: Writing a simple program

Page 24: TK 2633 Microprocessor & Interfacing

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

Example: Writing a simple programExample: Writing a simple program STORING IN MEMORY AND CONVERTING FROM HEX STORING IN MEMORY AND CONVERTING FROM HEX

CODE TO BINARY CODECODE TO BINARY CODE To store the program in R/W memory of a single-board To store the program in R/W memory of a single-board

microcomputer and display the output, we need to know microcomputer and display the output, we need to know the memory addresses and the output port address. the memory addresses and the output port address. Let us assume that R/W memory ranges from 2000H to 2OFFH, Let us assume that R/W memory ranges from 2000H to 2OFFH,

and the system has an LED output port with the address 01H. and the system has an LED output port with the address 01H. Now, to enter the program:Now, to enter the program:

Reset the system by pushing the RESET key.Reset the system by pushing the RESET key. Enter the first memory address using Hex keys where the program Enter the first memory address using Hex keys where the program

should be stored. Let us assume it is 2000H.should be stored. Let us assume it is 2000H. Enter each machine code by pushing Hex keys. For example, to enter Enter each machine code by pushing Hex keys. For example, to enter

the first machine code, push the 3, E, and STORE keys. (The STORE the first machine code, push the 3, E, and STORE keys. (The STORE key may be labeled differently in different systems).key may be labeled differently in different systems).

Repeat Step 3 until the last machine code, 76H.Repeat Step 3 until the last machine code, 76H. Reset the system.Reset the system.

Page 25: TK 2633 Microprocessor & Interfacing

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

Example: Writing a simple programExample: Writing a simple program

In this illustrative example, the program will be In this illustrative example, the program will be stored in memory as follows: stored in memory as follows:

Page 26: TK 2633 Microprocessor & Interfacing

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

Example: Writing a simple programExample: Writing a simple programEXECUTING THE PROGRAMEXECUTING THE PROGRAM

To execute the program, we need to tell the To execute the program, we need to tell the microprocessor where the program begins by microprocessor where the program begins by entering the memory address 2000H.entering the memory address 2000H.Now, we can push the Execute key (or the key with Now, we can push the Execute key (or the key with

a similar label) to begin the execution. a similar label) to begin the execution. As soon as the Execute function key is pushed, the As soon as the Execute function key is pushed, the

microprocessor loads 2000H in the program counter, microprocessor loads 2000H in the program counter, and the program control is transferred from the and the program control is transferred from the Monitor program to our program.Monitor program to our program.

The microprocessor begins to read one machine The microprocessor begins to read one machine code at a time, and when it fetches the complete code at a time, and when it fetches the complete instruction, it executes that instruction. instruction, it executes that instruction.

Page 27: TK 2633 Microprocessor & Interfacing

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

Overview Of The 8085 Instruction SetOverview Of The 8085 Instruction SetThe 8085 microprocessor instruction set The 8085 microprocessor instruction set

has 74 operation codes that result in 246 has 74 operation codes that result in 246 instructions. instructions.

The following notations are used in the The following notations are used in the description of the instructions:description of the instructions:

R = 8085 8-bit register (A,B,C,D,E,H,L)

M = Memory register (location)

Rs=Register source (A,B,C,D,E,H,L)

Rd=Register destination (A,B,C,D,E,H,L)

Rp=Register pair (BC,DE,HL,SP)

() = Contents of

Page 28: TK 2633 Microprocessor & Interfacing

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

Data Transfer (Copy) InstructionsData Transfer (Copy) InstructionsThese instruction perform the following 6 These instruction perform the following 6

operations:operations:Load an 8-bit registerLoad an 8-bit registerCopy from register to registerCopy from register to registerCopy between I/O and accumulatorCopy between I/O and accumulatorLoad 16-bit number in a register pairLoad 16-bit number in a register pairCopy between register and memoryCopy between register and memoryCopy between registers and stack memoryCopy between registers and stack memory

Page 29: TK 2633 Microprocessor & Interfacing

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

Data Transfer (Copy) InstructionsData Transfer (Copy) Instructions

Page 30: TK 2633 Microprocessor & Interfacing

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

Arithmetic InstructionsArithmetic InstructionsAddAddSubtractSubtract Increment (Add 1)Increment (Add 1)Decrement (Subtract 1)Decrement (Subtract 1)

Page 31: TK 2633 Microprocessor & Interfacing

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

Arithmetic InstructionsArithmetic Instructions

Page 32: TK 2633 Microprocessor & Interfacing

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

Logic and Bit Manipulation InstructionsLogic and Bit Manipulation InstructionsANDANDORORX-OR (Exclusive OR)X-OR (Exclusive OR)CompareCompareRotate BitsRotate Bits

Page 33: TK 2633 Microprocessor & Interfacing

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

Branch InstructionsBranch Instructions

Page 34: TK 2633 Microprocessor & Interfacing

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

Machine Control InstructionsMachine Control InstructionsThese instructions affect the operation of These instructions affect the operation of

the processor.the processor.HLT Stop processing and waitHLT Stop processing and waitNOP Do not perform any operationNOP Do not perform any operation

Page 35: TK 2633 Microprocessor & Interfacing

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

Common ErrorsCommon Errors LDA 205lH: Not entering the code of the 16-bit LDA 205lH: Not entering the code of the 16-bit

address in reversed order.address in reversed order. Forgetting to enter the code for the operand, such Forgetting to enter the code for the operand, such

as 205lH.as 205lH. MOV B, A: Assuming that this copies from B to A.MOV B, A: Assuming that this copies from B to A. Incrementing the address in decimal, from 2039H Incrementing the address in decimal, from 2039H

to 2040H.to 2040H. HLT: Not terminating a program.HLT: Not terminating a program. Confusing the entering of Hex code in memory as Confusing the entering of Hex code in memory as

executing a program. executing a program.

Page 36: TK 2633 Microprocessor & Interfacing

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

SummarySummary The 8085 microprocessor operations are classified into The 8085 microprocessor operations are classified into

five major groups: data transfer (copy), arithmetic, logic, five major groups: data transfer (copy), arithmetic, logic, branch, and machine control.branch, and machine control.

An instruction has two parts:An instruction has two parts: opcode (operation to be performed) opcode (operation to be performed) operand (data to be operated on) - The operand can be data (8- or operand (data to be operated on) - The operand can be data (8- or

16-bit), address, or register, or it can be implicit. 16-bit), address, or register, or it can be implicit. The method of specifying an operand (directly, indirectly, The method of specifying an operand (directly, indirectly,

etc.) is called the etc.) is called the addressing modeaddressing mode.. The instruction set is classified in three groups according The instruction set is classified in three groups according

to the word size: 1-, 2-, or 3-byte instructions.to the word size: 1-, 2-, or 3-byte instructions. To write an assembly language program, divide the given To write an assembly language program, divide the given

problem into small steps in terms of the microprocessor problem into small steps in terms of the microprocessor operations, translate these steps into assembly language operations, translate these steps into assembly language instructions, and then translate them into the 8085 instructions, and then translate them into the 8085 machine code. machine code.

Page 37: TK 2633 Microprocessor & Interfacing

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

Thank youThank youQ&AQ&A