Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

All Cs 2 Programs

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Program 1

To find out 2's complement of five numbers stored from memory locations 6000H onwards .store the result from
memory location 6100H.(Before execution store 11H,22H,33H,44H,55H from 6000 to 6004H)

Address Label Mnemoics Opcode Comments


2000 start LXI 6000H 21 initialise H-L pointer with 6000H
2001 oo
2002 60
2003 LXI D 6100H 11 initialise D E pointer with 6100H
2004 oo
2005 61
2006 MVI C,05 0E initialise counter reg c with 05
2007 o5
2008 loop MOV A,M 7E get the number in accumalator
2009 CMA 2F 1's complement the accumalator
200A INR A 3C 2's Complement the accumalator
200B STAX D 12 store the 2's complement at address pointed by DE pair
200C INX H 23 increment HL pointer
200D INX D 13 increment DE pointer
200E DCR C 0D decrement counter register c
200F JNZ loop C2 is counter 0 ? No jump to label loop
2010 o8
2011 20
2012 stop HLT 76 stop processing
Output:-

Before Execution:-

Memory Location Data


6000H 11H
6001H 22H
6002H 33H
6003H 44H
6004H 55H

After Execution:-

Memory Location Data


6100H EFH
6101H DEH
6102H CDH
6103H BCH
6104H ABH

Result:-
Program Executed successfully.
Program 2
To count the number of odd data bytes occurring in a block .Store the result at the memory location
7600H.(Before execution store 01 to 0A from 7501 to 750AH).
Address Label Mnemoics Opcode Comments
2000 start LXI H,7501 21 initialise HL pointer with address 7501H
2001 O1
2002 75
2003 MVIC,0A 0E initialise counter reg c with 0A
2004 0A
2005 MVI B,00H O6 initialise counter reg B with OO
2006 OO
2007 loop MOV A,M 7E get the number in accumalator
2008 RRC 0F Rotate right to determine odd or even
2009 JNC D2 is carry? No jump to next label
200A 0D
200B 20
200C INR B O4 increment odd counter reg B
200D next INX H 23 increment HL pointer
200E DCR C 0D decrement counter reg c
200F JNZ loop C2 is count zero ? No jump to loop
2010 O7
2011 20
2012 MOV A,B 78 get odd count in accumalator
2013 STA 7600H 32 store contents of accumalator to M.L. 7600H
2014 OO
2015 76
2016 End HLT 76 stop processing
Output:-

Before Execution:-

Memory Location Data


7501H O1H
7502H O2H
7503H O3H
7504H O4H
7505H O5H
7506H O6H
7507H O7H
7508H O8H
7509H O9H
750AH OAH
After Execution:-

Memory Location Data


7600H O5H

Result:-
Program Executed successfully.
Program 3
To fill the memory block of 10 memory locations starting from 6000H with data 00H and FFH at every alternate
memory locations.
Address Label Mnemoics Opcode Comments
2000 start MVI C,0AH 0E initialise counter reg c by 0AH.
2001 0A
2002 MVI D,00H 16 initialise reg D with immediate data 00H
2003 OO
2004 MVI E,FFH 1E initialise reg E with immediate data FFH
2005 FFH
2006 LXI H,6000H 21 initilse HL pointer with M.L. 6000H
2007 OO
2008 60
2009 loop MOV M,D 72 fill 00H in M.L. pointed byHL pair
200A DCR C 0D decrement counter reg c
200B INX H 23 increment HL pointer
200C MOV M,E 73 fill FFH in M.L. pointed by HL pair
200D INX H 23 increment HL pointer
200E DCR C 0D decrement counter reg c
200F JNZ loop C2 is count zero ? No jump to loop
2010 O9
2011 20
2012 End HLT 76 stop processing
Output:-
After Execution:-

Memory Location Data


6000H OOH
6001H FFH
6002H OOH
6003H FFH
6004H OOH
6005H FFH
6006H OOH
6007H FFH
6008H OOH
6009H FFH

