You are on page 1of 47

MICROPROCESSOR

ARCHITECTURE
Lab Experiments

2017
AL KUNOOZ UNIVERSITY COLLEGE
Ass. Lecturer Aqeel Al Ameri
aay.ali80@gmail.com
Microprocessor Architecture Lab 2017
Second Stage

Microprocessor 8085 Lab


Experiment 1

Expirement1: it Consist of two labs (Lab1 & Lab2)

1. Lab1 : Introduction to GNUSim8085 simulator


2. Lab2 : Write an assembly language program

1
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Lab-1: Introduction to use GNUSim8085


Microprocessor 8085 on of the Intel Corporation family. It was the last version of
8-bit general purpose registers and it’s the most successful version of 8-bit
registers.

GNUSim8085 simulator is the software that will be used to apply the experiments
lab. It is a graphical simulator, assembler and debugger for the Intel 8085
microprocessor in Linux and Windows. Blow the features of the software:

 A simple editor component with syntax highlighting.


 A keypad to input assembly language instructions with appropriate
arguments.
 Easy view of register contents.
 Easy view of flag contents.
 Hexadecimal <–> Decimal converter.
 View of stack, memory and I/O contents.
 Support for breakpoints for program debugging.
 One click conversion of assembly program to opcode listing.
 The following snapshot is the main screen for GNUSim8085

Figure 1 is the Snapshot of main screen for GNUSim8085 simulator.

2
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Figure-1: GNUSim8085 main screen

In the file menu you will find a lot of commands can help you to do:

 New: to create a new ASM file (assembly languages program).


 Open: to open ASM file that’s been already saved to computer.
 Save and Save as: to save the current ASM file.
 See figure 2

Figure-2: Commands of File menu


3
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

In the file menu you will find a lot of commands can help you to do:

 Registers: to reset (Set zero value) the registers (A, H, L, B, C, D, E).


 Flags: to reset the flag registers (S, Z, AC, P, and C).
 IO Ports: to reset the values of input/output ports.
 Memory: to reset the memory locations (addresses) of memory.
 Reset All: to reset all above items.
 See figure-3 below

Figure-3: Commands of Reset menu

The general purpose registers (GPR) values as well as the values of accumulator
and flag register could be shown in the figure 4. Each operation (arithmetical and
logical) utilizes the GPR and flag registers so the various values of these registers
could be showed in the figure 5.

4
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Figure-4: shows GPR and Flag Registers values

Figure 5 shows the parts of software that uses to write an assembly language
program.

Figure-5: Pseud code in assembly language

GNUSim8085 can help to perfume some useful functions as per below:

1. Converting the numbers formulas: to convert the number from decimal to


hexadecimal and vice versa. See figure 6 that show the example to convert
between the two formulas.

5
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Example: convert the value 2Fh to decimal value.


Sol.: follow the steps as per shown in figure 6

3 1

Figure-6: Converting Hex to Decimal and vice versa

The result will be appeared in textbox as you can see in step 3. And the result
will be 47 in decimal formula.

2. Changing I/O ports values: The values of I/O ports could be changed as
you can see in example below.
Example2: change the value of port number 4 to be 04H.
Sol: see the steps in figure-7 below:

2
1
3

Figure-7: Changing ports values

6
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

3. Load Values to the Memory: in order to load any value to the memory, the
address of memory location should be specified after that the value loads to
the specified location.
Example 3: load the value to the 2Fh to the memory location address 20h
Sol.: follow the step in figure 8 below

1 2

Figure-8: Load data to the memory locations


ports values

Remark: 2F(16)=47(10) and 20(16)=32(10)

Save the program:


The cod of program writes in assembly languages instructions and the extension of
the program is ASM. To save the program click on save/save as from file menu
then choose the name and location. See figure 9

7
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Name the file here

Figure-9: save the file

8
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Lab-2: Write ALP using 8085 instructions


Write the program:

As mentioned above the code must be written in assembly languages instructions:

Example: write an assembly language program to store a values to the registers B,


C, D, E, H, and L. Suppose the values are: 02h, 04h, 06h,08h, 0A, 0B respectively.

To execute the program we will use the MVI instruction (move), which is used to
move an immediate value into any specified register (move a value to the
registers). The syntax of mentioned instruction as per below:

Opcode Operand Description


R Move 8-bit immediate value to the
MVI
8-bit Data registers

The program:

MVI B,02h
MVI C,04h
MVI D,06h
MVI E,08h
MVI H,0Ah
MVI L,0Bh
HLT

9
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Example 2

Load the value 2F to the accumulator the load it to the registers B, C, D, E, H, and
L
Will use MVI instruction to move the immediate value 2F to accumulator (register
A), then will use the MOV instruction to move the content of accumulator to the
registers B, C, D, E, H, and L

Opcode Operand Description


Move a value from Source Register
MOV R
to the Destination Register

The program:

MVI A,2FH
MOV B,A
MOV C,A
MOV D,A
MOV E,A
MOV H,A
MOV L,A
HLT

10
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Experiment 2
Simple Addition Operation

Expirement1: it Consist of two labs (Lab3 & Lab4)

1. Lab-3: Addition of Two 8-bit Numbers and Sum is 8-bit


2. Lab-4 : Addition of Two 16-bit Numbers and Sum is 16-bit

11
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Lab-3: Addition of two 8-bit numbers and sum is 8-bit

Two types of addition operation could be perfumed in 8085 MP, a simple addition
operation is to add 8-bit number to another 8-bit number and the result will be 8-bit
number. Another type of addition operation is the 16-bit numbers and the result
will be 16-bit number.

Consider the first number is stored in register A and the second number is stored to
the register B, and these two numbers are 2Fh and 08h respectively.

In this case some instructions will be needed to perform the addition operation
above.

Opcode Operand Description


ADD R
Add register or memory to accumulator
M

Opcode Operand Description


ADI 8-bit Data Add immediate to accumulator

Analysis

1. Move first number/data into accumulator (register A)


2. Move second number/data into register B
3. Add the second data with accumulator using ADD instruction

Program
MVI A,2FH

MVI B,08H

ADD B

12
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

HTL

The Result

After the execution of the program the value of register B will be added to
accumulator value and store the result in accumulator. The result is 37H.

The problem above could be solved using instruction ADI instead of instruction
ADD. It means the first number (2Fh) is stored to the accumulator then the second
number must add to the accumulator value as an immediate value.

Program 2:
MVI A,2FH

ADI 08H

HTL

Consider the first number 2FH is stored in memory location 8000H and the second
number 08H is stored in memory location 8001H. In this case we need to load
these two values from memory (read from memory) in order to use them. The LDI
instruction will be used for this task.

Opcode Operand Description


LDA 16-bit Data Load the memory contents to the
Memory Address accumulator

Analysis

1. Load first number from the memory address 8000H to the accumulator
2. Move the value of accumulator to register B
3. Load second number from the memory address 8001H to the accumulator
4. Add register B to the accumulator value
5. See the memory representation in figure 10.

13
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage



8000 2F
8001 08
8002


Figure-10: Memory representation
The program
LDA 8000H

MOV B,A

LDA 8001H

ADD B

HLT

The Result

After the execution of the program above, the memory content of location 8000H
is loaded to the accumulator then it is copied to the register B. the second number
which is located in memory address 8001H is loaded to the accumulator. Finally
the value of register B is added to the accumulator value to get the result of
addition the two numbers and the summation stores in accumulator. The result is
37H.

14
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Lab-4: Addition of two 16-bit numbers and sum is 16-bit

Another type of addition operation is the 16-bit numbers and the result will be 16-
bit number.

We will need instructions which can use with the 16-bit data as per below:

Opcode Operand Description


LHLD 16-bit address Load H-L registers direct

 This instruction copies the contents of memory location pointed out by 16-
bit address into register L.
 It copies the contents of next memory location into register H.
 Example: LHLD 2040 H

Opcode Operand Description


SHLD 16-bit address Store H-L registers direct

 The contents of register L are stored into memory location specified by the
16-bit address.
 The contents of register H are stored into the next memory location.
 Example: SHLD 2550 H, Suppose the content of HL is 10,20 respectively.
So after execute the instruction the content L will be stored to the location
2550 and the content of H will be stored to the location 2551.

15
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage


HL=1020 
2550 20
2551 10
2552

Opcode Operand Description


XCHG None Exchange H-L with D-E

 The contents of register H are exchanged with the contents of register D.


 The contents of register L are exchanged with the contents of register E.
 Example: XCHG

