Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

Link to JUBIN SImulator:

http://vlabs.iitb.ac.in/vlabs-dev/labs_local/microprocessor/labs/exp1/procedure.php

Experiment No.1
AIM: Introduction to 8085 microprocessor Kit.
Study of HEX Keypad:
Study the functions of the following Keys:
LOAD RES 0 8 H
SAVE SET 1 9 L
CODE INC 2 A
STEP DEC 3 B
VI SPH 4 C
RUN SPL 5 D
EXEC PCH 6 E
REG PCL 7 F
LOAD: This command is opposite to save command. The contents of audio
cassette block is loaded (retrieved back) in the system RAM from a given
DS (file name)
SAVE: This command is used to save the contents of specified block on to a
audio cassette for permanent storage.
CODE: When this command key is pressed the address field remains blank, Data
field shows a dot indicating that it expects a code.
User is provided with a table of codes, indicating the meaning and prerequisites
of each code. User loads the appropriate code and executes it by
pressing EXEC.
The monitor branches to the appropriate sub-routines pointed by the code.
STEP: Mere running a program with RUN is done whenever the program
development is complete i.e. to run a final working program. During the
program development stage some sort of aid to execute the part of
program at a time and then test its success is required

The STEP command helps you to do the above.


There are two ways of stepping the program.
SINGLE STEPPING: to execute single instruction at a time, using STEP
command. The STEP command requires a start address, break address

1
and the no.of times the br should occur.
BREAK POINT: set a software breakpoint RST1. This software
breakpoint can be done using the RUN command. It requires RST1 (CFH)
to be inserted to a location where you want to break.
The disadvantage of this method is that you have to insert and remove

'CF' and you have to operate in the RAM area only.


VI: This key causes immediate recoginition of RST 7.5 interrupt and control
passess to location 003C in the monitor. This location has a jump to
location 20CE in user RAM. You can put any instruction or jump in20CE
to 20D0

- Interrupts must be enabled (EI) instruction.


- RST 7.5 must be unmasked (mask reset by SIM instruction)
RUN: This command is used to execute your programs or subroutines from a
specified address.
To execute program from 2100:
Address Data
Press Key RUN PPP XX
2000 2000.
EXEC E
EXEC: Pressing EXEC will place the data field contents into the named register
and terminate the command.
REG: This command allows you to display and optionally modify the contents
of 8085 CPU registers. The various registers are A, B, C, D, E, F, I, H, L,
SPH, SPL, PCH, PCL. (H – higher byte, L – lower byte)
RES: On RES, the display shows MP – 85 as a sign on message, indicating that
the monitor is ready to accept a command. Pressing any non-command
key generates “Err” message. After “-Err” user can immediately give a
valid comand.
SET: You can use this command to SET the address of a required memory
location. A dot in the address field of display indicated that the entry will
be displayed in the address field.
INC: Pressing INC, first time will shift the dot to the data field of display. Data
field will show the contents of the memory location pointed by the
address set. You can modify or retain the data field to any value.\
DEC: DEC acts as similar to INC, except the address field is decremented,
pointing to previous memory locations

SPH: Stack pointer Register (Higher byte)


SPL: Stack pointer Register (Lower byte)
PCH: Program Counter Register (Higher byte)
PCL: Program Counter Register (Lower byte)
0 – F: Hex Keypad
H,L: Registers H & L

2
Experiment No.2
AIM: Addition of two 8bit numbers, sum 8 bit.

Address Mnemonics Operand Opcode Remarks