Result:-
Program Executed successfully.
Program 4
To add the three decimal numbers stored in different memory locations . Store the result at memory location
6203H.(Before execution store data 15,25 and 45 at 6200H ,6201H and 6202H respectively).
Address Label Mnemoics Opcode Comments
2000 start LXI H,6200H 21 initialise HL pointer
2001
2002
2003 MOV A,M 7E get first data in acc
2004 INX H 23 increment HL pointer
2005 ADD M 86 add content of memory with accumalator
2006 INX H 23 increment HL pointer
2007 ADD M 86 add content of memory with accumalator
2008 DAA 27 decimally adjust accumalator
2009 INX H 23 increment HL pointer
200A MOV M,A 77 copy the result to the M.L. 6203H
200B end HLT 76 stop the microprocessor
Output:-
Before Execution:-

Memory Location Data


6200H 15H
6201H 25H
6202H 45H

After Execution:-

Memory Location Data


6203H 85H

Result:-
Program Executed successfully.
Program 5

To multiply two 8 bit number in memory location 6200H and 6201H store two byte result in consecutive memoru
locations starting from 6000H.(Before execution store 09H in 6200H and 0EH 6201H )

Address Label Mnemoics Opcode Comments


2000 start LXI H,6200H 21 initialise HL pointer with 6200H
2001 OO
2002 62
2003 MOV E,M 5E initialse one no to reg E
2004 INX H 23 increment HL pointer
2005 MOV C,M 4E initialise reg c with second no
2006 LXI H,0000H 21 initialise HL pointer with 0000H
2007 OO
2008 OO
2009 MVI D,00H 16 initialise reg D with 00H
200A OO
200B loop DAD D 19 decimally adjust accumalator
200C DCR C 0D decrement counter reg C
200D JNZ loop C2 is count zero? No jump to loop
200E 0B
200F 20
2010 SHLD 6000H 22 Move two byte result in M.L. starting from 6000H
2011 OO
2012 60
2013 stop HLT 76 stop processing
Output:-
Before Execution:-

Memory Location Data


6200H O9H
6201H OEH

After Execution:-

Memory Location Data


6000H 7EH
6001H OOH

Result:-
Program Executed successfully.
Program 6

To interchange the nibbles of accumalator containing data 96h and store result at 6200H.

Address Label Mnemoics Opcode Comments


2000 start MVI A,96H 3E initialise accumalator with 96H
2001 96
2002 RLC O7 Rotate accumalator left without carry
2003 RLC O7 Rotate accumalator left without carry
2004 RLC O7 Rotate accumalator left without carry
2005 RLC O7 Rotate accumalator left without carry
2006 STA 6200 32 Store result to M.L. 6200H
2007 OO
2008 62
2009 end HLT 76 Stop processing

Output:-

Before Execution :-
[A]=96H
After Execution :-
[A]=69H
Result :-

Program Executed successfully.


Program 7

To count the no of 1's and 0's in a 8 bit binary number . Store the count of 0's and 1's in M.L. 6001 and 6002H
repectively.

Address Label Mnemoics Opcode Comments


2000 start LXI H,6000H 21 imitialise HL pointer with 6000H
2001 OO
2002 60
2003 MVI C,08 0E initialse reg c as counter to 8
2004 O8
2005 MVI D,00H 16 initialise reg D to OO
2006 OO
2007 MOV A,M 7E get data in accumalator to check the bit
2008 loop RRC OF rotate the contents of accumalator to right
2009 JC 2000H DA if carry jump to 200DH
200A 0D
200B 20
200C INR D 14 increment counter reg D
200D DCR C 0D decrement counter reg C
200E JNZ LOOP C2 jump if not zero to 2008H
200F O8
2010 20
2011 INX H 23 increment HL pointer
2012 MOV M,D 72 move zero count to M.L. 6001H
2013 stop MVI A,08H 3E move immediate data 8 to accumalatot
2014 O8
2015 SUB D 92 subtract content of reg D from accumalator
2016 INX H 23 increment HL pointer
2017 MOV M,A 77 move content of accumalator to M.L. 6002H
2018 HLT 76 stop

Output:-

Before Execution :-

Memory Location Data


6000H 41H