Example: Addition of Two 16-Bit Numbers and Sum is 16-bit

AIM: Write 8085 assembly language program for addition of two16-bit numbers
and sum is 16 bit

The givens: The first 16-bit number is stored in 8501 and 8502 memory locations.
The second 16-bit number is stored in 8503 and 8504 memory locations. After
addition result will be stored from 8505 and 8506 memory locations.

16
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Analysis:

1. Store first 16-bit number in H-L pair.


2. Exchange the contents of D-E pair and H-L pair to store first number in D-E
registers pair.
3. Store second 16-bit number in HL register pair.
4. Addition of 1st and 2nd number

5. Store result in 8505H and 8506H locations

8501 05
8502 01
8503 02
8504 03

Program :

LHLD 8501 H Load the content of 8501H location in L register and H


register is loaded with the content of 8502H location

XCHG The contents of HL register pair are exchanged with D-


E register pair. So that first data is stored in DE register
pair.

LHLD 8503 H Load second 16-bit number (data-2) in H-L pair.

DAD D The contents of D-E pair are added with the contents of
H-L pair and result is stored in H-L pair.

SHLD 8505 H Store LSBs of sum in 8505 and MSBs of sum 8506 H.

HLT

17
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Experiment Result

Input Data Result


Memory Location Data Memory Location Data
8501 05H LSBs of data-1 8505 07H LSBs of sum
8502 01H MSBs of data-1 04H MSBs of sum 04H MSBs of sum
8503 02H LSBs of data-2
8504 03H MSBs of data-2

Conclusion:

The addition of two 16-bit numbers is performed using 8085 microprocessor where
sum is 16-bit

Assignment

1. What is the function of XCHG instruction?


2. How can you load 16-bit data in 8500H and 8501H memory locations?
3. What is the function of DAD D instruction?
4. What is difference between byte and word?

Report

Prepare a report to explain the swapping operation between two 16-bit


numbers which are stored in the memory locations 0000H and 0005H.
Suppose the values of this numbers are 1122H & 3344H respectively. Then
find the summations of mentioned numbers and store the result in memory
address 000FH. Justify the problem solving by a program and real result of
execution.

18
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Experiment 3: Arithmetic Instruction

The purpose of experiment:

1. Learn the arithmetic Instructions and operations


2. Ability to programming the registers and memory locations

2. Arithmetic Instructions

These instructions perform the operations like:


 Addition
 Subtract
 Increment
 Decrement

This experiment consists of two labs:

1. Lab-1: learn the increment / Decrement operations


2. Lab-2: More a practical exercises about the arithmetic operations.

19
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Lab-5: Increment / Decrement Operations

1.1 Addition
Any 8-bit number, or the contents of register, or the contents of memory
location can be added to the contents of accumulator.
 The result (sum) is stored in the accumulator.
 No two other 8-bit registers can be added directly.
 Example: The contents of register B cannot be added directly to the
contents of register C.

Opcode Operand Description


ADD R
Add register or memory to accumulator
M
 The contents of register or memory are added to the contents of
accumulator.

 The result is stored in accumulator.


 If the operand is memory location, its address is specified by H-L pair.
 All flags are modified to reflect the result of the addition.
 Example: ADD B or ADD M

Opcode Operand Description


ADI 8-bit Data Add immediate to accumulator
 The 8-bit data is added to the contents of accumulator.
 The result is stored in accumulator.
 All flags are modified to reflect the result of the addition.
 Example: ADI 45 H

20
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Opcode Operand Description


DAD Reg. pair Add register pair to H-L pair

 The 16-bit contents of the register pair are added to the


 contents of H-L pair.
 The result is stored in H-L pair.
 If the result is larger than 16 bits, then CY is set.
 No other flags are changed.
 Example: DAD B

1.2 Increment / Decrement:
The 8-bit contents of a register or a memory location can be incremented or
decremented by 1.
 The 16-bit contents of a register pair can be incremented or
decremented by 1.
 Increment or decrement can be performed on any register or a memory
location.

Opcode Operand Description


INR R
Increment register or memory by 1
M
 The contents of register or memory location are incremented by 1.
 The result is stored in the same place.
 If the operand is a memory location, its address is specified by the
