0% found this document useful (0 votes)
4 views

Unit-4 - Assembly Language Programming Basics (Part-2)

The document provides an overview of Assembly Language Programming Basics for the 8085 microprocessor, detailing topics such as addressing modes, program writing steps, execution, and debugging. It includes examples of assembly language programs and outlines the timing and machine cycles for various instructions. The content emphasizes the importance of comments and troubleshooting in programming.

Uploaded by

shahjanvi208
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Unit-4 - Assembly Language Programming Basics (Part-2)

The document provides an overview of Assembly Language Programming Basics for the 8085 microprocessor, detailing topics such as addressing modes, program writing steps, execution, and debugging. It includes examples of assembly language programs and outlines the timing and machine cycles for various instructions. The content emphasizes the importance of comments and troubleshooting in programming.

Uploaded by

shahjanvi208
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Microprocessor and Interfacing

(MPI)
GTU # 3160712

Unit-4:
Assembly Language
Programming Basics
PART-II: 8085 Assembly Program Basics
Positive Vibes:MPI is the interesting, easiest and scoring subject.
Subject Overview
Positive Vibes:MPI is the interesting, easiest and scoring subject.
Sr. No. Unit % Weightage
1 Introduction to Microprocessor 8%
2 Microprocessor Architecture and Operations 7%
3 8085 Microprocessor 12%
4 Assembly Language Programming Basics 13%
5 8085 Assembly Language Programs 12%
6 Stack & Subroutines 13%
7 I/O Interfacing 20%
8 Advanced Microprocessors 15%

Unit 4 – Assembly Language Basics 2


 Topics
Loopingto be covered
Positive Vibes:MPI is the interesting, easiest and scoring subject.

▪ Addressing Modes in 8085


▪ 8085 Assembly Language Programs Basics
▪ 8085 Assembly Language Programs
✓ Writing & Assembling the Programs
✓ Executing the Programs
✓ Debugging the Programs
▪ T-States & Machine Cycle of 8085 Instructions
▪ Timing Diagram
Positive Vibes:MPI is the interesting, easiest and scoring subject.

Addressing Modes in 8085


Addressing Modes in 8085
Positive Vibes:MPI is the interesting, easiest and scoring subject.

Immediate Addressing Mode

Direct Addressing Mode

Register Addressing Mode

Indirect Addressing Mode

Implicit Addressing Mode

Unit 4 – Assembly Language Basics 5


Immediate Addressing Mode
 8/16-bit data is specified in the instruction itself as one of its operand. Positive Vibes:MPI is the interesting, easiest and scoring subject.

 For example:
MVI B,20H
LXI D,1034H
ADI 45H
SUI 30H
CPI 68H

Unit 4 – Assembly Language Basics 6


Direct Addressing Mode
 8/16-bit memory address is directly provided with the instruction. Positive Vibes:MPI is the interesting, easiest and scoring subject.

 For example:
LDA 1035H ; here 1035 is 16-bit memory address
IN 02H ; 02 is 8-bit I/O port address
OUT 03H ; 03 is 8-bit I/O port address

Unit 4 – Assembly Language Basics 7


Register Addressing Mode
 It specifies register or register pair that contains data. Positive Vibes:MPI is the interesting, easiest and scoring subject.

 For example:
MOV A,B ; A  B
ADD B ; A  A+B
DAD H ; HL  HL+RP

Unit 4 – Assembly Language Basics 8


Indirect Addressing Mode
 In this type of addressing mode, the 16-bit memory address is indirectly provided with the
Positive Vibes:MPI is the interesting, easiest and scoring subject.

instruction using a register pair.


 For example:
LDAX D; A <- M[DE]
STAX B; A -> M[BC]

Unit 4 – Assembly Language Basics 9


Implicit/Implied Addressing Mode
 This mode doesn’t require any operand; the data is specified by the Opcode itself.
Positive Vibes:MPI is the interesting, easiest and scoring subject.

 For example:
XTHL
SPHL
PCHL

Unit 4 – Assembly Language Basics 10


Positive Vibes:MPI is the interesting, easiest and scoring subject.

8085 Assembly Language


Programs Basics
Writing Assembly Language Programs
The steps to write Assembly Language Programs are as follows: Positive Vibes:MPI is the interesting, easiest and scoring subject.

Step-1: Read the problem carefully.