2000 LXI H, 3000H 21 Load H-L pair with address 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
st
2003 MOV A, M 7E Move the 1 operand from memory to reg. A.
2004 INX H 23 Increment H-L pair.
nd
2005 MOV B, M 46 Move the 2 operand from memory to reg. B.
2006 MVI C, 00H 0E Initialize reg. C with 00H.
2007 00 Immediate value 00H.
2008 ADD B 80 Add B with A.
2009 JNC 200D D2 Jump to address 200DH if there is no carry.
200A 0D Lower-order of 200DH.
200B 20 Higher-order of 200DH.
200C INR C 0C Increment reg. C.
200D INX H 23 Increment H-L pair.
200E MOV M, A 77 Move the result from reg. A to memory.
200F INX H 23 Increment H-L pair.
2010 MOV M, C 71 Move carry from reg. C to memory.
2011 HLT 76 Halt.

Explanation:

 This program adds two operands stored in memory location 3000H and 3001H, along
with considering the carry produced (if any).
 Let us assume that the operands stored at memory location 3000H is FAH and 3001H is
28H.
 Initially, H-L pair is loaded with the address of first memory location.

 The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
 The second operand is moved to register B from memory location 3001H.
 Register C is initialized to 00H. It stores the carry (if any).
 The two operands stored in register A and B are added and the result is stored in
accumulator.
 Then, carry flag is checked for carry. If there is a carry, C register is incremented.
 H-L pair is incremented and the result is moved from accumulator to memory 3002H.

H-L pair is again incremented and carry (either 0 or 1) is moved from register C to memory
location 3003H

3
Output:
Before Execution:
3000H: FAH
3001H: 28H

After Execution:
3002H: 22H
3003H: 01

4
Experiment No.3
AIM: Addition of two 16bit numbers, sum 16 bit.

Address Mnemonics Operand Opcode Remarks


2000 LHLD 3000 H 2A Load H-L pair with data from 3000 H
2001 00
2002 30
2003 XCHG EB Exchange H-L pair with D-E pair
2004 LHLD 3002 H 2A Load H-L pair with data from 3002 H
2005 02
2006 30
2007 MVI C, 00 H 0E Move 0 to C
2008 00
2009 DAD D 19 Add D-E pair with H-L pair
200A JNC 200E H D2 Jump to location 200E H if no carry
200B 0E
200C 20
200D INR C 0C Increment C
200E SHLD 3004 H 22 Store the result at location 3004 H
200F 04
2010 30
2011 MOV A, C 79 Move carry from C to A
2012 STA 3006 H 32 Store the carry at location 3006 H
2013 06
2014 30
2015 HLT 76 Halt

Before Execution:

3000: 16 H
3001: 5A H
3002: 9A H
3003: 7C H

After Execution:

3004: B0 H
3005: 76 H
3006: 01 H

5
Experiment No.4
AIM: Subtract two 8-bit numbers along with considering the borrow.
Program:

Address Mnemonics Operand Opcode Remarks


2000 LXI H, 3000H 21 Load H-L pair with address 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
st
2003 MOV A, M 7E Move the 1 operand from memory to reg. A.
2004 INX H 23 Increment H-L pair.
nd
2005 MOV B, M 46 Move the 2 operand from memory to reg. B.
2006 MVI C, 00H 0E Initialize reg. C with 00H.
2007 00 Immediate value 00H.
2008 SUB B 90 Subtract B from A.
2009 JNC 200D D2 Jump to address 200DH if there is no borrow.
200A 0D Lower-order of 200DH.
200B 20 Higher-order of 200DH.
200C INR C 0C Increment reg. C.
200D INX H 23 Increment H-L pair.
200E MOV M, A 77 Move the result from reg. A to memory.
200F INX H 23 Increment H-L pair.
2010 MOV M, C 71 Move borrow from reg. C to memory.
2011 HLT 76 Halt.

Explanation:

 This program subtracts two operands stored in memory location 3000H and 3001H,
along with considering the borrow taken (if any).
 Let us assume that the operands stored at memory location 3000H is 05H and 3001H is
02H.
 Initially, H-L pair is loaded with the address of first memory location.

 The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
 The second operand is moved to register B from memory location 3001H.
 Register C is initialized to 00H. It stores the borrow (if any).

 The two operands stored in register A and B are subtracted and the result is stored in