contents of H-L pair.
 Example: INR B or INR M

21
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Opcode Operand Description


INX R Increment register pair by 1

 The contents of register pair are incremented by 1.


 The result is stored in the same place.
 Example: INX H

Opcode Operand Description


DCR R
Decrement register or memory by 1
M

 The contents of register or memory location are decremented by 1.


 The result is stored in the same place.
 If the operand is a memory location, its address is specified by the
contents of H-L pair.
 Example: DCR B or DCR M

Opcode Operand Description


DCX R Decrement register pair by 1
 The contents of register pair are decremented by 1.
 The result is stored in the same place.
 Example: DCX H

22
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Example:

The sequence numbers (1,2,3,4,5) are stored in the memory locations starting from
5500H. Write an assembly language program to increment the first two numbers
and decrement the last two numbers.

Analysis

1. Load the starting location to the register pair H-L pair.


2. Increment the memory content which specified by HL
3. Increment HL
4. Increment the memory content which specified by HL
5. Increment HL two times respectively.
6. Decrement the memory content (No. 4)
7. Increment HL (last number).
8. Decrement the memory content (No. 5)

Solution:

LXI H,0004H

INR M 5500 01
5501 02
INX H
5502 03
INR M 5503 04
INX H 5504 05
INX H

DCR M

INX H

DCR M

HLT

23
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Results

Input Data Result


Memory Location Data Memory Location Data
5500 H 01 H No.1 5500 H 02 H No.1
5501 H 02 H No.2 5501 H 03 H No.2
5502 H 03 H No.3 5502 H 03 H No.3
5503 H 04 H No.4 5503 H 03 H No.5
5504 H 05 H No.5 5504 H 04 H No.5

24
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Lab-6: Arithmetic Operations Practical

1.3 Subtract
Any 8-bit number, or the contents of register, or the contents of memory
location can be subtracted from the contents of accumulator.
 The result is stored in the accumulator.
 Subtraction is performed in 2’s complement form.
 If the result is negative, it is stored in 2’s complement form.
 No two other 8-bit registers can be subtracted directly.

Opcode Operand Description


SUB R
Subtract register or memory from accumulator
M

 The contents of the register or memory location are subtracted from the
contents of the accumulator.
 The result is stored in accumulator.
 If the operand is memory location, its address is specified by H-L pair.
 All flags are modified to reflect the result of subtraction.
 Example: SUB B or SUB M

Opcode Operand Description


SUI 8-bit Data Subtract register or memory from accumulator

 The 8-bit data is subtracted from the contents of the accumulator.

25
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage
 The result is stored in accumulator.
 All flags are modified to reflect the result of subtraction.
 Example: SUI 45 H

Example 1: Write ALP to subtract two 8-bit values, suppose the two values are
05h and 03h respectively.
MVI a,05H
MVI b,03H
SUB b // SUBTRACT B FROM A LIKE a=a-b
HLT
Example 2: Write ALP to subtract two 8-bit values, using 8-bit immediate value to
be subtracted from the accumulator value.

MVI a , 05H
SUI 03H //subtract immediate value from accumulator(a=a-03h)
HLT
Example 3:

We have two values 03H , 08H are stored in the memory in 1000h , 2000h
respectively. Write ALP program to load the two values and find the subtraction
then store the result in 3000h

The program :
LDA 1000h // load the value in the location 1000h to accumulator

MOV B,A // copy the value of A to B to load next value

LDA 2000H // load the value in the location 2000h to accumulator

SUB B // find the subtract of b from a (a=a-b)

STA 3000h // Store the result in memory location 3000h


HLT

26
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Experiment 4
Using Logical & Brunching Instruction

Purpose of experiment

1. Learn the Logical instruction of 8085


2. Learn the brunching instructions
3. Move the control of program sequence during main program.

27
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Lab-7: logical Instruction

1. Logical Instruction

These instructions perform logical operations on data stored in registers, memory


and status flags.

1.1 Compare
Any 8-bit data, or the contents of register, or memory location can be compares
for:
 Equality
 Greater Than
 Less Than
with the contents of accumulator. The result is reflected in status flags.

Opcode Operand Description


CMP R Compare register or memory with
M accumulator

 The contents of the operand (register or memory) are compared with the