Step-2: Break it down into small steps.
Step-3: Represent the sequence with flowchart.
Step-4: Translate flowchart into appropriate mnemonic instructions.
Step-5: Translate mnemonic into machine code.
Step-6: Enter machine code in memory and execute.
Step-7: Start troubleshooting-debugging a program

Unit 4 – Assembly Language Basics 12


Documentation
 Appropriate comments are critical for conveying the logic behind the program. Positive Vibes:MPI is the interesting, easiest and scoring subject.

 The comment should explain what is intended; they should not explain mnemonics.
 Comment is optional.
Example:
MOV A,B ; Move data from B to A 
MOV A,B ; send data to accumulator for processing 

Unit 4 – Assembly Language Basics 13


Program Execution
 Machine code can be loaded in R/W memory, with reference to starting memory location.Positive Vibes:MPI is the interesting, easiest and scoring subject.

 Execution can be done in two ways:


1. Execute entire code on click.
2. Single step execution.
 It will execute one instruction at a time.
 We can observe the content of register and flag after execution of each instruction.

Unit 4 – Assembly Language Basics 14


Debugging Program
 Debug a program is similar to troubleshooting hardware. Positive Vibes:MPI is the interesting, easiest and scoring subject.

 If the code doesn’t work, it is essential to search carefully for errors in programming logic,
machine codes and execution.
How to Debug machine code:
 Translating assembly to machine code is similar to building a circuit.
 Following errors are common:
1. Writing a wrong code.
2. Specifying the wrong jump location.
3. Writing memory address in decimal, thus specifying wrong jump location.
4. Writing lower order and higher order bits in wrong sequence.

Unit 4 – Assembly Language Basics 15


Positive Vibes:MPI is the interesting, easiest and scoring subject.

8085 Assembly Language


Programs Basics
8085 Assembly Program: Add Two 8-bit Numbers
Write a program to add data at 1005H & 1006H memory location and store the result at 1007H
Positive Vibes:MPI is the interesting, easiest and scoring subject.

memory location.
Start

1. LXI H,1005 ; to retrive m/m addr Transfer 16-bit


address to HL Pair
2. MOV A,M ; retrieve m/m content
3. INX H ; increment memeory to 1006H Data Transfer: A <- M[HL]
4. ADD M ; add accumulator with M[1006]
HL=HL + 1
5. STA 1007 ; store result
6. HLT ; HLT program A = A + M[HL]

Store result
[1007] <- A

End

Unit 4 – Assembly Language Basics 17


8085 Assembly Program
Write a program to load register B with 37H and display number at the output Port 01
Positive Vibes:MPI is the interesting, easiest and scoring subject.

1. MVI B,37 ; B <- 37H


2. MOV A,B ; A <- B for I/O processing
3. OUT 01 ; PORT 01 <- A
4. HLT

Unit 4 – Assembly Language Basics 18


Positive Vibes:MPI is the interesting, easiest and scoring subject.

T-States & Machine Cycle


of 8085 Instructions
Timing Cycle required by 8085 Instructions
Positive Vibes:MPI is the interesting, easiest and scoring subject.

Operation T-States
Opcode Fetch 4-6T
Memory Read 3T
Memory Write 3T
I/O Read 3T
I/O Write 3T

• Instruction that require 5T-States for Opcode Fetch


HLT
• Instructions that require 6T-States for Opcode Fetch
1. CALL 5. PCHL
2. Conditional CALL 6. SPHL
3. DCX 7. PUSH
4. INX 8. Conditional RET

Unit 4 – Assembly Language Basics 20


Machine Cycle required by 8085 Instruction
Positive Vibes:MPI is the interesting, easiest and scoring subject.

Operation M/C
Fetch (F) 1
Memory Read (MEMR) 1
Memory Write (MEMW) 1
I/O Read (IOR) 1
I/O Write (IOW) 1
Read Immediate Data (R) 1

Unit 4 – Assembly Language Basics 21


Timing and Machine Cycle
1. MOV B, D Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle:
1(F) = 1 Machine Cycle
Timing Cycle:
= 4T (Fetch)

Unit 4 – Assembly Language Basics 22


Timing and Machine Cycle
2. MVI C ,17H Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + R


1 + 1=2
Timing Cycle: Fetch + R
4T + 3T= 7T

Unit 4 – Assembly Language Basics 23