accumulator.
 Then, carry flag is checked for borrow. If there is a borrow, C register is incremented.

 H-L pair is incremented and the result is moved from accumulator to memory location
3002H.
 H-L pair is again incremented and borrow (either 0 or 1) is moved from register C to

6
memory location 3003H.

Output:
Before Execution:
3000H: 05H
3001H: 02H

After Execution:
3002H: 03H
3003H: 00H

7
Experiment No.5
AIM: Subtract two 16-bit numbers along with considering the borrow.

Address Mnemonics Operand Opcode Remarks


Load H-L pair with data from
2000 LHLD 3000 H 2A 3000H
2001 00
2002 30
Exchange data from H-L pair with
2003 XCHG EB D-E
Load H-L pair with data from
2004 LHLD 3002 H 2A 3002 H
2005 02
2006 30
2007 MVI B, 00 H 06 Move 0 H to B
2008 00
2009 MVI C, 00 H 0E Move 0 H to C
200A 00
st
200B MOV A, E 7B Move lower order of 1 no. to A
200C SUB L 95 Subtract lower order L from A
Jump to2011 H if there is no
200D JNC 2011 H D2 borrow
200E 0F
200F 20
2010 INR C 0C If borrow, then increment C
2011 MOV E, A 5F Move lower order back to E
st
2012 MOV A, D 7A Move higher order of 1 no. to A
2013 SUB C 91 First, subtract borrow from A
2014 SUB H 94 Now, subtract higher order from A
Jump to 2019 H if there is no
2015 JNC 2019 H D2 borrow
2016 19
2017 20
2018 INR B 04 If borrow, increment B
2019 MOV D, A 57 Move higher order back to D
Exchange the result from D-E
201A XCHG EB with H-L
201B SHLD 3004 H 22 Store the result al location 3004 H
201C 04
201D 30
201E MOV A, B 78 Move borrow to A
201F STA 3006 H 32 Store borrow at location 3006 H
2020 06
2021 30
2022 HLT 76 Halt

Before Execution: After Execution:

3000: 02 H 3004: FE H
3001: 02 H 3005: FD H
04 H 3006: 01 H
8
3002:

3003: 04 H

The result is in 2’s complement form

9
Experiment No.6

AIM: 1’s complement of an 8-bit number

Address Mnemonics Operand Opcode Remarks


2000 LDA 3000H 3A Load H-L pair with data from 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
2003 CMA 2F Complement accumulator.
2004 STA 3001H 32 Store the result at memory location 3001H.
2005 01 Lower-order of 3001H.
2006 30 Higher-order of 3001H.
2007 HLT 76 Halt.

Explanation:
 This program finds the 1’s complement of an 8-bit number stored in memory location
3000H.
 Let us assume that the operand stored at memory location 3000H is 85H.
 The operand is moved to accumulator from memory location 3000H.
 Then, its complement is found by using CMA instruction.
The result is stored at memory location 3001H.

Output:
Before Execution:
3000H: 85H

After Execution:
3001H: 7AH

10
Experiment No.7

AIM: 1’s complement of 16-bit number

Address Mnemonics Operand Opcode Remarks


2000 LHLD 3000H 2A Load H-L pair with operand from 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
2003 MOV A, L 7D Move the lower-order from reg. L to reg. A.
2004 CMA 2F Complement accumulator.
2005 MOV L, A 6F Move the result from reg. A to reg. L.
2006 MOV A, H 7C Move the higher-order from reg. H to reg. A.
2007 CMA 2F Complement accumulator.
2008 MOV H, A 67 Move the result from reg. A to reg. H.
2009 SHLD 3002H 22 Store the result at address 3002H.
200A 02 Lower-order of 3002H.
200B 30 Higher-order of 3002H.
200C HLT 76 Halt.

Explanation:
 This program finds the 1’s complement of 16-bit number stored in memory 3000H-