contents of the accumulator.
 Both contents are preserved.
 The result of the comparison is shown by setting the flags of the PSW as
follows:
o if (A) < (reg/mem): carry flag is set
o if (A) = (reg/mem): zero flag is set
o if (A) > (reg/mem): carry and zero flags are reset.
o Example: CMP B or CMP M

28
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Opcode Operand Description


CPI 8-bit data Compare immediate with accumulator

 The 8-bit data is compared with the contents of accumulator.


 The values being compared remain unchanged.
 The result of the comparison is shown by setting the flags of the PSW as
follows:
o if (A) < data: carry flag is set
o if (A) = data: zero flag is set
o if (A) > data: carry and zero flags are reset
o Example: CPI 89H

29
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Lab-8: Branching Instructions

 The branching instruction alter the normal sequential flow.


 These instructions alter either unconditionally or conditionally.

Opcode Operand Description


JMP 16-bit address Jump unconditionally

 The program sequence is transferred to the memory location specified by the


16-bit address given in the operand.
 Example: JMP 2034 H.

Opcode Operand Description


Jx 16-bit address Jump Conditionally

 The program sequence is transferred to the memory location specified


by the 16-bit address given in the operand based on the specified flag
of the PSW.
 Example: JZ 2034 H.

Op code Description Status Flags


JC Jump if Carry CY = 1
JNC Jump if No Carry CY = 0
JP Jump if Positive S=0
JM Jump if Minus S=1
JZ Jump if Zero Z=1
JNZ Jump if No Zero Z=0
JPE Jump if Parity Even P=1
JPO Jump if Parity Odd P=0

30
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Example 1:

Write ALP to find the greater value of two 8-bit numbers. Suppose the numbers
are located in 0004h and 0005h respectively. The result should be stored at the
memory address 0020H.
Sol 1:
LDA 0004H
MOV B,A
LDA 0005H
MOV C,A
SUB B
JP tr ; Jump to the str (address) if the value of accumulator is positive
MOV A,B
JMP str
tr: MOV A,C
str: STA 0020H
HLT
Sol 2:

LDA 0004h
MOV B,A
LDA 0005H
cmp B
JNC str
MOV A,B
str: STA 0020h
HLT
Example 2: write an ALP to find . Suppose the two numbers are located in
the memory addresses 0001h and 0002h.

Note: No multiplication instruction in 8085. Therefore, the repeated addition


operation is utilized instead the multiplication. E.g. the equivalent
operation is . Repetition the first number as much as
possible according to the second number.

31
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

LXI H,0001h
MOV B,M
INX H
MOV C,M
MVI A,00

Adding: ADD B

DCR C
JNZ Adding
STA 0005H
HLT

Assignment Report:

An array is located in the memory starting from address 2020h. it consists of


10 element. Find the summation of this array and store the summation in the
address 5000.

32
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Experiment 5: Practical of Loop and


Brunching Instructions

Lab-9: Branching Instructions

Purpose of experiment:
1. Gain skills and ability to understanding different method
of brunching program
2. Practical the jumping instruction during the same program.

33
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Example1: Write an ALP to simulate the MOD function in order to get


the modulation between two 8-bit numbers.
Suppose the two numbers are located in memory starting from the
address 0000H, and the result should be stored in a memory address
0005H

Solution:
LXI H,0000
MOV A,M
INX H
MOV B,M
CMP B
JC Result
Loop: SUB B
CMP B

JNC Loop
Result: STA 0005
HLT

Example 2: write an ALP to simulate the DIV Function in order to get


the integer division of two 8-bit numbers (div is the division of two
numbers ignoring the fraction part)

34
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Solution
LXI H,0000
MOV A,M
INX H
MOV B,M
MVI C,00
CMP B
JC Result
Loop: SUB B
INR C
CMP B
JNC Loop
Result: MOV A,C
STA 0005
HLT

Example 3: Write an ALP to load the memory address 2000 by the value
02, the next fourth address should be incremented by 02 (each address is
greater than the previous one by 2)

Solution :

MVI A,02

35
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage
LXI H,2000H
MVI C,05H
START: MOV M,A
ADI 02H
INX H
DCR C
JNZ START
HLT

36
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Report:
You have an array consists of 10 of 8-bit elements, stored in the memory
starting from the address 5000H, write ALP to add the immediate value
03H for each address.