Timing and Machine Cycle
3. MVI M , 25H Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + R+ Write data(MEMW)


1 + 1 +1=3
Timing Cycle: Opcode Fetch + R + MEMW
4T + 3T + 3T = 10T

Unit 4 – Assembly Language Basics 24


Timing and Machine Cycle
4. MOV A,M Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + Read Memory(MEMR)


1 + 1 =2
Timing Cycle: Fetch + MEMR
4T + 3T = 7T

Unit 4 – Assembly Language Basics 25


Timing and Machine Cycle
4. MOV M, A Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + Write Memory(MEMW)


1+1=2
Timing Cycle: Fetch + MEMW
4T + 3T = 7T

Unit 4 – Assembly Language Basics 26


Timing and Machine Cycle
5. NOP Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch


= 1 M/C Cycle
Timing Cycle: Fetch
= 4T

Unit 4 – Assembly Language Basics 27


Timing and Machine Cycle
6. HLT : Halt and enter wait state Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + Wait


= 1 or more M/C Cycle
Timing Cycle: Fetch + Wait
= 5T or more T-States

Unit 4 – Assembly Language Basics 28


Timing and Machine Cycle
7. IN 18H Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + R + IOR


=1 +1+1
=3
Timing Cycle: Fetch + R + IOR
= 4T + 3T + 3T
= 10T

Unit 4 – Assembly Language Basics 29


Timing and Machine Cycle
8. OUT 19H Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + R + IOW


=1 +1+1
=3
Timing Cycle: Fetch + R + IOW
= 4T + 3T + 3T
= 10T

Unit 4 – Assembly Language Basics 30


Timing and Machine Cycle
9. ADD B Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch


= 1 Machine Cycle
Timing Cycle: Fetch
= 4T

Unit 4 – Assembly Language Basics 31


Timing and Machine Cycle
10. ADI 26H Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + R


1 + 1=2
Timing Cycle: Fetch + MEMR
4T + 3T = 7T

Unit 4 – Assembly Language Basics 32


Timing and Machine Cycle
11. ADD M Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + MEMR


1 + 1=2
Timing Cycle: Fetch + MEMR
4T + 3T = 7T

Unit 4 – Assembly Language Basics 33


Timing and Machine Cycle
12. SUB C Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch


= 1 Machine Cycle
Timing Cycle: Fetch
= 4T

Unit 4 – Assembly Language Basics 34


Timing and Machine Cycle
13. SUI 26H Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + R


1 + 1=2
Timing Cycle: Fetch + MEMR
4T + 3T = 7T

Unit 4 – Assembly Language Basics 35


Timing and Machine Cycle
14. SUB M Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + MEMR


1 + 1=2
Timing Cycle: Fetch + MEMR
4T + 3T = 7T

Unit 4 – Assembly Language Basics 36


Timing and Machine Cycle
15. LDA 2030H Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + ReadL 8-bit + ReadH 8-bit +MEMR (content)


=1 +1+1+1
=4
Timing Cycle: Fetch + MEMR + MEMR + MEMR
= 4T + 3T + 3T + 3T
= 13T

Unit 4 – Assembly Language Basics 37


Timing and Machine Cycle
16. POP RP : POP B Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + MEMR (SP) + MEMR (SP+1)


=1 +1+1
=3
Timing Cycle: Fetch + MEMR + MEMR
= 4T + 3T + 3T
= 10T

Unit 4 – Assembly Language Basics 38


Timing and Machine Cycle
16. PUSH RP : PUSH B Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + MEMW (SP) + MEMW (SP-1)


=1 +1+1
=3
Timing Cycle: Fetch + MEMW + MEMW
= 6T + 3T + 3T
= 12T

Unit 4 – Assembly Language Basics 39


LHLD Instruction
Positive Vibes:MPI is the interesting, easiest and scoring subject.
Registers Memory

02 0001
A
04 0002
B C 0A 0003
06 0004
D E
0F 0005
H L 0D 0006
05 0007
03 0008
LHLD 0006H

Unit 4 – Assembly Language Basics 40


Timing and Machine Cycle
17. LHLD 2034H Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + MEMRL (2034) + MEMRH (2034)


+ MEMR_Content (2034)
+ MEMR_Content (2035)
=1 +1+1+1+1
=5
Timing Cycle: Opcode Fetch+ MEMR + MEMR + MEMR + MEMR
= 4T + 3T + 3T + 3T + 3T
= 16T

