You are on page 1of 28

Introduction to 8085 Assembly

Language Programming

Mohamad Al Azawi
Azawi.m@gmail.com
Programming Model 8085

Programming
Registers

Mohamad Al Azawi
Azawi.m@gmail.com
Flags
D7 D6 D5 D4 D3 D2 D1 D0

CY P AC Z S
•The flags are affected by the ALU operation and since the results are
stored in accumulator then the flags reflect the condition of the
accumulator
•The following is the description of the flags
•S- Sign flag: S 1 if D7 of the result =1;means –ve number
•Z – Zero flag : if the ALU operation is 0 then Z  1, and vice versa
•AC – auxiliary carry flag: used for BCD and AC1 if the carry is
passed from D3 to D4 (not used in conditions)
•P – Parity flag: P 1 if the number of 1’s is even and vice versa
•CY – carry : CY 1 if there is a carry result from the ALU operation
Mohamad Al Azawi
Azawi.m@gmail.com
Instruction Classification

• Instruction: is a binary pattern designed inside


µp to perform a specific function.
• Instruction Set: is the entire group of instructions
• 8085 is upward compatible

Mohamad Al Azawi
Azawi.m@gmail.com
inst Classification 8085
• The instruction set is classified int the
following five functional categories:
1. Data transfer (copy) operations
2. Arithmetic operations
3. Logical operations
4. Branching operations
5. Machine control operations

Mohamad Al Azawi
Azawi.m@gmail.com
Data transfer (copy) operation
• Copying data from source to destination
without modifying the contents of the
source
• The data is transferred :
1. Between registers
2. Specific data byte to reg. or mem loc
3. Between mem loc and registers
4. Between an I/O device and accumulator
Mohamad Al Azawi
Azawi.m@gmail.com
Arithmetic operations
• Perform arithmetic operations such as:
– Addition – adding any 8-bit numbers, mem
loc, or reg. content can be added to the
contents of the accumulator
– Subtraction - Subtracting any 8-bit numbers,
mem loc, or reg. content can be subtracted
from the contents of the accumulator (using
2’s complement)
– Increment / Decrement

Mohamad Al Azawi
Azawi.m@gmail.com
Logical operations
• AND, OR, Exclusive OR:- ANDing, ORing, or
XORing any 8-bit numbers, mem loc, or reg.
content can be ANDed, ORed, or XORed with the
contents of the accumulator
• Rotate: shifting the bits in the accumulator
• Compare: (=, <, >, with the contents of acc.)
• Complement: complementing the cont. of acc.

Mohamad Al Azawi
Azawi.m@gmail.com
Branching Operations

