352ccs - Lab Manual
352ccs - Lab Manual
Microprocessor &
Assembly Language
Lab Manual
|Page 1
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
Course Syllabus
Course Title Microprocessor and Assembly Language
Course Code 343 CSM -3
• Lab Description
• This lab session is designed to establish a foundation for understanding the
basic Assembly Language Instruction and incorporate Assembly Language
Programming using 8085 Simulator. The experiments are designed to provide
a substantial and motivational lab experience.
• The 8085 Simulator studied programs include:
|Page 2
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
|Page 3
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
14 14 Revision
|Page 4
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
b) Accumulator
It is an 8 bit register which hold one of the data to be processed by ALU and
stored the result of the operation.
c) Program counter (PC)
It is a 16 bit pointer which maintain the address of a byte entered to line stack.
d) Stack pointer (SP)
It is a 16 bit special purpose register which is used to hold line memory
address for line next instruction to be executed.
f) Temporary register
It is an 8 bit register associated with ALU hold data, entering an operation,
used by the microprocessor and not accessible to programs.
g) Flags
Flag register is a group of fire, individual flip flops line content of line flag
register will change after execution of arithmetic and logic operation. The line states
flags are
i) Carry flag (C)
ii) Parity flag (P)
iii) Zero flag (Z)
iv) Auxiliary carry flag (AC)
v) Sign flag (S)
|Page 5
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
j) Register Array
These are used to store 8 bit data during execution of some instruction.
|Page 6
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
|Page 7
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
|Page 8
ﻟﻣﺎ ادﻣﺞ الH وL REGESTER ﺳوا
ﻓﺎﻧﺎ اﻗﺻد اﻟﻣﯾﻣوري ادرس ﻣﻛﺎن ﻓﻲ اﻟﻣﯾﻣوري
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
ﺑروﻗران ﻛﺎوﻧﺗر
اﺷرﺣﻲ اﻟﺗطﺑﯾﻖ
SOLUTION: ﻛﯾف اﻓرق ﺑﯾن اﻟرﺟﯾﺳﺗر ﺑﻧﻔﺳﺟﻲ
اﻻزرق اﻻﻧﺳﺗرﻛﺷن
واﻟداﺗﺎ اﺳود
|Page 10
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
1) Immediate Addressing:
In immediate addressing mode, the data is specified in the instruction itself.
The data will be a part of the program instruction.
EXAMPLE: MVI B, 3EH - Move the data 3EH given in the instruction to B
register;
2) Direct Addressing:
In direct addressing mode, the address of the data is specified in the
instruction. The data will be in memory. In this addressing mode, the program
instructions and data can be stored in different memory.
EXAMPLE: LDA 1050H - Load the data available in memory location
1050H in to accumulator;
3) Register Addressing:
In register addressing mode, the instruction specifies the name of the register
in which the data is available.
|Page 11
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
5) Implied Addressing:
In implied addressing mode, the instruction itself specifies the data to be
operated.
EXAMPLE: CMA - Complement the content of accumulator
|Page 12
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
|Page 13
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
EXAMPLES
a. Move between Register and Register-MOV Rd, Rs
b. Move Immediate Instruction- MVI Rd, 8 bit data
c. Move between Register and Memory- MOV M , r and MOV r, M
d. Load Immediate Register Pair- LXI Rp,16 bit data
e. Store Accumulator Direct- STA addr
f. Load Accumulator Direct- LDA addr
ARITHMETIC INSTRUCTIONS
a) ADD with register/memory
ADD r [or] ADD M
r → register name M → memory location
It is used to add the contents of a specified register or memory to the contents
of the accumulator.
(A) (A) + r.
The result is stored in the accumulator.
b) ADD immediate.
|Page 14
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
LDA 0012H
ADI 8 bit data
It is used to add 8 bit data to the contents of the accumulator.
MOV B,A
(A) (A) + 8-bit data. LDA 0013H
The result is stored in the accumulator. SUB B
STA 0014H
c) ADD with carry HLT
ADC r [or] ADC M
It is used to add the contents of a specified register or memory along with the
carry flag to the contents of the accumulator.
(A) (A) + r + Carry
The result is stored in the accumulator.
e) SUB immediate.
SUI 8 bit data
It is used to subtract 8 bit data from the contents of the accumulator.
(A) (A) - 8-bit data.
The result is stored in the accumulator
|Page 15
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
1050 041A 05 05
1051 041B 12 0C
b) Go to Memory Dump 041B then double click and enter Second Data (Here as 12).
|Page 16
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
c) You can Notice 12 has been changed to 0e (because Decimal Number 12 has
been converted to Hexadecimal 0e)
Step 5: Press OK
|Page 17
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
Output = 11
OUTPUT :
Here B= 5, A = 12
So A-B➔12-5 =7
|Page 18
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
1050 041A 05 05
1051 041B 12 0C
|Page 19
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
DCR r or DCR M
Example: 1
DCR C → Decrements the content of C register by 1 and the new value is
stored in C register.
INX rp
This instruction increments the contents of the specified register pair by 1.
(rp) (rp) +1
The register pair used are BC, DE, HL and the 16-bit Stack Pointer.
The result is stored in the specified register pair itself.
|Page 20
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
INPUT Memory Equivalent Data (In Data Converted
Address in Memory Decimal)
Program Dump (In
HexaDecimal
1050 1050 04 04
1051 1051 02 02
1053 041d 0
1050 1050 10 oa
1051 1051 30 10
1053 041d 1
|Page 21
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
INPUT Memory Equivalent Data (In Data Converted(In
Address in Memory Decimal) HexaDecimal
Program Dump
4150 1036 02 02
4151 1037 07 07
4151 1039 03 03
1050 1036 03 03
1051 1037 15 0f
1053 1039 05
|Page 22
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
Instruction for Flags, Use Carry Flag in Addition and use borrow
in Subtraction.
.
• Objectives / Statement Purpose:
To perform 8 Bit Addition using Carry and 8 Bit Subtraction with Borrow.
• Activity Outcomes:
Student should get familiar with Arithmetic Operations like Addition with Carry
and Subtraction with Borrow.
|Page 23
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
Here A = 24010 = FO16
B = 4910 = 3116
A+B = 28910 = 12116
1001 0803 49 31
|Page 24
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
(or)
ALGORITHM:
1) Load HL Register with Memory Address 1000
2) Move the First Data From Memory to Accumulator
3) Increment HL Pair
4) Move the Second Data From Memory to Register B
5) Load Register C as 0 for Carry
6) Add the Accumulator and Register B Content
7) If No Carry Do Step 9
8) Increment Register C (Carry is there)
9) Increment HL Pair
10) Move the Accumulator Content( Result) to Memory Location specified by
HL Pair
11) Increment HL Pair
12) Move the Register C( Carry) to Memory Location specified by HL Pair
OUTPUT :
Here A = 24010 = FO16
B = 4910 = 3116
A+B = 28910 = 12116
1001 1001 49 31
|Page 25
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
Here B = 1710 = 1116 A = 0310 = 0316 A-B = 0310-1710 = - 1410
Here the Answer is Negative so find 2’s Complement of 14 ➔ 0000 1110
1’s Complement of 14 ➔ 1111 0001
+1➔ 1
2’s Complement of 14 ➔ 1111 0010 ➔F216
1003 0805
1003 0805
|Page 26
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
Example
CMP B
If (B) > (A) , then Carry flag is set
If (B) = (A) , then Zero flag is set
If (A) > (B) , then No flag is set
|Page 27
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
1000 1000 04 04
1001 1001 08 08
1001 1001 10 0a
|Page 28
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
It is used to add the contents of HL pair with the contents of register pair mentioned in
the instruction. (HL) (HL) + (register pair).
The result is stored in the accumulator.
Example: 1
DAD B
Adds the content of the HL register with the content of the BC register pair stores the
result in the HL register pair
HL HL+BC
SHLD (store H and L register direct): The contents of register L are stored into
the memory location specified by the 16-bit address in the operand and the
contents of H register are stored into the next memory location by incrementing
the operand. The contents of registers HL are not altered. This is a 3-byte
instruction, the second byte specifies the low-order address and the third byte
specifies the high-order address.
Example: SHLD 2470
|Page 29
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
1000 1000 02 02
1001 1001 03 03
1002 1002 04 04
1003 1003 05 05
1005 1005 06 06
|Page 30
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
INPUT Memory Equivalent Data Data Converted
Address in Memory
Program Dump (In Decimal) (In
HexaDecimal
1000 1000 05 05
1001 1001 09 09
1002 1002 03 03
1003 1003 06 06
1005 1005 02 02
(Or)
ALGORITHM:
1) Get the Higher Order Bit of first 16-Bit Numbers in A and Move to Register D
2) Get the Lower Order Bit of first 16-Bit Numbers in A and Move to Register E
3) Get the Higher Order Bit of Second 16-Bit Numbers in A and Move to
Register H
4) Get the Lower Order Bit of Second 16-Bit Numbers in A and Move to
Register L
5) Move E Register Content to Accumulator
6) Subtract L From A
7) Move D Register Content to Accumulator
8) Subtract H From A
9) Store the Result in 1004 using SHLD Command
OUTPUT :
1000 1000 05 05
|Page 31
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
1001 1001 09 09
1002 1002 03 03
1003 1003 06 06
1005 1005 02 02
|Page 32
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
|Page 33
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
1000 1000 7 07
1001 1001 12 0c
1002 1002 35 23
1003 1003 60 3c
1004 1004 10 0a
1005 1005 2 2
1006 1006 5 5
1007 1007 22 16
|Page 34
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
INPUT Memory Equivalent Data Data Converted
Address in Memory
Program Dump (In Decimal) (In HexaDecimal
1000 1000 7 07
1001 1001 12 0c
1002 1002 35 23
1003 1003 60 3c
1004 1004 10 0a
1005 1005 2 2
1006 1006 5 5
1007 1007 22 16
|Page 35
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
|Page 36
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
1000 1000 05 05
INPUT
1001 1001 04 04
1002 1002 02 02
1003 1003 09 09
1004 1004 12 0C
1005 1005 06 06
1000 1000 05 05
1001 1001 02 02
1002 1002 04 04
OUTPUT
1003 1003 06 06
1004 1004 09 09
1005 1005 12 0C
ALGORITHM:
1) Load the address of the Size of Array in HL Register Pair,Move it to C
Register(Array Size)
2) Copy it in D register (For Bubble Sort(N-1) Times
3) Get the First data in A Register
4) Compare it with the value at next location
5) If they are out of order, Swap the Content of A register and memory
6) Decrement D register Content by 1
7) Repeat Steps 4 to 6 till the value in De Register become zero
8) Decrement C register content by 1
|Page 37
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
1000 1000 05 05
INPUT
1001 1001 04 04
1002 1002 02 02
1003 1003 09 09
1004 1004 12 0C
1005 1005 06 06
1000 1000 05 05
1001 1001 12 0C
1002 1002 09 09
OUTPUT
1003 1003 06 06
1004 1004 04 04
1005 1005 02 02
|Page 38
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
Example: 1
ANA B
If A = 97H = 1001 0111
And if B = C5H = 1100 0101
Then ANA B results in A = 1000 0101= 85H
2. ANI 8-bit data
This instruction performs logical AND operation between the accumulator and
the 8 bit data given in the instruction itself.
The result is stored in the accumulator.
Example: 1
ANI 0FH
If A = 97H = 1001 0111
And if 8 bit data = 0FH = 0000 1111
Then ANI 0FH results in A = 0000 0111= 07H in the A register.
b. ROTATE instruction
1. Rotate accumulator right
RRC
Each binary bit of the accumulator is rotated right by one position. Bit D0 is
placed in the position of D7 as well as in the Carry flag. CY is modified
according to bit D0. S, Z, P,AC are not affected.
2. Rotate accumulator left
RLC
|Page 39
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
Each binary bit of the accumulator is rotated left by one position. Bit D7 is
placed in the position of D0 as well as in the Carry flag. CY is modified
according to bit D7. S, Z, P, AC are not affected.
3. Rotate accumulator left through carry
RAL
Each binary bit of the accumulator is rotated left by one position through the
Carry flag. Bit D7 is placed in the Carry flag, and the Carry flag is placed in
the least significant position D0. CY is modified according to bit D7. S, Z, P,
AC are not affected.
4. Rotate accumulator right through carry
RAR
Each binary bit of the accumulator is rotated right by one position through the
Carry flag. Bit D0 is placed in the Carry flag, and the Carry flag is placed in
the most significant position D7. CY is modified according to bit D0. S, Z, P,
AC are not affected.
Example: DAA
|Page 40
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
INPUT:
BCD Number: 0010 0111
We need to enter its Hexa Decimal Equivalent as Input: (1X23) +(1X22) +(1X21)
+ (1X20)
= 32+4+2+1 =39 (Decimal)
Convert 39 to Hexadecimal = 27H
OUTPUT:
0010 0111
2 7
Decimal Number 27 = 1B Hexadecimal.
1000 39 27H
|Page 41
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
ALGORITHM:
1) Load the data 0fH to the accumulator.
2) Move the accumulator content to Register B.
3) Load the Hexa Decimal Number in Location 1000, move it to C and A.
4) Perform ANI (And Immediate) 0f with Accumulator.
5) Move Accumulator Content to E and C Register Content to A
6) Perform AND Operation with the Register B and Accumulator Content.
7) Do RRC (Rotate Accumulator Right) for 4 times then move it to Register D.
8) Check if zero then do step 14.
9) Move 0 to Accumulator
10) Add 16 to Accumulator
11) Convert it to Decimal Using DAA
12) Decrement D Register Content
13) Check if Non Zero then do step 10.
14) Add E to Accumulator.
15) Convert it to Decimal Using DAA
16) Increment the Memory address and move the BCD Equivalent from
Accumulator to that Memory Location.
OUTPUT :
1000 27 1BH
|Page 42
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
|Page 43
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
|Page 44
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
0500 66 42(Hex)
|Page 45
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
0500 11 0B
|Page 46
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
OUTPUT :
|Page 47
King Khalid University Lab Manual
College of Computer Science Microprocessor & Assembly Language
Computer Science Program 352CCS -3
2050 05 05
2060 00 00
2061 01 01
2062 04 04
2063 09 09
LOOK 2064 16 10
UP
TABLE 2065 25 19
2066 36 24
2067 49 31
2068 64 40
2069 81 51
OUTPUT 2051 25 19
|Page 48