Upload
michiemar
View
235
Download
0
Embed Size (px)
Citation preview
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 1/43
TK 2633
Microprocessor & Interfacing
Lecture 3: Introduction to 8085 Assembly Language Programming
(2)
1
Prepared By: Associate Prof. Dr Masri Ayob
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 2/43
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:
• one is the task to be performed, called the operation
code (op-code),• 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 an 8-bit (or 16-bit)
address. In some instructions, the operand is
implicit.Prepared by: Dr Masri Ayob 2
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 3/43
Instruction, Data Format, And Storage
In the 8085, “byte” and “word” are synonymousbecause it is an 8-bit microprocessor.
However, instructions are commonly referred to in
terms of bytes rather than words.
• 1-byte instructions
• 2-byte instructions
• 3-byte instructions
Prepared by: Dr Masri Ayob 3
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 4/43
1-byte instructions
It includes the opcode and the operand in thesame byte. For example:
Prepared by: Dr Masri Ayob - TK21234
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 5/43
2-byte instructions
The first byte specifies the operation code andthe second byte specifies the operand. For
example:
Prepared by: Dr Masri Ayob - TK21235
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 6/43
3-byte instructions
The first byte specifies the operation code and the
following two bytes specify the 16-bit address.The second byte is the low-order address and the
third byte is the high-order address.
For example:
Prepared by: Dr Masri Ayob – TK26336
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 7/43
Addressing Modes
Instructions can be categorized according to theirmethod of addressing the hardware registers
and/or memory.
• Implied Addressing
• Register Addressing• Immediate Addressing
• Direct Addressing
• Register Indirect Addressing
• Combined Addressing Modes.
Prepared by: Dr Masri Ayob 7
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 8/43
Implied Addressing
The addressing mode of certain instructions isimplied 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.
Prepared by: Dr Masri Ayob 8
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 9/43
Register Addressing
Quite a large set of instructions call for registeraddressing.
We must specify one of the registers A through E,
H or L as well as the operation code.
The accumulator is implied as a second operand.
• For example, the instruction CMP E may be
interpreted as 'compare the contents of the E
register with the contents of the accumulator.
Prepared by: Dr Masri Ayob 9
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 10/43
Register Addressing
Most of the instructions that use registeraddressing deal with 8-bit values.
However, a few of these instructions deal with 16-
bit register pairs.
• For example, the PCHL instruction exchanges thecontents of the program counter with the contents
of the H and L registers.
Prepared by: Dr Masri Ayob 10
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 11/43
Immediate Addressing
These instructions have data assembled as a partof the instruction itself.
• For example, the instruction CPI 'C' may be
interpreted as ‘compare the contents of the
accumulator with the letter C.• When assembled, this instruction has the
hexadecimal value FE43.
• Hexadecimal 43 is the internal representation for
the letter C.
Prepared by: Dr Masri Ayob 11
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 12/43
Immediate Addressing
• For example, the instruction CPI 'C' may beinterpreted as ‘compare the contents of the
accumulator with the letter C.
• When this instruction is executed, the processor
fetches the first instruction byte and determines
that it must fetch one more byte.
• The processor fetches the next byte into one of
its internal registers and then performs the
compare operation.
Prepared by: Dr Masri Ayob 12
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 13/43
Direct Addressing
These instructions require three bytes of storage:one for the instruction code, and two for the 16-bit
address.
Example:
• JMP 1000H causes a jump to the hexadecimaladdress 1000H by replacing the current contents of
the PC with the new value 1000H.
Prepared by: Dr Masri Ayob 13
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 14/43
Register Indirect Addressing
These instructions reference memory via aregister pair.
For example: MOV M,C
• moves the contents of the C register into the
memory address stored in the H and L register pair.
The instruction LDAX B loads the accumulator
with the byte of data specified by the address in
the B and C register pair .
Prepared by: Dr Masri Ayob 14
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 15/43
Combined Addressing Modes
Some instructions use a combination ofaddressing modes.
• A CALL instruction, for example, combines direct
addressing and register indirect addressing.
• The direct address in a CALL instruction specifiesthe address of the desired subroutine;
• the register indirect address is the stack pointer.
The CALL instruction pushes the current contents
of the program counter into the memory locationspecified by the stack pointer. .
Prepared by: Dr Masri Ayob 15
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 16/43
Timing Effects of Addressing Modes
Addressing modes affect both the amount of timerequired for executing an instruction and the
amount of memory required for its storage.
For example, instructions that use implied or
register addressing, execute very quickly sincethey deal directly with the processor’s hardware or
with data already present in hardware registers.
• Most important, however is that the entire
instruction can be fetched with a single memory
access. The number of memory accesses required
is the single greatest factor in determining
execution timing.
16
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 17/43
Timing Effects of Addressing Modes
More memory accesses require more executiontime.
• A CALL instruction for example, requires five
memory accesses: three to access the entire
instruction and two more to push the contents ofthe program counter onto the stack.
Prepared by: Dr Masri Ayob 17
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 18/43
Data Format
The 8085 is an 8-bit microprocessor, and itprocesses only binary numbers.
We need to code binary numbers into different
media.
Common codes and data formats are ASCII, BCD,signed integers, and unsigned integers:
• ASCII Code - 7-bit alphanumeric code that
represents decimal numbers, English alphabets,
and nonprintable characters such as carriage
return. Extended ASCII is an 8-bit code.
• BCD Code - Binary-coded decimal; it is used for
decimal numbers.
Prepared by: Dr Masri Ayob 18
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 19/43
Data Format
Signed Integer - A signed integer is either apositive number or a negative number.
• 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.• The remaining seven bits, D6—D0, represent the
magnitude of an integer. Therefore, the largest
positive integer that can be processed by the 8085
at one time is 0111 1111 (7FH); the remaining Hex
numbers, 80H to FFH, are considered negative
numbers.
Prepared by: Dr Masri Ayob 19
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 20/43
Data Format
Unsigned Integers - An integer without a sign canbe represented by all the 8 bits in a
microprocessor register.
• Therefore, the largest number that can be
processed at one time is FFH.• However, this does not imply that the 8085
microprocessor is limited to handling only 8-bit
numbers. Numbers larger than 8 bits (such as 16-bit
or 24-bit numbers) are processed by dividing themin groups of 8 bits.
Prepared by: Dr Masri Ayob 20
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 21/43
How To Write, Assemble, And Execute
a Simple Program
A program is a sequence of instructions written totell a computer to perform a specific function.
The instructions are selected from the instruction
set of the microprocessor.
To write a program:
• divide a given problem in small steps in terms of the
operations the 8085 can perform;
• then translate these steps into instructions.
Prepared by: Dr Masri Ayob 21
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 22/43
Example: Writing a simple program
PROBLEM STATEMENT• Write instructions to load the two hexadecimal
numbers 32H and 48H in registers A and B,
respectively.
• Add the numbers, and display the sum at the LEDoutput port PORT.
Prepared by: Dr Masri Ayob 22
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 23/43
Example: Writing a simple program
PROBLEM ANALYSIS• 1. Load the numbers in the registers.
• 2. Add the numbers.
• 3. Display the sum at the output port PORT.
Prepared by: Dr Masri Ayob 23
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 24/43
Example: Writing a simple program
Prepared by: Dr Masri Ayob 24
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 25/43
Example: Writing a simple program
ASSEMBLY LANGUAGE PROGRAM• To write an assembly language program, we need to
translate the blocks shown in the flowchart into
8085 operations and then, subsequently, into
mnemonics.
• By examining the blocks, we can classify them into
three types of operations: Blocks 1 and 3 are copy
(data transfer) instruction.
• Block 2 is an arithmetic operation;
• Block 4 is a machine-control operation.
• To translate these steps into assembly and machine
languages, we should review the instruction set.
Prepared by: Dr Masri Ayob 25
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 26/43
Example: Writing a simple program
Prepared by: Dr Masri Ayob 26
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 27/43
Example: Writing a simple program
Prepared by: Dr Masri Ayob 27
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 28/43
Example: Writing a simple program
Storing in memory and converting from hex codeto binary code.
To store the program in R/W memory of a single-
board microcomputer and display the output, we
need to know the memory addresses and theoutput port address.
Prepared by: Dr Masri Ayob 28
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 29/43
Example: Writing a simple program
• Let us assume that R/W memory ranges from 2000H
to 2OFFH, and the system has an LED output port
with the address 01H. Now, to enter the program:
• Reset the system by pushing the RESET key.
• Enter the first memory address using Hex keys
where the program should be stored. Let us
assume it is 2000H.
• 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 keymay be labeled differently in different systems).
• Repeat Step 3 until the last machine code, 76H.
• Reset the system.
Prepared by: Dr Masri Ayob 29
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 30/43
Example: Writing a simple program
In this illustrative example, the program will bestored in memory as follows:
Prepared by: Dr Masri Ayob - TK212330
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 31/43
Example: Writing a simple program
EXECUTING THE PROGRAM• To execute the program, we need to tell the
microprocessor where the program begins by
entering the memory address 2000H.
• Now, we can push the Execute key (or the keywith a similar label) to begin the execution.
• As soon as the Execute function key is pushed,
the microprocessor loads 2000H in the program
counter, and the program control is transferred
from the Monitor program to our program.
• The microprocessor begins to read one machine
code at a time, and when it fetches the complete
instruction, it executes that instruction.
Prepared by: Dr Masri Ayob 31
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 32/43
Overview Of The 8085 Instruction Set
The 8085 microprocessor instruction set has 74operation codes that result in 246 instructions.
The following notations are used in the description
of the instructions:
Prepared by: Dr Masri Ayob 32
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
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 33/43
Data Transfer (Copy) Instructions
These instruction perform the following 6operations:
• Load an 8-bit register
• Copy from register to register
• Copy between I/O and accumulator• Load 16-bit number in a register pair
• Copy between register and memory
• Copy between registers and stack memory
Prepared by: Dr Masri Ayob 33
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 34/43
Data Transfer (Copy) Instructions
Prepared by: Dr Masri Ayob 34
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 35/43
Arithmetic Instructions
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 36/43
Arithmetic Instructions
Prepared by: Dr Masri Ayob 36
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 37/43
Logic and Bit Manipulation Instructions
ANDOR
X-OR (Exclusive OR)
Compare
Rotate Bits
Prepared by: Dr Masri Ayob 37
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 38/43
Branch Instructions
Prepared by: Dr Masri Ayob 38
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 39/43
Machine Control Instructions
These instructions affect the operation of theprocessor.
• HLT Stop processing and wait
• NOP Do not perform any operation
Prepared by: Dr Masri Ayob 39
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 40/43
Common Errors
LDA 205lH: Not entering the code of the 16-bitaddress in reversed order.
Forgetting to enter the code for the operand, such
as 205lH.
MOV B, A: Assuming that this copies from B to A.
Incrementing the address in decimal, from 2039H
to 2040H.
HLT: Not terminating a program.Confusing the entering of Hex code in memory as
executing a program.
Prepared by: Dr Masri Ayob 40
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 41/43
Summary
The 8085 microprocessor operations are classifiedinto five major groups: data transfer (copy),
arithmetic, logic, branch, and machine control.
An instruction has two parts:
• opcode (operation to be performed)• operand (data to be operated on) - The operand can
be data (8- or 16-bit), address, or register, or it can
be implicit.
Prepared by: Dr Masri Ayob 41
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 42/43
Summary
The method of specifying an operand (directly,indirectly, etc.) is called the addressing mode.
The instruction set is classified in three groups
according to the word size: 1-, 2-, or 3-byte
instructions.To write an assembly language program, divide
the given problem into small steps in terms of the
microprocessor operations, translate these steps
into assembly language instructions, and then
translate them into the 8085 machine code.
Prepared by: Dr Masri Ayob 42
7/22/2019 TK2633-Lecture3-Introduction to 8085 Assembly Language Programming(2)
http://slidepdf.com/reader/full/tk2633-lecture3-introduction-to-8085-assembly-language-programming2 43/43
Thank youQ & A