Step 1
Set the memory location like the snapshot below:

Step 2:
The below ALP 8085 code to perfume the problem above:

37
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

LXI H,5000H
MVI C,5
add1: MOV A,M
ADI 03
MOV M,A
INX H
DCR C
JNZ add1
HLT

Step 3: The result after execution code above as per below:

38
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Report 3:
Provide a report for below problem:

An array which stored at the location 5000h and ends with the value 25,
explain the suitable steps to find the No. of its elements, then write an
ALP to perform the problem.

39
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Microprocessor 8086 Instructions Set


Experiment 7
1. In this course, we will study the real-mode operation of the 8086
microprocessor via a software emulator known as EMU8086. Real
mode is characterized by a 20-bit segmented memory address
space (giving just over 1 MB of addressable memory) and
unlimited direct software access to all memory and I/O addresses
and peripheral hardware. Nevertheless, real mode provides no
support for memory protection, multitasking, or code privilege
levels.

2. Basic Arithmetic Operation (+, -, *, and /)


8086 MP provides over 20000 instructions, in this experiment will
use the basic arithmetic operations (addition, subtraction,
multiplication, and division).

2.1. Addition Instruction

Opcode Operand Description


R,R Add register to register,
R, [ ] Memory location to register
ADD
[ ],R Register to memory location,
R,Imm Immediate value to register

40
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

2.2. Subtraction Instruction


Opcode Operand Description
R, R Subtract register from register,
R, [ ] Memory content from register
ADD
[ ], R Register from memory content,
R, Imm Immediate value from register

2.3. Multiplication Instruction


Opcode Operand Description
Multiplication register to accumulator
R
MUL Multiplication memory content to
[]
accumulator

2.4. Division Instruction


Opcode Operand Description
Division accumulator by register
R
DIV Division accumulator by memory
[]
content

3. In our experiment the 8086 ALP performs below operation:


 Addition of two values e.g. 10+15
 Subtraction of two values e.g. 20-10
 Multiplication of two values e.g. 5*1
 Division of two values e.g. 5/1

41
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

4. Steps of writing 8086 code:

1. Open emu8086
2. Choose a new file

3. In the whit blank space write the ALC below:


ORG 100h
MOV AX,10 ;set AX by value 10
MOV BX,15 ;set AX by value 15
ADD AX,BX ;AX = AX+BX
MOV CX,20 ;set CX by value 20
SUB CX,10 ;subtract immediate vale 10 from BX
MOV DL,01 ;set DL by value 10
MUL DL ;DL=DL*1
DIV DL ;DL=DL /1

RET

42
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Now : calculate the expression : (10+15)*(20-10)?

org 100h

MOV AX,10

MOV BX,15

ADD AX,BX

MOV CX,20

SUB CX,10

MUL CX

RET

43
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

Experiment 8-Program Structure with variables:

In order to write 8086 ALP allows using variables, a structure of program must be
used as per below:

1. From main screen of emu 8086 click on new


2. Then select empty workspace

3. Write the program structure as per below:

.MODEL SMALL
.STACK 100H
.DATA
{This part allows declaring the variables}

44
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage

.CODE

MAIN PROC
MOV AX,@DATA
MOV DS,AX

{This part is specifying to write the code }

MAIN ENDP
END MAIN

Examples about variables declaring:

.DATA
x db 10 ; the variable x is 8-bit variable with value 10
y dw 20 ; the variable y is 16-bit variable with value 20
A db 10,20,5,3,7 ; a variable A is array has 5 elements
z dw ? ; z is 8-bit variable with no value.

Where :

DB means: define Byte, it allows to declare an 8-bit variable.

DW means: define word, it allows to declare a 16-bit variable.

Example: write 8086 ALP to calculate below expression:

45
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College
Microprocessor Architecture Lab 2017
Second Stage
.MODEL SMALL
.STACK 100H
.DATA
x db 2
y db 3
z db ?

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
mov al,x
mov ch,02
mul ch
mov bl,al
mov al,y
mov ch,03
mul ch
add al,bl
mov ch,05
mul ch
mov z,al
MAIN ENDP
END MAIN

46
Aqeel Al Ameri Technical Computer Engineer Dept.
Al Kunooz University College

You might also like