After Execution :-

Memory Location Data


6001H O6H
6002H O2H

Result :-
Program Executed Successfully
Program 8

To fill memory locations starting from 6000 onwards with decimal numbers from 0 to 19.

Address Label Mnemoics Opcode Comments


2000 start LXI H,6000H 21 imitialise HL pointer with 6000H
2001 OO
2002 60
2003 MVI B,14 O6 initialse reg B as counter to 14
2004 14
2005 SUB A 97 clear the contents of accumalator
2006 loop MOV M,A 77 move content of accumalator to M.L.pointed by HL pair
2007 ADI O1 C6 add immediate data 1 to the content of accumalator
2008 O1
2009 DAA 27 decimally adjust accumalator
200A INX H 23 increment HL pointer
200B DCR B O5 decrement counter register B
200C JNZ loop C2 jump if counter not zero
200D O6
200E 20
200F HLT 76 stop
Output:-

After Execution:-

Memory Location Data


6000H OOH
6001H O1H
6002H O2H
6003H O3H
6004H O4H
6005H O5H
6006H O6H
6007H O7H
6008H O8H
6009H O9H
600AH 10H
600BH 11H
600CH 12H
600DH 13H
600EH 14H
600FH 15H
6010H 16H
6011H 17H
6012H 18H
6013H 19H

Result :-
Program Executed successfully.
Program 9