Unit 4 – Assembly Language Basics 41


Timing and Machine Cycle
18. RAR Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch


= 1 Machine Cycle
Timing Cycle: Fetch
= 4T

Unit 4 – Assembly Language Basics 42


Timing and Machine Cycle
19. XTHL Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + MEMR(SP)+MEMW(L)+ MEMR(SP+1)+MEMW(H)


=1 +1+1+1+1
=5
Timing Cycle: Fetch+ MEMR + MEMW + MEMR + MEMW
= 4T + 3T + 3T + 3T + 3T
= 16T

Unit 4 – Assembly Language Basics 43


Timing and Machine Cycle
20. CALL 2030H Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + MEMWL(Store) + MEMWH(Store)


+ MEMRL(Call) + MEMRH(Call)
=1 +1+1+1+1
=5
Timing Cycle: Fetch+ MEMW + MEMW + MEMR + MEMR
= 6T + 3T + 3T + 3T + 3T
= 18T

Unit 4 – Assembly Language Basics 44


Timing and Machine Cycle
21. RET Positive Vibes:MPI is the interesting, easiest and scoring subject.

Machine Cycle: Fetch + MEMR (SP) + MEMR (SP+1)


=1 +1+1
=3
Timing Cycle: Fetch + MEMR + MEMR
= 4T + 3T + 3T
= 10T

Unit 4 – Assembly Language Basics 45


Exercise: Find Byte Size, Timing & Machine Cycle
1. LDAX B Positive Vibes:MPI is the interesting, easiest and scoring subject.

2. SHLD 2470
3. SPHL
4. DAA
5. INR R/M
6. JMP
7. PCHL
8. CMP R/M
9. RRC
10. RIM
11. SIM
12. ORA R/M
13. XCHG
14. DI
15. EI

Unit 4 – Assembly Language Basics 46


Exercise Solution
Sr. Instruction Byte Size Machine Cycle T-States
Positive Vibes:MPI is the interesting, easiest and scoring subject.

1. LDAX B 1 F+R=2 4T+3T=7T


2. SHLD 2470 3 F+R+R+W+W=5 4T+3T+3T+3T+3T=16T
3. SPHL 1 F=1 6T
4. DAA 1 F=1 4T
5. INR R 1 F=1 4T
INR M 1 F+R+W=3 4T+3T+3T=10T
6. JMP 2030 3 F+R+R=3 4T+3T+3T=10T
7. PCHL 1 F=1 6T
8. CMP R 1 F=1 4T
CMP M 1 F+R=2 4T+3T=7T
9. RRC 1 F=1 4T
10. RIM 1 F=1 4T

Unit 4 – Assembly Language Basics 47


Exercise Solution
Sr. Instruction Byte Size Machine Cycle T-States
Positive Vibes:MPI is the interesting, easiest and scoring subject.

11. SIM 1 F=1 4T


12. ORA R 1 F=1 4T
ORA M 1 F+R=2 4T+3T=7T
13. XCHG 1 F=1 4T
14. DI 1 F=1 4T
15. EI 1 F=1 4T

Unit 4 – Assembly Language Basics 48


Positive Vibes:MPI is the interesting, easiest and scoring subject.

Timing Diagram
Opcode Fetch
T1 T2 T3 T4
Positive Vibes:MPI is the interesting, easiest and scoring subject.
CLK

A15
High order memory address Unspecified
A8
AD7 Low order
Opcode
AD0 M/m addr.

ALE
IO/M

RD
Memory read cycle
T1 T2 T3 T4
Positive Vibes:MPI is the interesting, easiest and scoring subject.
CLK

A15
High order memory address
A8
AD7 Low order
Data from memory
AD0 M/m addr. S1 S0 Mode
0 0 HLT
0 1 WRITE
1 0 READ
ALE
IO/M
S0 IO/M=0, S1=1 , S0=0
S1
RD
Memory write cycle
T1 T2 T3 T4
Positive Vibes:MPI is the interesting, easiest and scoring subject.
CLK

A15
High order memory address
A8
AD7 Low order Data from
AD0 M/m addr. Microprocessor S1 S0 Mode
0 0 HLT
0 1 WRITE
1 0 READ
ALE
IO/M
S1 IO/M=0, S1=0 , S0=1
S0
WR
I/O read cycle
T1 T2 T3 T4
Positive Vibes:MPI is the interesting, easiest and scoring subject.
CLK