• (conditional and noncondithional(


• Jump: conditional jump, decision making,
Z, CY flags.
• Call, return, and restart

Mohamad Al Azawi
Azawi.m@gmail.com
Machine control operations

Halt, Interrupt, or do nothing

Mohamad Al Azawi
Azawi.m@gmail.com
Notes
• In copy inst the data in the source is not
changed only the data in the destination
• Arith. And logic operations are performed
in the accumulator and the results are
stored in accumulator
• The flags are affected according to the
results
• Any reg. including mem. can be
incremented and decremented
Mohamad Al Azawi
Azawi.m@gmail.com
Data format

• The instruction consists of the following


tow parts:
– Operation code (opcode)
– Operand

Mohamad Al Azawi
Azawi.m@gmail.com
Instruction Word Size

• The 8085 instructions are classified as


follows:
– One – word or 1 – byte instruction
– Tow – word or 2 – byte instruction
– Three – word or 3 – word instruction
( Word = 1 byte in 8085)

Mohamad Al Azawi
Azawi.m@gmail.com
One – byte instruction
• Includes the opcode and operand in the
same byte, such as
Hex Binary operand opcode Task
code code
4FH 0100 1111 C, A MOV Copy the contents of acc to reg. C

80H 1000 0000 B ADD Add the cont. of reg. B to the Acc.

2FH 0010 1111 ---- CMA Complement the contents of the


acc.

Mohamad Al Azawi
Azawi.m@gmail.com
Tow Byte Instructions
• The first byte specifies the opcode and the
second specifies the operand

Hex code Binary code operand opcode Task

3EH 0011 1110 A, DATA MVI Load an 8-bit data byte in


DATA DATA the acc.

Mohamad Al Azawi
Azawi.m@gmail.com
Three byte instruction
• The first byte specifies the opcode and the
next two bytes specify 16 bit address

Hex code Binary code operand opcode Task

C3H 1100 0011 2085H JMP Transfer the prog sequ.


85H 1000 0101 To the mem loc 2085H
20H 0010 0000

Mohamad Al Azawi
Azawi.m@gmail.com
Opcode format
• The internal registers are identified as follows:
Code reg. Code reg. pair

000 B 00 BC
001 C 01 DE
010 D 10 HL
011 E 11 SP
100 H
101 L
111 A
110 RESERVED FOR MEMORY RELATED OPERATION

Mohamad Al Azawi
Azawi.m@gmail.com
• EX.
Function opcode
1. Rotate each bit of the 00000111 = 07H
acc. To the left by one (8-bit opcode)
position.
2. Add the content of the 10000 xxx
reg. to the accum.

bit opcode – 5

bit are reserved-3


.for a reg
Mohamad Al Azawi
Azawi.m@gmail.com
• Ex:
ADD : 10000
register B : 000
to A :
binary instruction:10000 000 = 80H

In assembly language this can be represented as:


opcode operand hex code
ADD B 80H

Mohamad Al Azawi
Azawi.m@gmail.com
• EX: Move (copy ) the contents of the register Rs
(source) to register Rd (destination)
01 DDD SSS
MOV reg. Rd reg. Rs
Move the content from A to C
move the contents: 01
to Register C : 001
from Register A : 111
binary instruction : 01 001 111  4FH

IN Assem. Lang. MOV C,A


Mohamad Al Azawi
Azawi.m@gmail.com
Data Format

• ASCII Code
• BCD Code
• Signed Integer
• Unsigned Integers

Mohamad Al Azawi
Azawi.m@gmail.com
Writing, Assembling and Execution of
Assembly programs
• Add tow hex. Numbers
– PROBLEM STATEMENT
• Write instruction to load 2 hex no. 32H and 48H in
reg. A and b respectively, Add the numbers and
display the sum at the led output port1
– PROBLEM ANALYSIS
• Divide the problem into small steps as follows
– Load the numbers in the registers
– Add the numbers
– Display the sum at the output port PORT1

Mohamad Al Azawi
Azawi.m@gmail.com
Start
• FLOW CHART
Load Hexadecimal
Numbers

Add Numbers

Display Sum

End
Mohamad Al Azawi
Azawi.m@gmail.com
MVI A,32H ; Load the Register A with 32H
MVI B,48H ; Load the Register B with 48H

ADD B ; Add the 2 bytes and save res in A


OUT 01H ; Display the acc. Contents at port 01H
HALT ; End

Mohamad Al Azawi
Azawi.m@gmail.com
CONVERTING FROM ASSEMBLY LANGUAGE TO HEX CODE

Mnemonics Hex Code

MVI A,32H 3E
32
MVI B,48H 06
48
ADD B 80
OUT 01H D3
01
HALT 67
Mohamad Al Azawi
Azawi.m@gmail.com
STORING IN MEMORY AND CONVERTING FROM HEX
CODE TO BINARY CODE

Assume that R/W memory range from 2000H to


20FFH and the system has LED output port with the
address 01H now to enter the program:
1. Reset the system
2. Enter the first memory address using Hex key where
the program should be stored say 2000H
3. Enter each machine code by pushing Hex Key, for
example to enter the first 3EH, press 3, then E, then
STORE keys.
4. Repeat step 3 untill the last machine code
5. Reset the system.
Mohamad Al Azawi
Azawi.m@gmail.com
• How hex code converted into binary ??
Mnemonics Hex Codememory contents Mem Add
MVI A,32H 3E 0011 1110 2000
32 0011 0010 2001
MVI B,48H 06 0000 0110 2002
48 0100 1000 2003
ADD B 80 1000 0000 2004
OUT 01H D3 1101 0011 2005
01 0000 0001 2006
HLT 76 0111 1110 2007

Mohamad Al Azawi
Azawi.m@gmail.com
Manual To memory for
Flow Monitor
Lookup Storage
Chart Program
8085 Hex Binary
Mnemonics Code Code

Mohamad Al Azawi
Azawi.m@gmail.com

You might also like