To transfer data in reverse order stored in consecutive memory location . Store result in next consecutive order memory
location.(Before execution store data in M.L. 6000H to 6009H

Address Label Mnemoics Opcode Comments


2000 start LXI H,6009H 21 initialise HL pointer with address 6009H
2001 O9
2002 60
2003 LXI D,600A 11 initialise DE pointer with address 600AH
2004 0A
2005 60
2006 MVI C,0A 0E move 0A to counter reg C
2007 0A
2008 loop MOV A,M 7E get data pointed by HL in Accumalator
2009 STAX D 12 store data in accumalator to M.L. pointed by DE pair
200A DCX H 2B decrement HL pointer
200B INX D 13 incremnt DE pointer
200C DCR C 0D decrement counter reg c
200D JNZ LOOP C2 Jump to loop if counter not zero
200E O8
200F 20
2010 stop HLT 76 stop
output:-

Before Execution:- After Executon :-

Memory Location Data Memory Location Data


6000H OOH 600AH O9H
6001H O1H 600BH O8H
6002H O2H 600CH O7H
6003H O3H 600DH O6H
6004H O4H 600EH O5H
6005H O5H 600FH O4H
6006H O6H 6010H O3H
6007H O7H 6011H O2H
6008H O8H 6012H O1H
6009H O9H 6013H OOH

Result :-

Program Executed successfully


Program 10

To find largset number among given block stored from M.L. 6100H .Store the largest number in M.L. 6100H .(Before
execution store data from 6100H to 610AH).

Address Label Mnemoics Opcode Comments


2000 start LXI H,6100H 21 initialise HL pointer to M.L. 6100H
2001 OO
2002 61
2003 MVI C,0A 0E move 0A to counter reg C
2004 0A
2005 MOV A,M 7E move the contents of M.L. pointed by HL to accumalator
2006 loop CMP M BE compare data of accumaltor with memory
2007 JNC next D2 jump if no carry to next
2008 0B
2009 20
200A MOV A,M 7E get the largest data in accumalator
200B next INX H 23 increment HL pointer
200C DCR C 0D decrement counter register C
200D JNZ loop C2 jump to label loop if counter not zero
200E O6
200F 20
2010 STA 6100H 32 store larger data from accumalator
2011 OO
2012 61
2013 stop HLT 76 stop
Output:-

Before Execution :-

Memory Location Data


6100H O1H
6101H O3H
6102H O2H
6103H O7H
6104H 10H
6105H 11H
6106H OCH
6107H ODH
6108H OEH
6109H OFH
610AH OBH

After Execution:-
Memory location Data
6100H 11H
Program 11

To find smallest number among given block stored from memory location 6100H.Store the largest number in M.L.
6100H.(Before execution store data from 6100H to 610AH)

Address Label Mnemoics Opcode Comments


2000 start LXI H,6100H 21 initialise HL pointer to M.L. 6100H
2001 OO
2002 61
2003 MVI C,0A 0E move 0A to counter reg C
2004 0A
2005 MOV A,M 7E move the contents of M.L. pointed by HL to accumalator
2006 loop CMP M BE compare data of accumaltor with memory
2007 JC next DA jump if carry to next
2008 0B
2009 20
200A MOV A,M 7E get the smallest data in accumalator
200B next INX H 23 increment HL pointer
200C DCR C 0D decrement counter register C
200D JNZ loop C2 jump to label loop if counter not zero
200E O6
200F 20
2010 STA 6100H 32 store smallest data from accumalator
2011 OO
2012 61
2013 stop HLT 76 stop
Output:-

Before Execution :-

Memory Location Data


6100H O1H
6101H O3H
6102H O2H
6103H O7H
6104H 10H
6105H 11H
6106H OCH
6107H ODH
6108H OEH
6109H OFH
610AH OBH

After Execution:-
Memory location Data
6100H O1H

Result:-
Program Executed successfully
Program 12
To exchange the content of given two blocks . The length of block is stored in M.L. 6100H.(Before execution stored data from 6101H to
6105H and 7101H to 7105H).

Address Label Mnemoics Opcode Comments


2000 start LXI H,6100H 21 initialise HL pointer
2001 OO
2002 60
2003 MOV C,M 4E move the length counter in reg c
2004 INX H 23 increment HL pointer
2005 LXI D,7101H 11 initialise DE pair
2006 O1
2007 71
2008 next MOV B,M 46 move the content pointed by HL pair to reg B
2009 LDAX D 1A Load the content pointed by DE pair to accumalator
200A MOV M,A 77 Move the content of accumalator to M.L. pointed by HL pair
200B MOV A,B 78 Move the content of reg B to Accumalator
200C STAX D 12 Store the content of accumalator to the M.L. pointed by DE pair
200D INX H 23 increment HL pointer
200E INX D 13 increment DE pointer
200F DCR C 0D Decrement counter register c
2010 JNZ NEXT C2 Jump to next if counter not zero
2011 O8
2012 20
2013 stop HLT 76 stop
Output:-
Before Execution :-

Memory Location Data Memory Location Data


6100H 05H 7101H 10
6101H 09H 7102H 11
6102H 08H 7103H 12
6103H 07H 7104H 13
6104H 06H 7105H 14
6105H 05H
After Execution:-
Memory location Data
Memory Location Data Memory Location Data
6100H 05H 7101H 09H
6101H 10 7102H 08H
6102H 11 7103H 07H
6103H 12 7104H 06H
6104H 13 7105H 05H
6105H 14

Result :-
program executed successfully.
Program 13
To find first occurrence of data O5H in given block.Store the address of this occurrence in HL pair.If the no is not
found then store FFFFH in HL pair . The length of block is stored in memory location 6100H(Before execution store
data from 6100H to6106H).
Address Label Mnemoics Opcode Comments
2000 start LXI H,6100H 21 initialise HL pointer
2001 OO
2002 60
2003 MOV C,M 4E move the length counter in reg c
2004 MVI A,O5 3E Initialise accumalator with O5
2005 O5
2006 INX H 23 increment HL pointer
2007 loop CMP M BE compare contents of HL pointer with accumalator
2008 JZ end CA is equal? Yes jump to end
2009 13
200A 20
200B INX H 23 increment HL pointer
200C DCR C decrement counter register c
200D JNZ loop C2 is zero? No jump to loop
200E O7
200F 20
2010 LXI,FFFFH 21 store HL pair with FFFFH
2011 FF
2012 FF
2013 end HLT 76 stop
output:-

Before Execution

Memory location Data


6100H 06H
6101H 12H
6102H O5H
6103H O9H
6104H O3H
6105H 19H
6106H O5H

After Execution:-
Memory Location Data
HL->6102H O5H

Result:-
Program Executed successfully.
Program 14
To count the number of times a data is found in a block of memory location starting from address 6100HThe length of
block is stored in memory location 6100.Store occuerrence counter to memory location 7100H.

Address Label Mnemoics Opcode Comments


2000 START LXI H,6100H 21 initialise HL pointer with address 6100H
2001 OO
2002 61
2003 MOV C,M 4E move the content of memory location to reg as counter
2004 INX H 23 increment HL pointer
2005 MVI A,05 3E move data O5 in acc
2006 O5
2007 MVI B,00H O6 initialise occurrence counter reg B to OO
2008 OO
2009 LOOP CMP M BE compare acc with data in m.l.
200A JNZ NEXT C2 jump to NEXT if not zero
200B OR
200C 20
200D INR B O4 increment occurrence reg B
200E NEXT INX H 23 increment HL pointer
200F DCR C OD decrement length length rec c
2010 JNZ LOOP C2 jumo to loop if not zero
2011 O9
2012 20
2013 MOV A,B 78 get occurrence counter in acc
2014 STR 7100H 32 store occurrence counter in 7100H
2015 71
2016 OO
2017 END HLT 76 stop

Output :-
Before Execution:-
Memory Location Data After Execution:-
6100H O6H Memory Location Data
6101H 12H 7100H O3H
6102H 05H
6103H 09H Result:-
6104H 05H Program Executed successfully.
6105H 10H
6106H O5H
Program 15
To count the numbe of even data bytes occurring in a block starting from the memory location 6001 to 600A .Before
execution store data from 6001 to 600AH.
Address Label Mnemoics Opcode Comments
2000 START LXI H,6001 21 initialise HL pointer with m.l.6001
2001 O1
2002 60
2003 MVI C,OAH OE initialise counter register C with data OAH
2004 OA
2005 MVI B,OOH O6 initialise even counter reg B with 00H
2006 OO
2007 LOOP MOV A,M 7E get data in accumalator from memory
2008 RRC OF rorate accumalator content right to count even data byte
2009 JC NEXT OA jump to label next if carry
200A OD
200B 20
200C INR B O4 increment counter register B
200D NEXT INX H 23 increment HL pointer
200E DCR C OD decrement length counter reg c
200F JNZ LOOP C2 jump to label loop if counter not zero
2010 O7
2011 20
2012 MOV A,B 78 get even counter in accumalator
2013 STA 6100 32 Store even counter to memory location 6100H.
2014 OO
2015 61
2016 END HLT 76 stop processing
Output:-
Before Exectuion After Execution:-

Memory Location Data Memory Location Data


6001H 05H 6100H 05H
6002H 09H
6003H 08H Resullt:-
6004H 06H Program executed successfully
6005h 04H
6006H 05H
6007H 04H
6008H 05H
6009H 10H
600AH 11H
Program 16
To divide a hexadecimal number stored in M.L. 6000H by a hexadecimal number stored in M.L. 6001H.
Store the quotient at 6002H and remainder at 6003H.
Address Label Mnemoics Opcode Comments
2000 START LXI H,6000H 21 initialise HL pointer to M.L. 6000H
2001 OO
2002 60
2003 MVI C,00H OE initialise quotient register C to OOH
2004 OO
2005 MOV A,M 7E get the dividend in accumalator
2006 INX H 23 increment HL pointer
2007 LOOP CMP M BE compare dividend with divisor
2008 JC NEXT DA jump to label NEXT if carrry
2009 10
200A 20
200B SUB M 90 subtract divisor from dividend
200C INR C OC increment quotient reg C
200D JMP LOOP C3 jump to Label LOOP
200E O5
200F 20
2010 NEXT INX H 23 increment HL pointer
2011 MOV M,C 71 store quotient in memory location 6002H
2012 INX H 23 increment HL pointer
2013 MOV M,A 77 store remainder in 6003H
2014 END HLT 76 stop processing
Output:-

Before Execution:-

Memory Location Data


6000H 09H
6001H 05H
After Execution:-
Memory Location Data
6002H 04H
6003H 01H

Result:-
Program executed successfully.

You might also like