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

Lecture 9 Microprocessor Programs

The document discusses program execution. It explains that the CPU fetches instructions from memory addresses sequentially based on the program counter. It shows an example program stored in memory with the CPU executing an "MVI B,7FH" instruction to load the value 7FH into register B, followed by an "ADD B" instruction to add the value in B to the accumulator, and finally a "STA 085Ch" instruction to store the accumulator value at memory address 085C.

Uploaded by

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

Lecture 9 Microprocessor Programs

The document discusses program execution. It explains that the CPU fetches instructions from memory addresses sequentially based on the program counter. It shows an example program stored in memory with the CPU executing an "MVI B,7FH" instruction to load the value 7FH into register B, followed by an "ADD B" instruction to add the value in B to the accumulator, and finally a "STA 085Ch" instruction to store the accumulator value at memory address 085C.

Uploaded by

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

Lecture 9

Microprocessor
Programs
Lecture 9(a)

Program Design
Flowcharts
For complicated problems, flowcharts help
simplify the development of the program.

The design process involves first developing the


algorithm in the form of a flowchart.

The flowchart is then turned into a program.


Example 1

A program to copy a block of data from one block


of locations to the other (copy & paste).
Assume source block starts at 4000h and
destination block starts at 6000h and 1000h
items are to be copied.
Flowchart Start

Labels at points
Example 1 DE = 4000h
where there is a HL = 6000h
junction BC = 1000h

MOVE_NEXT

Move contents of memory pointed by DE


to memory pointed to by HL

Increment DE
Increment HL

Decrement BC

BC = 0? N

Label where two


Y alternate pathways
End exist; label one of the
two paths
Start

Program Example 1 DE = 4000h


HL = 6000h
BC = 1000h

MOVE_NEXT

Move contents of memory pointed by DE


to memory pointed to by HL

START: LXI D,4000H Increment DE


LXI H,6000H Increment HL
LXI B,1000H
Decrement BC
MOVE_NEXT: LDAX D
MOV M,A N
BC = 0?
INX DE
INX HL Y
DCX BC End
JNZ MOVE_NEXT
HLT
Example 1
START: LXI D,4000H ; source block starting address
LXI H,6000H ;destination block start address
LXI B,1000H ; number of items to be moved

MOVE_NEXT: LDAX D ; move from source to A


MOV M,A ; move from A to destination

INX DE ; increment source pointer


INX HL ; increment destnatn. pointer
DCX BC ; decrement counter
JNZ MOVE_NEXT ; repeat till counter is zero
HLT
Tutorial Exercise 7
1. Question 1
2. Question 4
Lecture 9(b)

Assembling Programs
Cont’d
Assembling labels
The program is first assembled with blank
memory spaces left for the 16-bit addresses
corresponding to the label values.

The addresses of labeled instructions are then


read off from the assembly sheet and filled into
each blank memory that should contain a label.
Assembling Modified Example 1
ORG 1850H

START: LXI D,2200H ; source block starting address


LXI H,2900H ;destination block start address
LXI B,400H ; number of items to be moved

MOVE_NEXT: LDAX D ; move from source to A


MOV M,A ; move from A to destination

INX D ; increment source pointer


INX H ; increment destination pointer
DCX B ; decrement counter
JNZ MOVE_NEXT ; repeat till counter is zero
HLT
Memory Contents
address (hex) (hex)
Assembling Modified Example 1 1850
1851
11
00
1852
22
ORG 1850H 1853
21
1854
START: LXI D,2200H 1855 00
LXI H,2900H 29
LXI B,400H
1856
1857 01
MOVE_NEXT: LDAX D 1858 00
MOV M,A 1859 04
INX D 185A 0A
INX H
185B 77
DCX B
JNZ MOVE_NEXT 185C 13
HLT 185D 23
185E 0B
185F C2
Exercise: enter the
1860
program into the 8085 59
MOV_NEXT = 1859H 1861 18
kit and test run it 76
Exercise
THR_HLD EQU 8CH
T_OFF EQU 0FH
T_ON EQU 0F0H

ORG 9000H

START: MVI B,THR_HLD ; Threshold light intensity


IN 80H ; read light intensity
CMP B ; compare to threshold value
JNC LIGHTS_OFF ; branch to switch off lights

MVI A,T_OFF ; code to switch on lights OUT 81H


; turn off lights
JMP START ; check intensity again

LIGHT_OFF: MVI A,T_ON ; code to switch on lights


OUT 81H ; switch on lights
JMP START ; check intensity again

Assemble the program


Example 2
HL points to the memory location containing
the lowest byte in a 32-bit number. The higher
bytes are stored in higher memory locations.
The 32-bit number is a representation of a
floating point number in the IEEE 754 single
format. A program to strip the number into
the biased exponent stored in register C, and
the mantissa stored in register pair DE and
register D. Register D contains the lowest
bits. Only magnitudes are of concern.
Example 2
(HL + 3) 1000 1111
(HL + 2) 0101 1101
(HL + 1) 1110 1001
(HL) 1001 0011

1000 1111 0101 1101 1110 1001 1001 0011


C DE B
Example 2
ORG 4050h

MOV B,M ; lowest byte into B (mantissa)


INX H ; increment the pointer
MOV E,M ; next byte into E (mantissa)
INX H ; increment the pointer
MOV A,M ; next byte into D (mantissa + exp)
ORI 10000000b ; append mantissa integer part
MOV D,A ; highest mantissa bits in D
MOV A,M ; mantissa + exponent LSB
INX H ; increment the pointer
RAR ; exponent LSB into Cy MOV A,M ; sign +
exponent higher bits
RAL ; shift out sign bit, shift in exp LSB
MOV C,A ; biased exponent in register C
HLT ; end program execution`

Assemble the program


Lecture 9(c)

Program Execution
Program Execution Illustration Memory
address (hex)
Contents
(hex)

Program 0850 DB
0851 06
ORG 8050h 0852 06
0853 7F
IN 06h Program 0854 88
MVI B,7FH into 0855 32
ADD B memory 0856 50
STA 085Ch
0857 08
HLT
0858 76
0859 10
085A 6F
085B DD
Ports
Data
085C 14
085D 88
Program
Execute
Fetch Execution
byte Illustration
instruction
instruction
Memory
address (hex)
Contents
(hex)
0850 DB
8085 CPU 0851 06
0852 06
PC 8057
8053
8055
8050
8051
8052
8054
8056
8059
8058 0853 7F
0854 88
IR   3208
DB
06 76
06
7F
5C
88 0855 32
0856 5C
0857 08
A  
16
96
 

0858 76
Port address
0859 Contents
10 (hex)
B  
7F (hex)
085A 6F
04 D5
Cy   01 085B
05
DD
86
085C 14
96
06 16
085D 88
07 E1
High Level Programming
The standard practice is to write programs using high
level programming languages

High level language consists of English-like


statements.
It is easier to comprehend and less tedious to use than
low level programming language.

Compiling is the process of converting a high level


language into machine code
Generally, a single high level program statement may
compile into a number of machine instructions.
High Level Programming
x equ 201h
y equ 202h
z equ 203h

int x,y,z; LDA x


MOV B,A
z = x + y; LDA y
ADD B
STA z
Exercise 5
Exercise 8

1. Question 2
2. Question 3

You might also like