3001H.

 There is no direct way to find 1’s complement of 16-bit number. Therefore, this can be
accomplished by finding the 1’s complement of two 8-bit numbers.
 Let us assume that the operand stored at memory locations 3000H-3001H is 45H-6AH.
 The operand is loaded into H-L pair from memory locations 3000H-3001H.
 The lower-order is moved from register L to accumulator.
 Its complement is found by using CMA instruction.
 The result obtained is moved back to register L.
 Then, the higher-order is moved from register H to accumulator.
 Its complement is found by using CMA instruction.
 The result obtained is moved back to register H.
 Now, the final result is in H-L pair.
 The result is stored from H-L pair to memory locations 3002H-3003H.

Output:
Before Execution: After Execution:
3000H: 45H 3002H: BAH
3001H: 6AH 3003H: 95H

11
Experiment No.8

AIM: 2’s complement of an 8-bit number.

Address Mnemonics Operand Opcode Remarks


2000 LDA 3000H 3A Load H-L pair with data from 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
2003 CMA 2F Complement accumulator.
2004 INR A 2C Increment accumulator.
2005 STA 3001H 32 Store the result at memory location 3001H.
2006 01 Lower-order of 3001H.
2007 30 Higher-order of 3001H.
2008 HLT 76 Halt.

Explanation:
 This program finds the 2’s complement of an 8-bit number stored in memory location 3000H.
 Let us assume that the operand stored at memory location 3000H is 85H.
 The operand is moved to accumulator from memory location 3000H.
 Then, its complement is found by using CMA instruction.
 One is added to accumulator by incrementing it to find its 2’s complement.
 The result is stored at memory location 3001H.

Output:
Before Execution:
3000H: 85H

After Execution:
3001H: 7BH

12
Experiment No.9

AIM: 2’s complement of 16-bit number

Address Mnemonics Operand Opcode Remarks


2000 LHLD 3000H 2A Load H-L pair with operand from 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
2003 MOV A, L 7D Move the lower-order from reg. L to reg. A.
2004 CMA 2F Complement accumulator.
2005 MOV L, A 6F Move the result from reg. A to reg. L.
2006 MOV A, H 7C Move the higher-order from reg. H to reg. A.
2007 CMA 2F Complement accumulator.
2008 MOV H, A 67 Move the result from reg. A to reg. H.
2009 INX H 23 Increment H-L pair to find 2’s complement.
200A SHLD 3002H 22 Store the result at address 3002H.
200B 02 Lower-order of 3002H.
200C 30 Higher-order of 3002H.
200D HLT 76 Halt.

Explanation:

 This program finds the 2’s complement of 16-bit number stored in memory locations
3000H-3001H.

 There is no direct way to find 2’s complement of 16-bit number. Therefore, this can be
accomplished by finding the 1’s complement of two 8-bit numbers and then
incrementing it to get 2’s complement.
 Let us assume that the operand stored at memory locations 3000H-3001H is 12H-05H.
 The operand is loaded into H-L pair from memory locations 3000H-3001H.
 The lower-order is moved from register L to accumulator.
 Its complement is found by using CMA instruction.
 The result obtained is moved back to register L.
 Then, the higher-order is moved from register H to accumulator.
 Its complement is found by using CMA instruction.
 The result obtained is moved back to register H.
 H-L pair is incremented to get 2’s complement.
 Now, the final result is in H-L pair.
The result is stored from H-L pair to memory locations 3002H-3003H

13
Output:
Before Execution: After Execution:
3000H: 12H 3002H: EEH
3001H: 05H 3003H: FAH

14
Experiment No.10

AIM: Shift left 8-bit number by 1 bit.

Address Mnemonics Operand Opcode Remarks


2000 LDA 3000H 3A Load H-L pair with data from 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
2003 RAL 17 Shift left accumulator.
2004 STA 3001H 32 Store the result at memory location 3001H.
2005 01 Lower-order of 3001H.
2006 30 Higher-order of 3001H.
2007 HLT 76 Halt.