A15
High order I/O address
A8
AD7 Low order
I/O data
AD0 I/O addr. S1 S0 Mode
0 0 HLT
0 1 WRITE
1 0 READ
ALE
S0

IO/M IO/M=1, S1=1 , S0=0


S1
IOR
I/O write cycle
T1 T2 T3 T4
Positive Vibes:MPI is the interesting, easiest and scoring subject.
CLK

A15
High order I/O address
A8
AD7 Low order Data from
AD0 I/O addr. Microprocessor S1 S0 Mode
0 0 HLT
0 1 WRITE
1 0 READ
ALE
S1

IO/M IO/M=1, S1=0 , S0=1


S0
IOW
Timing Diagram : MOV B,M
Opcode Fetch Memory Read
T1 T2 T3 T4 T5 T6 T7
Positive Vibes:MPI is the interesting, easiest and scoring subject.

CLK

A15 High order memory Unspe


High order memory address
A8 address cified

AD7
Low order Low order Data from
M/m addr. Opcode M/m addr.
AD0 memory

ALE

IO/M

RD
Timing Diagram : MVI A, 32H
Opcode Fetch Memory Read
T1 T2 T3 T4 T5 T6 T7
Positive Vibes:MPI is the interesting, easiest and scoring subject.

CLK

A15 High order memory Unspe


High order memory address
A8 address cified

AD7
Low order Low order Read
M/m addr. Opcode M/m addr.
AD0 Immediate

ALE

IO/M

RD
Calculate Execution time of MVI A,32H
Given: Clock Frequency (f) = 2 MHz Positive Vibes:MPI is the interesting, easiest and scoring subject.

Calculation:
1 1
Step-1: T-state = clock period = = = 0.5 sec
𝑓 2
Step-2: Execution time for Opcode Fetch
= 4T x 0.5 = 2sec
Step-3: Execution time for Memory Read
= 3T x 0.5 = 1.5sec
Step-4: Execution time for Instruction
= (4T + 3T) x 0.5
= 7T x 0.5
= 3.5sec

Unit 4 – Assembly Language Basics 57


Timing Diagram : OUT 02H

Opcode Fetch Memory Read I/O Write


T1 T2 T3 T4 T1 T2 T3 T1 T2 T3
Positive Vibes:MPI is the interesting, easiest and scoring subject.

CLK

A15
High order Unspecifi High order memory
Port address 02H
A8 memory address ed address

AD7 Low Low Port Acc.


addr
Opcode addr
02H addr
AD0 content

ALE
IO/M

RD

IOW
Timing Diagram : IN 02H

Opcode Fetch Memory Read I/O Read


T1 T2 T3 T4 T1 T2 T3 T1 T2 T3
Positive Vibes:MPI is the interesting, easiest and scoring subject.

CLK

A15
High order memory Unspecifi High order memory
Port address 02H
A8 address ed address

AD7 Low Low Port Acc.


addr
Opcode addr
02H addr
AD0 content

ALE
IO/M

RD

IOR
GTU Exam Questions
Sr. Questions Marks
Positive Vibes:MPI is the interesting, easiest and scoring subject. Year
1. Draw the timing diagram of following instruction of the 8085 microprocessor. 7 W’17
i. OUT 50h W’18
ii. MOV A, B S’18
iii. MVI A, 8bit S’19
2. How many machine cycles are executed by 8085 microprocessor? List down it. 1 S’18
3. Explain various addressing modes of 8085 microprocessor. 7 S’18
W’18
W’19
4. Identify the machine cycles in the following instructions 7 W’18
1. SUB B
2. ADI 47H
3. STA 2050H
4. PUSH B

Unit 4 – Assembly Language Basics 60


References
Book: Microprocessor Architecture, Programming, and Applications with the
Positive 8085,
Vibes:MPI is the interesting, easiest and scoring subject.

Ramesh S. Gaonkar Pub: Penram International

Mobile 8085 and 8086 Microprocessor Opcodes app from Play Store:
Application http://tiny.cc/aopcodes

Unit 4 – Assembly Language Basics 61


Positive Vibes:MPI is the interesting, easiest and scoring subject.

Thank You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy