Title: TK 2633 Microprocessor
1TK 2633Microprocessor Interfacing
- Lecture 1 Introduction to 8085 Assembly Language
Programming (2)
2Instruction, 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.
3Instruction, Data Format, And Storage
- 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. - 1-byte instructions
- 2-byte instructions
- 3-byte instructions
41-byte instructions
- It includes the opcode and the operand in the
same byte. For example
52-byte instructions
- The first byte specifies the operation code and
the second byte specifies the operand. For
example
63-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
7Addressing Modes
- Instructions can be categorized according to
their method of addressing the hardware registers
and/or memory. - Implied Addressing
- Register Addressing
- Immediate Addressing
- Direct Addressing
- Register Indirect Addressing
- Combined Addressing Modes.
8Implied Addressing
- The addressing mode of certain instructions is
implied by the instructions 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.
9Register Addressing
- Quite a large set of instructions call for
register addressing. - 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. - Most of the instructions that use register
addressing deal with 8-bit values. - However, a few of these instructions deal with
16-bit register pairs. - For example, the PCHL instruction exchanges the
contents of the program counter with the contents
of the H and L registers. -
10Immediate Addressing
- These instructions have data assembled as a part
of 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. - 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.
11Direct 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 hexadecimal
address 1000H by replacing the current contents
of the PC with the new value 1000H.
12Register Indirect Addressing
- These instructions reference memory via a
register 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 .
13Combined Addressing Modes
- Some instructions use a combination of addressing
modes. - A CALL instruction, for example, combines direct
addressing and register indirect addressing. - The direct address in a CALL instruction
specifies the 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
location specified by the stack pointer. .
14Timing Effects of Addressing Modes
- Addressing modes affect both the amount of time
required 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 since
they deal directly with the processors 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. - More memory accesses require more execution time.
- A CALL instruction for example, requires five
memory accesses three to access the entire
instruction and two more to push the contents of
the program counter onto the stack.
15Data Format
- The 8085 is an 8-bit microprocessor, and it
processes 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.
16Data Format
- Signed Integer - A signed integer is either a
positive 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, D6D0, 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. - Unsigned Integers - An integer without a sign can
be 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 them in groups of 8 bits.
17How To Write, Assemble, And Executea Simple
Program
- A program is a sequence of instructions written
to tell 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.
18Example 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 LED
output port PORT.
19Example 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.
20Example Writing a simple program
21Example 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.
22Example Writing a simple program
23Example Writing a simple program
24Example Writing a simple program
- STORING IN MEMORY AND CONVERTING FROM HEX CODE TO
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
the output port address. - 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 key may be
labeled differently in different systems). - Repeat Step 3 until the last machine code, 76H.
- Reset the system.
25Example Writing a simple program
- In this illustrative example, the program will be
stored in memory as follows
26Example 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 key with
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.
27Overview Of The 8085 Instruction Set
- The 8085 microprocessor instruction set has 74
operation codes that result in 246 instructions. - The following notations are used in the
description of the instructions
R 8085 8-bit register (A,B,C,D,E,H,L) M
Memory register (location) RsRegister
source (A,B,C,D,E,H,L) RdRegister
destination (A,B,C,D,E,H,L) RpRegister
pair (BC,DE,HL,SP) () Contents of
28Data Transfer (Copy) Instructions
- These instruction perform the following 6
operations - 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
29Data Transfer (Copy) Instructions
30Arithmetic Instructions
- Add
- Subtract
- Increment (Add 1)
- Decrement (Subtract 1)
31Arithmetic Instructions
32Logic and Bit Manipulation Instructions
- AND
- OR
- X-OR (Exclusive OR)
- Compare
- Rotate Bits
33Branch Instructions
34Machine Control Instructions
- These instructions affect the operation of the
processor. - HLT Stop processing and wait
- NOP Do not perform any operation
35Common Errors
- LDA 205lH Not entering the code of the 16-bit
address 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.
36Summary
- The 8085 microprocessor operations are classified
into 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. - 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.
37Thank youQA