Explanation:

 This program performs the left shift operation on an 8-bit number by one bit stored in
memory location 3000H.
 Let us assume that the operand stored at memory location 3000H is 05H.
 The operand is moved to accumulator from memory location 3000H.
 Then, shift left operation is done by using RAL instruction.
The result is stored at memory location 3001H

Output:
Before Execution:
3000H: 05H

After Execution:
3001H: 0AH

15
Experiment No.11

AIM: Program to Shift Left 8-bit Number by 2 Bit

Opcod
Address Mnemonics Operand e Remarks
Load A with data from 3000
2000 LDA 3000 H 3A H
2001 00
2002 30
2003 RAL 17 Shift Left Accumulator
2004 RAL 17 Shift Left Accumulator
2005 STA 3001 H 32 Store the result at location 3001 H
2006 01
2007 30
2008 HLT 76 Halt

Before Execution:

3000: 05 H

After Execution:

3001: 14 H

16
Experiment No.14
AIM: Mask the lower nibble of an 8-bit number.

Address Mnemonics Operand Opcode Remarks


2000 LDA 3000H 3A Load H-L pair with data from 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
2003 ANI F0H E6 AND Immediate F0H with reg. A.
2004 F0 Immediate value F0H.
2005 STA 3001H 32 Store the result at memory location 3001H.
2006 01 Lower-order of 3001H.
2007 30 Higher-order of 3001H.
2008 HLT 76 Halt.

Explanation:
 This program masks the lower nibble of an 8-bit number stored in memory location
3000H.
 Let us assume that the operand stored at memory location 3000H is 45H.
 The operand is moved to accumulator from memory location 3000H.

 Then, AND operation of F0H is performed with accumulator. This results in the masking
of lower nibble.
The result is stored at memory location 3001H.
Output:
Before Execution:
3000H: 45H

After Execution:
3001H: 40H

17
Experiment No.15
AIM: Mask the higher nibble of an 8-bit number.

Address Mnemonics Operand Opcode Remarks


2000 LDA 3000H 3A Load H-L pair with data from 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
2003 ANI 0FH E6 AND Immediate 0FH with reg. A.
2004 0F Immediate value 0FH.
2005 STA 3001H 32 Store the result at memory location 3001H.
2006 01 Lower-order of 3001H.
2007 30 Higher-order of 3001H.
2008 HLT 76 Halt.

Explanation:
 This program masks the higher nibble of an 8-bit number stored in memory location
3000H.
 Let us assume that the operand stored at memory location 3000H is 45H.
 The operand is moved to accumulator from memory location 3000H.

 Then, AND operation of 0FH is performed with accumulator. This results in the masking
of higher nibble.
The result is stored at memory location 3001H

Output:
Before Execution:
3000H: 45H

After Execution:
3001H: 05H

18
Experiment No.16
AIM: Find the smaller out of two numbers.

Address Mnemonics Operand Opcode Remarks


2000 LXI H, 3000H 21 Load H-L pair with address 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
st
2003 MOV A, M 7E Move the 1 operand from memory to reg. A.
2004 INX H 23 Increment H-L pair.
nd
2005 MOV B, M 46 Move the 2 operand from memory to reg. B.
2006 CMP B B8 Compare B with A.
2007 JC 200BH DA Jump to address 200BH if there is no carry.
2008 0B Lower-order of 200BH.
2009 20 Higher-order of 200BH.
200A MOV A, B 78 Move smallest from reg. B to reg. A.
200B INX H 23 Increment H-L pair.
200C MOV M, A 77 Move the result from reg. A to memory.
200D HLT 76 Halt.

Explanation:
 This program compares two operands to find the smallest out of them.

 After comparison, the smallest of two must be in accumulator. If it is already in


accumulator, then it is moved to memory.

 If it is not in accumulator, then first it is moved to accumulator and then from there, it is
moved to memory.
 Let us assume that the operands stored at memory location 3000H is 25H and 3001H is
15H.
 Initially, H-L pair is loaded with the address of first memory location.

 The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
 The second operand is moved to register B from memory location 3001H.
 The two operands are compared.
 After comparison, if A > B, then CF = 0, and if A < B, then CF = 1.

 Carry flag is checked for carry. If there is no carry, it means B is smaller than A and it is
moved to accumulator.

 At last, H-L pair is incremented and the smallest number is moved from accumulator to
memory location 3002H.

19
Output:
Before Execution:
3000H: 25H
3001H: 15H
After Execution:
3002H: 15H

20
Experiment No.17

AIM: Find the smaller number in an data array.


Address Mnemonics Operand Opcode Remarks
2000 LXI H, 3000H 21 Load H-L pair with address 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
2003 MOV C, M 4E Move counter from memory to reg. C.
2004 INX H 23 Increment H-L pair.
st
2005 MOV A, M 7E Move the 1 number from memory to reg. A.
2006 DCR C 0D Decrement counter.
2007 INX H 23 Increment H-L pair.
2008 MOV B, M 46 Move the next number from memory to reg. B.
2009 CMP B B8 Compare B with A.
200A JC 200EH DA Jump to address 200EH if there is no carry.
200B 0E Lower-order of 200EH.
200C 20 Higher-order of 200EH.
200D MOV A, B 78 Move smallest from reg. B to reg. A.
200E DCR C 0D Decrement counter.
200F JNZ 2007H C2 Jump to address 2007H if counter is not zero.
2010 07 Lower-order of 2007H.
2011 20 Higher-order of 2007H.
2012 INX H 23 Increment H-L pair.
2013 MOV M, A 77 Move the result from reg. A to memory.
2014 HLT 76 Halt.

Explanation:
 This program finds the smallest number in an array.
 Initially, the counter is initialized with the size of an array.
 Then, two numbers are moved to registers A and B, and compared.

 After comparison, the smallest of two must be in accumulator. If it is already in


accumulator, then its fine, otherwise it is moved to accumulator.

 Counter is decremented and checked whether it has reached zero. If it has, the loop
terminates otherwise, the next number is moved to register and compared.

21
 Let us assume that the memory location 3000H stores the counter. The next memory
locations store the array.
 Initially, H-L pair is loaded with the address of the counter and is moved to register C.

 The first number is moved from memory to accumulator and counter is decremented by
one.
 H-L pair is again incremented and second number is moved to register B.
 The two numbers are compared.
 After comparison, if A > B, then CF = 0, and if A < B, then CF = 1.

 Carry flag is checked for carry. If there is no carry, it means B is smaller than A and it is
moved to accumulator.
 Counter is decremented and checked whether it has become zero.

 If it hasn’t become zero, it means there are numbers left in the array. In this case, the
control jumps back to increment the H-L pair and moves the next number to register B.

 This process continues until counter becomes zero, i.e. all the numbers in the array are
compared.

 At last, H-L pair is incremented and the smallest number is moved from accumulator to
memory.

Output:
Before Execution:
3000H: 05H (Counter)
3001H: 15H
3002H: 01H
3003H: 65H
3004H: E2H
3005H: 83H

After Execution:
3006H: 01H

22
Experiment No.18
AIM: Find the larger out of two numbers.

Address Mnemonics Operand Opcode Remarks


2000 LXI H, 3000H 21 Load H-L pair with address 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
st
2003 MOV A, M 7E Move the 1 operand from memory to reg. A.
2004 INX H 23 Increment H-L pair.
nd
2005 MOV B, M 46 Move the 2 operand from memory to reg. B.
2006 CMP B B8 Compare B with A.
2007 JNC 200BH D2 Jump to address 200BH if there is no carry.
2008 0B Lower-order of 200BH.
2009 20 Higher-order of 200BH.
200A MOV A, B 78 Move largest from reg. B to reg. A.
200B INX H 23 Increment H-L pair.
200C MOV M, A 77 Move the result from reg. A to memory.
200D HLT 76 Halt.

