Lab Manual: Deccan College of Engineering and Technology
Lab Manual: Deccan College of Engineering and Technology
Lab Manual: Deccan College of Engineering and Technology
LAB MANUAL
Of
MICROPROCESSOR LAB
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
-----------------------------------------------------------------------------------------------------------
INDEX
CYCLE-2
8085 MICROPROCESSOR
The Microprocessor is a programmable device that takes in numbers, performs on them
arithmetic or logical operations according to the program stored in memory and then produces
other numbers as a result (Silicon chip which includes ALU, register circuits & control circuits).
A Programmable Machine can be represented with 4 components:-
1. Microprocessor 3.Memory
2. Input 4.Output
1
Pin Diagram of 8085 Microprocessor
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ES85 MICROPROCESSOR KIT
PROCEDURE OF EXECUTION
Commands and Keys
Reset
This key is located in the main 85 board. On depressing this key the program starts executing
from the beginning or reset address 0000. On power on reset it. Display ES - 85 in local LCD
display.
H (Help Menu)
This key is used go PS-85L help menu and it will display the following commands. Depressing
the space bar key increments to display the next command
KEY FUNCTIONS
A <BEG> ASSEMBLE
B BAUD RATE
D <BEG> DISASSEMBLE
E <BEG><END> EXAMINE
G <BEG> EXECUTE
H HELP COMMANDS
L <OFFSET> DOWN LOAD
M <ADDR> MODIFY
N NORMAL MODE
Q QUIT
R <REG> REGISTER DISPLAY
S SERIAL MODE
T <START><END><DS> BLOCK TRANSFER
U <BEG><END> UP LOAD
17
Steps to Execute the Program on 8085 Microprocessor Kit
Follow the steps given below in order to execute the program on 8085 Microprocessor Kit:
1. Enter Program
2. Enter Data
3. Execute Program
4. Check Result
Procedure:
Press RESET
Press A and Enter starting address of the program ex: 8000 and Press Enter
Ex: A8000
ES85 ------- 8000:
-A8000
Type the Program
Press RESET
Enter G8000, 8000 which will set the program counter to the address
Give the inputs as example
PC: 8000
S8501H, 21-Value
Press spacebar to enter the next input values and Press enter after last input.
Press N and then press comma till restart is triggered (till change of address)
Check the output as
Press Output
S8503H, 21- value
18
PROGRAM NO. 1
19
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Transfer first number in
8003 7E MOV A,M
accumulator.
Increment content of H-L
8004 23 INX H
register pair
Add first number and
8005 86 ADD M
second number
Increment content of H-L
8006 23 INX H
register pair
8007 77 MOV M,A Store sum in 8503 H
Terminate program.
8008 EF RST.5 (Memory points to
0028h)
Result:
INPUT DATA RESULT
Memory location Data Memory Data
location
8501 26H 8503 88H
8502 62H 8504 00H
Viva-Voice Questions:
20
PROGRAM NO. 2
21
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Transfer first number in
8003 7E MOV A,M
accumulator.
Increment content of H-L
8004 23 INX H
register pair
subtract first number and
8005 86 SUB M
second number
Increment content of H-L
8006 23 INX H
register pair
8007 77 MOV M,A Store result in 8503 H
Terminate program.
8008 EF RST.5 (Memory points to
0028h)
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 07H 8503 04H
8502 03H 8504 00H
Viva-Voice Questions:
1. What is the function of LXI H, 8000 H instruction?
22
PROGRAM NO. 3
23
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Sum of msb’s & register
8003 0E MVI C,00H
value in 00h
8004 00
Transfer first number in
8005 7E MOV A,M
accumulator.
Increment content of H-L
8006 23 INX H
register pair
Add first number and
8007 86 ADD M
second number
Jump if no carry to
8008 D2 JNC 800CH
800Ch location
Lower byte data is stored
8009 0C
in memory
Higher byte data is stored
800A 80
in memory
800B 0C INR C Increment register C
Data of accumulator is
800C 32 AHEAD STA 8503H
stored into 8503h address
Lower byte data is stored
800D 03
in memory
Higher byte data is stored
800E 85
in memory
800F 79 MOV A,C MSB’S of sum in A
MSB’S of sum in A is
8010 32 STA 8504H transferred to 8504h
location
Lower byte data is stored
8011 04
in memory
Higher byte data is stored
8012 85
in memory
8013 EF RST.5 Terminate program
24
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 34H 8503 5AH
8502 26H 8504 00H
Viva-Voice Questions:
1. What is the function of JNC instruction?
2. What is the difference between conditional and unconditional jump instruction?
3. What is the function of STA 2500$ instruction?
4. What is multi byte?
25
PROGRAM NO. 4
26
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Sum of msb’s & register
8003 0E MVI C,00H
value in 00h
8004 00
Transfer first number in
8005 7E MOV A,M
accumulator.
Increment content of H-L
8006 23 INX H
register pair
Add first number and
8007 86 ADD M
second number
8008 27 DAA
Jump if no carry to
8009 D2 JNC 800CH
800Ch location
Lower byte data is stored
800A 0C
in memory
Higher byte data is stored
800B 80
in memory
800C 0C INR C Increment register C
Data of accumulator is
800D 32 AHEAD STA 8503H
stored into 8503h address
Lower byte data is stored
800E 03
in memory
Higher byte data is stored
800F 85
in memory
8010 79 MOV A,C MSB’S of sum in A
MSB’S of sum in A is
8011 32 STA 8504H transferred to 8504h
location
Lower byte data is stored
8012 04
in memory
Higher byte data is stored
8013 85
in memory
EF RST.5 Terminate program
27
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 34H 8503 5AH
8502 26H 8504 00H
Viva-Voice Questions:
1. What is the function of DAA instruction?
2. What is the difference between the MOV & MVI opcodes?
3. What is the function of JNC instruction?
28
PROGRAM NO. 5
Viva-Voice Questions:
1. What is the function of DAA instruction?
2. What is the difference between the MOV & MVI opcodes?
3. What is the function of JNC instruction?
29
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Copy immediate data 99
8003 3E MVI A,99H
in A
8004 99
8005 96 SUB M 9’s complement
Increment content of A
8006 3C INR A
register
Decrement content of H-
8007 2B DCX H
L register pair
Addition of
8008 86 ADD M complemented data and
the second number
Decimal Accumulator
8009 27 DAA
Adjust
Data of accumulator is
800A 32 STA 8503H
stored into 8503h address
800B 03
800C 85
800D EF RST.5 Terminate program
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 34H 8503 5AH
8502 26H 8504 00H
30
PROGRAM NO. 6
31
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Get first 16-bit number in
8000 2A LHLD 8501 H
HL
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Save first 16-bit number
8003 EB XCHG
in de
Get second 16-bit
8004 2A LHLD 8503 H
number in HL
Lower byte data is stored
8005 03
in memory
Higher byte data is stored
8006 85
in memory
Get lower byte of the
8007 7B MOV A,E
first number
Add lower byte of the
8008 95 ADD L second number
800F 85
32
Result:
INPUT DATA RESULT
Memory location Data Memory Data
location
8501 02H 8505 07H
8502 03H 8506 07H
8503 05H
8504 04H
Viva-Voice Questions:
33
PROGRAM NO. 7
SUBTRACTION OF TWO 16
16-BIT NUMBERS
Aim: Program for Subtraction of two 16
16-bit numbers.
Apparatus required: 8085 Microprocessor Kit
Kit, +5V Power supply, keyboard
Theory:
Consider the first 16-bit
bit number 09H & 05H is stored in memory location 8501H
8 &
8502h, the second 16-bit
bit number 05H & 04H is stored in memory location 8503H
8 &
8504h.The result after Subtraction of two numbers is to be stored in the memory location
8505 H(LSB’s difference
difference) & 8506H(MSB’s difference).. Assume program
progra starts from
memory location 8000H.
Algorithm:
Start the program by loading HL register pair with address of 1st number.
Copy the data to DE register pair.
Load the second number to HL pair.
Subtract the two register pair contents and check for carry.
Store the value of difference and borrow in memory locations.
Terminate the program.
Flow chart:
34
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Get first 16-bit number in
8000 2A LHLD 8501 H
HL
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Save first 16-bit number
8003 EB XCHG
in de
Get second 16-bit
8004 2A LHLD 8503 H
number in HL
Lower byte data is stored
8005 03
in memory
Higher byte data is stored
8006 85
in memory
Get lower byte of the
8007 7B MOV A,E
first number
Subtract lower byte of
8008 95 SUB L the second number
35
Result:
INPUT DATA RESULT
Memory location Data Memory Data
location
8501 09H 8505 04H
8502 05H 8506 01H
8503 05H
8504 04H
Viva-Voice Questions:
36
PROGRAM NO. 8
37
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load Address Of
8000 3A LDA 8100 H Number In H-L Register
Pair
Lower Byte Data Is
8001 00
Stored In Memory
8002 81
Complement
8003 2F CMA
Accumulator
8004 32 STA 8101H Store The Result
8005 01
8006 81
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8100 03 8101 FC
Viva-Voice Questions:
1. What is the function of LDA instruction?
2. What is the function of CMA?
3. What is the function of STA?
38
PROGRAM NO. 9
39
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load Address Of
8000 3A LDA 8100 H Number In H-L Register
Pair
Lower Byte Data Is
8001 00
Stored In Memory
8002 81
Complement
8003 2F CMA
Accumulator
8004 3C INR A Increment
8006 01
8007 81
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8100 02 8101 FE
Viva-Voice Questions:
1. What is the function of LDA instruction?
2. What is the function of CMA?
3. What is the function of STA?
4. Explain the working of 2’s complement
5. What is the function of INR & INX opcodes?
40
PROGRAM NO. 10
41
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load Address Of
8000 3A LDA 8100 H Number In H-L Register
Pair
8001 00
8002 81
Move The Number Into
8003 7E MOV A,M
Accumulator
Complement
8004 2F CMA
Accumulator
8005 32 STA 8102H Store The Result
8006 02
8007 81
800C 03
800D 81
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8100 11 8102 6E
8101 11 8103 EE
42
PROGRAM NO. 11
43
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8100 H Load Accumulator
8001 00
8002 81
Move The Number Into
8003 7E MOV A,M
Accumulator
Complement
8004 2F CMA
Accumulator
8005 3C INR A Increment Accumulator
8006 32 STA 8102H Store The Result
8007 02
8008 81
8009 23 INX H Increment HL Reg.Pair
Move The Number Into
800A 7E MOV A,M
Accumulator
Complement
800B 2F CMA
Accumulator
800C 3C INR A Increment Accumulator
800D 32 STA 8103H Store The Result
800E 03
800F 81
8010 76 HLT Terminate
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8100 19 8102 E7
8101 23 8103 DD
44
PROGRAM NO. 12
Flow chart:
START
Store Data
Store Data
STOP
45
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8501 H Load Accumulator
8001 01
8002 85
Move Accumulator Data
8003 47 MOV B,A
Into A
8004 3A LDA 8502 H Load Accumulator
8005 02
8006 85
8007 32
8008 01
8009 85
Move Data Into
800A 78 MOV A, B
Accumulator
800B 32 STA 8502H Store The Result
800C 02
800D 85
800E 76 HLT
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 12 8501 13
8502 13 8502 12
Viva-Voice Questions:
1. Write A Simple Code To Exchange Data Using XCHG Opcode
2. Difference between LDA & STA opcodes
46
PROGRAM NO. 13
47
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8500 H Load Accumulator
8001 00
8002 85
Move Accumulator into
8003 5F MOV E, A
E
8004 3A LDA 8501 H Load Accumulator
8005 01
8006 85
Move Accumulator into
8007 4F MOV C, A
C
8008 21 LXI H,0000H Load Data Into HL
8009
800A
Data Of D Register Pair
800B 19 DAD D
With HL Register Pair
800C 0D DCR C Decrement C register
800D C2 JNZ
800E 0B
800F 80
Store HL Register Pair
8010 22 SHLD 8600H Data Into Memory
Location
8011 00
8012 86
8013 76 HLT Terminate
48
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8500 03 8600 03
8501 01
Viva-Voice Questions:
1. Explain the opcode DAD
2. What is the operands of DAD opcode
3. Explain the SHLD opcode
49
PROGRAM NO. 14
ADDITION OF 5 NUMBERS IN ARRAY
Aim: program to perform addition of 5 numbers in array.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The counter is set for 5 values. The HL register pair is loaded with the 5 numbers
simultaneously by incrementing the HL register pair and decrementing the counter till
zero. The result is stored in the last memory address. Assume that program starts at
8000h address location.
Algorithm:
C register is used as counter and loaded with 05h and accumulator with 00h numbers.
Load HL register pair with 8200h
The accumulator 00h value and the first number is added and stored in A
HL register pair is incremented and the counter is decremented till counter =00h
The result is stored in memory
Flow chart:
50
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 0E MVI C,05H Counter Set to 05h
8001 05
8002 3E MVI A,00H Accumulator Set to 00h
8003 00
Load HL register pair
8004 LXI H,8200H
with immediate data
8005 00
8006 82
8007 86 BACK ADD M Add to memory
Increment HL Register
8008 23 INX H
Pair
8009 0D DCR C Decrement Counter
800A C2 JNZ BACK Jump if no zero
800B 07
800C 80
Copy Data Of A To
800D 77 MOV M,A
Memory
800E 76 HLT Halt
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 05
8201 10
8202 15 8205 75
8203 20
8204 25
Viva Questions:
1. What is the function of JNZ opcode
2. Difference between HALT and RST instructions
51
PROGRAM NO. 15
LARGEST BETWEEN TWO NUMBERS
Aim: Program to find largest between two numbers.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The first number is stored in 8200h and the HL reg.pair is incremented and the second
number is compared with the first. Depending on the sign flag (if positive) first number is
stored in memory.
Algorithm:
Load HL register pair with 8200h
Copy first number into A.
HL register pair is incremented.
First and second number are compared and result is stored in memory
Flow chart:
52
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load data into HL
8000 21 LXI H, 8200 H
register pair
8001 00
8002 82
8003 7E MOV A, M Copy data into A
Increment HL register
8004 D3 INX H
pair
8005 BE CMP M Compare
8006 F2 JP 800AH Jump on Plus
8007 0A
8008 80
8009 7E MOV A, M Copy data into A
Store The Result In
800A 32 STA 8400H
Memory
800B 00
800C 84
800D 76 HLT Halt
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 03 8400 03
8201 01
Viva-Voice Questions:
1. Explain the 8085 FLAGS.
2. Explain the instruction JP.
3. Explain about CMP instruction.
53
PROGRAM NO. 16
SMALLEST BETWEEN TWO NUMBERS
Aim: Program to find smallest between two numbers.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The first number is stored in 8200h and the HL reg.pair is incremented and the second
number is compared with the first. Depending on the sign flag number is stored in
memory.
Algorithm:
Load HL register pair with 8200h
Copy first number into A.
HL register pair is incremented.
First and second number are compared and result is stored in memory
Flow chart:
54
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load data into HL
8000 21 LXI H, 8200 H
register pair
8001 00
8002 82
8003 7E MOV A, M Copy data into A
Increment HL register
8004 D3 INX H
pair
8005 BE CMP M Compare
8006 F2 JM 800AH Jump on Minus
8007 0A
8008 80
8009 7E MOV A, M Copy data into A
Store The Result In
800A 32 FW STA 8400H
Memory
800B 00
800C 84
800D 76 HLT Halt
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 01 8400 01
8201 03
Viva-Voice Questions:
1. Explain the 8085 FLAGS.
2. Explain the instruction JM.
3. Explain about CMP instruction.
55
PROGRAM NO. 17
MULTIPLYING A NUMBER BY 2
Aim: Program to Perform Multiplication.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in accumulator and rotated left is performed and the result is stored
in memory.
Algorithm:
Load A with 8200h.
The Number Is Rotated Left
Result Is Stored In Memory
Flow chart:
START
LOAD NUMBER
INTO
ACCUMULATOR
ROTATE LEFT
STORE
RESULT
FROM A TO
MEMORY
STOP
56
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8200H Load Accumulator
8001 00
8002 82
8003 07 RLC Rotate Left
Store The Result In
8004 32 STA 8400H
Memory
8005 00
8006 84
8007 76 HLT Halt
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 06 8400 0C
Viva-Voice Questions:
1. Explain rotate left with example.
2. Differentiate different rotate operations.
57
PROGRAM NO. 18
MULTIPLYING A NUMBER BY 4
Aim: Program to Perform Multiplication.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in accumulator and rotate left is performed twice and the result is
stored in memory.
Algorithm:
Load A with 8200h.
The Number Is Rotated Left twice.
Result Is Stored In Memory
Flow chart:
START
LOAD NUMBER
INTO
ACCUMULATOR
ROTATE LEFT
STORE
RESULT
FROM A TO
MEMORY
STOP
58
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8200H Load Accumulator
8001 00
8002 82
8003 07 RLC Rotate Left
8004 07 RLC Rotate Left
Store The Result In
8005 32 STA 8400H
Memory
8006 00
8007 84
8008 76 HLT Halt
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 02 8400 08
Viva-Voice Questions:
1. Explain rotate left with example.
2. Differentiate different rotate operations.
59
PROGRAM NO. 19
DIVIDING A NUMBER BY 2
Aim: Program to Perform Division.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in accumulator and rotate right is performed and the result is stored
in memory.
Algorithm:
Load A with 8200h.
The Number Is Rotate right
Result Is Stored In Memory
Flow chart:
START
LOAD NUMBER
INTO
ACCUMULATOR
ROTATE RIGHT
STORE
RESULT
FROM A TO
MEMORY
STOP
60
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8200H Load Accumulator
8001 00
8002 82
8003 07 RRC Rotate Right
Store The Result In
8004 32 STA 8201H
Memory
8005 00
8006 84
8007 76 HLT Halt
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 03 8201 FC
Viva-Voice Questions:
1. Explain rotate right with example.
2. Differentiate different rotate operations.
61
PROGRAM NO. 20
FIND ODD OR EVEN NUMBER
Aim: Program to find even or odd number.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in accumulator and rotated right is performed. If the number is even
EE is printed and if the number is odd 00 is printed.
Algorithm:
Store the input data bytes in consecutive memory locations.
Rotate right.
Fetch each data byte and check it D0 bit.
If D0 bit=0 then even, else odd.
Store odd in memory locations. Store even in some other consecutive memory location.
Flow chart:
START
LOAD NUMBER
INTO
ACCUMULATOR
STORE
RESULT
FROM A TO
MEMORY
STOP
62
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8200H Load Accumulator
8001 00
8002 82
8003 07 RRC Rotate Right
8004 32 MVI A,00H Print 00 if odd
8005 00
8006 0A JC FN Jump on carry
8007 0B
8008 80
8009 3E MVI A,EEH Print EE if EVEN
800A EE
Store The Result In
800B 32 FN STA 8400H
Memory
800C 00
800D 84
800E 76 HLT Halt
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 03 8400 00
Viva-Voice Questions:
1. Explain the load operations.
2. Explain jump instructions.
3. Explain store operations.
63
PROGRAM NO. 21
64
Flow chart:
65
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 2A LHLD 8501H Load into HL
8001 01
8002 85
8003 3A LDA 8503 H Load Accumulator
8004 03
8005 85
Move Accumulator into
8006 47 MOV B, A
B
8007 0E MVI C,08H Initialize Counter
8008 08
Data Of D Register Pair
8009 29 LOOP DAD D
With HL Register Pair
800A 7C MOV A,H Move H data into A
800B 90 SUB B Subtract B
800C 0A JC AHEAD Jump on carry
800D 11
800E 80
800F 67 MOV H,A Move A data into H
8010 2C INR L Increment L
8011 0D DCR C Decrement C
8012 C2 JNZ LOOP Jump on no zero
8013 09
8014 80
8015 22 SHLD 8504H Store Result
8016 04
8017 85
8018 EF HLT Terminate
66
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 54 8504 09
8502 00 8505 03
8503 09
Viva-Voice Questions:
1. Explain Branch Instructions.
2. Explain jump instructions.
3. Explain DAD instruction.
67
PROGRAM NO. 22
68
69
Program:
70
CYCLE-2
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
Introduction to MASM
The Microsoft macro assembler is an x86 high level assembler for DOS and Microsoft
windows. It supports wide varieties of macro facilities and structured programming
idioms including high level functions for looping and procedures
A program called assembler used to convert the mnemonics of instructions along with
the data into the equivalent object code modules, these object code may further
converted into executable code using linked and loader programs. This type of program
is called as ASSEMBLY LANGUAGE PROGRAMMING. The assembler converts and
Assembly language source file to machine code the binary equivalent of the assembly
language program. In this respect, the assembler reads an ASCII source file from the
disk and program as output. The major different between compilers for a high level
language like PASCAL and an Assembler is that the compiler usually emits several
machine instructions for each PASCAL statement. The assembler generally emits a
single machine instruction for each assembler language statement.
Attempting to write a program in machine language is not particularly bright. This
process is very tedious, mistakes, and offers almost no advantages over programming in
assembly language. The major disadvantages over programming in assembly language
over pure machine code are that you must first assemble and link a program before you
can execute it. However attempting to assemble the code by hand would take for longer
than the small amount of time that the assembler takes the perform conversion for you.
An assembler like Microsoft Macro Assembler (MASM) provides a large number of
features for assembly language programmers. Although learning about these features
take a fair amount of time. They are so useful that it is well worth the effort.
MASM PROG.ASM
The MASM program will assemble the PROG.ASM file. (To create PROG.OBJ
from PROG.ASM)
To link more than one object file use + signs between their file names as in:
LINK PROGA+PROGB+PROGC
71
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
72
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
DEBUG loads into memory like any other program, in the first available slot. The memory space used by
www.foxitsoftware.com/shopping
DEBUG for the user program begins after the end of Debug’s code. If an .EXE or .COM file were
specified, DEBUG would load the program according to accepted DOS conventions.
DEBUG uses a minus sign as its command prompt, so should see a “-“ appear on display.
ASSEMBLER DIRECTIVES: The limits are given to the assembler using some pre defined alphabetical
strings called Assembler Directives which help assembler to correctly understand. The assembly
language programs to prepare the codes.
DB GROUP EXTRN
DW LABEL TYPE
DQ LENGTH EVEN
DT LOCAL SEGMENT
ASSUME NAME
END OFFSET
ENDP ORG
ENDS PROC
EQU PTR
73
DB-Define Byte: The DB drive is used to reserve byte of memory locations in the available on memory.
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
DEBUG loads into memory like any other program, in the first available slot. The memory space
used by DEBUG for the user program begins after the end of Debug’s code. If an .EXE or .COM file
were specified, DEBUG would load the program according to accepted DOS conventions.
DEBUG uses a minus sign as its command prompt, so should see a “-“ appear on display.
To get a list of some commands available with DEBUG is:
T -- trace (step by step execution)
U -- un assemble
D -- dump
G -- go (complete execution)
H -- Hex
74
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
ASSEMBLER DIRECTIVES: The limits are given to the assembler using some pre defined alphabet-
ical strings called Assembler Directives which help assembler to correctly understand. The assembly
language programs to prepare the codes.
DB GROUP EXTRN
DW LABEL TYPE
DQ LENGTH EVEN
DT LOCAL SEGMENT
ASSUME NAME
END OFFSET
ENDP ORG
ENDS PROC
EQU PTR
DB-Define Byte: The DB drive is used to reserve byte of memory locations in the available on
memory.
DW-Define Word: The DW drive is used to reserve 16 byte of memory location available on memory.
DQ-Define Quad Word (4 words): The DB directives is used to reserve 8 bytes of memory locations
in the memory available.
DT-Define Ten Byte: The DT directive is used to reserve 10 byte of memory locations in the available
memory.
ASSUME: Assume local segment name the Assume directive is used to inform the assembler. The
name of the logical segments to be assumed for different segment used in programs.
END: End of the program the END directive marks the end of an ALP.
EQU: The directive is used to assign a label with a variable or symbol. The directive is just to reduce
recurrence of the numerical values or constants in the program.
SEGMENT: The segment directive marks the starting of the logical segment.
75
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
76
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
PROGRAM:
DATA SEGMENT
N1 DW 0005H
N2 DW 0002H
RES DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA START: MOV AX,
DATA
MOV DS, AX
MOV AX, N1
MOV BX, N2
ADD AX, BX
MOV RES, AX
INT 21H
CODE ENDS
END START
RESULT:
AX = 0007h
PROGRAM:
DATA SEGMENT
N1 DW 0005H
N2 DW 0003H
RES DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,N1
MOV BX,N2
SUB AX,BX
MOV RES,AX
INT 21H
CODE ENDS
END START
RESULT:
AX = 0002h
77
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
ALGORITHM:
1. Start.
2. Initialize counter = 10.
3. Initialize array pointer.
4. Sum = 0.
5. Get the array element pointed by array pointer.
6. Add array element in the Sum.
7. Increment array pointer decrement counter.
8. Repeat steps 4, 5 & 6 until counter = 0.
9. Display Sum.
10. Stop.
PROGRAM:
DATA SEGMENT
ARRAY DB 12H, 24H, 26H, 63H, 25H, 86H, 2FH, 33H, 10H, 35H
SUM DW 0
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
RESULT:
AX = 0211h
78
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
4 implement ALP to find the maximum number in the array. www.foxitsoftware.com/shopping
ALGORITHM:
1. Start.
2. Initialize data segment.
3. Initialize the pointer.
4. Initialize counter = 0.
5. Initialize the array base pointer.
6. Get the maximum number.
7. Compare the number with maximum number.
8. If num> MAX, Max = num & increment pointer.
9. Decrement the counter.
10. If count = 0 stop or else repeat steps 6, 7, 8, 9.
11. Store maximum number.
12. Stop.
PROGRAM:
DATA SEGMENT
N DB 05H
LIST DB 12H,34H,41H,
10H,15H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV AX,0000H
LEA SI,LIST
MOV AL,[SI]
INC SI
MOV CL,N
DEC CL
BACK:
CMP AL,[SI]
JNC MAX
MOV AL,[SI]
MAX:
INC SI
DEC CL
JNZ BACK
INT 03H
CODE ENDS
END START
RESULT:
79
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
5. To implement ALP to search a number in an array.
PROGARM:
DATA SEGMENT
N DB 05H
LIST DB 12H,34H,41H,10H,15H
ITEM DB 34H
DATA ENDS CODE
SEGMENT
80
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
DATA SEGMENT
N1 DW 0005H
N2 DW 0002H
RES1 DW ?
RES2 DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS: DATA
START:
MOV AX,DATA
MOV DS,AX
MOV DX , 0000H
MOV AX ,N1
MOV BX, N2
MUL BX
MOV RES1 , AX
MOV RES2 , BX
INT 03H
CODE ENDS
END START
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
DATA SEGMENT
N1 DW 4444H
N2 DW 2222H
RES1 DW ?
RES2 DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,N1
MOV DX,0000H
MOV BX,N2
DIV BX
MOV RES1,AX
MOV RES2,DX
INT 03H
CODE ENDS
END START
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
DATA SEGMENT
ARRAY DB 12H,14H,21H,10H,15H
SUM DW 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV CL,05H
XOR DI,DI
LEA BX,ARRAY
BACK:
MOV AL,[BX+DI]
MOV AH,00
ADD SUM,AX
MOV AX,SUM
INC DI
JNZ BACK
INT 03H
CODE ENDS
END START
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
DATA SEGMENT
N DB 05H
LIST DB 12H,34H,41H,10H,15H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE , DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,0000H
LEA SI,LIST
MOV AL,[SI]
INC SI
MOV CL,N
DEC CL
BACK:
CMP AL,[SI]
JC MIN
MOV AL,[SI]
MAX:
INC SI
DEC CL
JNZ BACK
INT 03H
CODE ENDS
END START
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
10. program to perform ASCENDING SORT numbers
DATA SEGMENT
STRING1 DB 99H,12H,56H,45H,36H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV CH,04H
UP2:
MOV CL,04H
LEA SI,STRING1
UP1:
MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JC DOWN
MOV DL,[SI+1]
XCHG [SI],DL
MOV [SI+1],DL
DOWN:
INC SI
DRC CL
JNZ UP1
DEC CH
JNZ UP2
INT 03
CODE ENDS
END START