Explanation:
 This program compares the two operands to find the largest out of them.

 After comparison, the largest of two must be in accumulator. If it is already in


accumulator, then it is moved to memory.

 If it is not in accumulator, then first it is moved to accumulator and then from there, it is
moved to memory.
 Let us assume that the operands stored at memory location 3000H is 25H and 3001H is
15H.
 Initially, H-L pair is loaded with the address of first memory location.

 The first operand is moved to accumulator from memory location 3000H and H-L pair
is incremented to point to next memory location.
 The second operand is moved to register B from memory location 3001H.
 The two operands are compared.

23
 After comparison, if A > B, then CF = 0, and if A < B, then CF = 1.

 Carry flag is checked for carry. If there is a carry, it means B is greater than A and it is
moved to accumulator.

 At last, H-L pair is incremented and the largest number is moved from accumulator to
memory location 3002H.

Output:
Before Execution:
3000H: 25H
3001H: 15H

After Execution:
3002H: 25H

24
Experiment No.19

AIM: Largest from an array.

Address Mnemonics Operand Opcode Remarks


2000 LXI H, 3000H 21 Load H-L pair with address 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 3000H.
2003 MOV C, M 4E Move counter from memory to reg. C.
2004 INX H 23 Increment H-L pair.
st
2005 MOV A, M 7E Move the 1 number from memory to reg. A.
2006 DCR C 0D Decrement counter.
2007 INX H 23 Increment H-L pair.
2008 MOV B, M 46 Move the next number from memory to reg. B.
2009 CMP B B8 Compare B with A.
200A JNC 200EH D2 Jump to address 200EH if there is no carry.
200B 0E Lower-order of 200EH.
200C 20 Higher-order of 200EH.
200D MOV A, B 78 Move largest from reg. B to reg. A.
200E DCR C 0D Decrement counter.
200F JNZ 2007H C2 Jump to address 2007H if counter is not zero.
2010 07 Lower-order of 2007H.
2011 20 Higher-order of 2007H.
2012 INX H 23 Increment H-L pair.
2013 MOV M, A 77 Move the result from reg. A to memory.
2014 HLT 76 Halt.

Explanation:
 This program finds the largest number in an array.
 Initially, the counter is initialized with the size of an array.
 Then, two numbers are moved to registers A and B, and compared.

 After comparison, the largest of two must be in accumulator. If it is already in


accumulator, then its fine, otherwise it is moved to accumulator.

 Counter is decremented and checked whether it has reached zero. If it has, the loop

25
terminates otherwise, the next number is moved to register and compared.

 Let us assume that the memory location 3000H stores the counter. The next memory
locations store the array.
 Initially, H-L pair is loaded with the address of the counter and is moved to register C.
 Then, H-L pair is incremented to point to the first number in the array.

 The first number is moved from memory to accumulator and counter is decremented by
one.
 H-L pair is again incremented and second number is moved to register B.
 The two numbers are compared.
 After comparison, if A > B, then CF = 0, and if A < B, then CF = 1.

 Carry flag is checked for carry. If there is a carry, it means B is greater than A and it is
moved to accumulator.
 Counter is decremented and checked whether it has become zero.

 If it hasn’t become zero, it means there are numbers left in the array. In this case, the
control jumps back to increment the H-L pair and moves the next number to register B.

 This process continues until counter becomes zero, i.e. all the numbers in the array are
compared.

 At last, H-L pair is incremented and the largest number is moved from accumulator to
memory.

Output:
Before Execution:
3000H: 05H (Counter)
3001H: 15H
3002H: 01H
3003H: 65H
3004H: E2H
3005H: 83H
After Execution:
3006H: E2H

26

You might also like