CS 2 Journal
CS 2 Journal
Aim:
Write a program that subtracts the number stored in C031H from the number stored in C030H.
Store the absolute difference in memory location C090H.
Memory Hex
Label Mnemonics Comments
Location Code
C000H 21 LXI H, C030H Copy C030H in HL register pair
C001H 30
C002H C0
Copy the contents of memory location pointed by
C003H 7E MOV A,M
HL pair to accumulator
C004H 23 INX H Increment HL pair by 1
C007H 0C
C008H C0
C009H 2F CMA Complement the contents of accumulator
C00AH C6 ADI 01H Add 01h to the contents of accumulator
C00BH 01
Store the contents of accumulator as a result to
C00CH 32 Store: STA C090H
C090H
C00DH 90
C00EH C0
C00FH CF RST 1 Stop
Example - 1
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 0 0 1 0 1 0 0
Example - 2
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 0 0 0 0 1 0 0
Data Memory Table:
Example - 1
C031H 06 06
Example - 2
C031H 06 06
Practical 02
Aim:
A block of data is stored in memory location from C030H to C039H.
Write a program to transfer the data in reverse order to memory location starting from C090H.
Memory Hex
Label Mnemonics Comments
Location Code
C001H 39
C002H C0
C004H 90
C005H C0
C006H 0E MVI C, 0AH Copy 0AH into C register
C007H 0A
Move the contents of the memory location pointed by
C008H 7E Repeat: MOV A,M
the HL pair to the accumulator.
Store the contents of the accumulator into the DE
C009H 12 STAX D
register pair.
C00AH 2B DCX H Decrement HL pair by 1
C00BH 13 INX D Increment DE pair by 1
C00CH 0D DCR C Decrement C register by 1.
C00DH C2 JNZ Repeat Jump to Repeat if Register C≠0
C00EH 08
C00FH C0
C010H CF RST 1 Stop
Register Array Values:
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 1 0 1 0 1 0 0
C031H 22 22 C091H 00 99
C032H 33 33 C092H 00 88
C033H 44 44 C093H 00 77
C034H 55 55 C094H 00 66
C035H 66 66 C095H 00 55
C036H 77 77 C096H 00 44
C037H 88 88 C097H 00 33
C038H 99 99 C098H 00 22
C039H AA AA C099H 00 11
Practical 03
Aim:
A block of data is stored in memory location from C030H to C039H.
Another block of data having the same length is stored in memory location starting from C090H.
Write a program to exchange the contents of these two blocks.
Memory Hex
Label Mnemonics Comments
Location Code
C000H 21 LXIH, C030H Copy C030H into HL register pair
C001H 30
C002H C0
C003H 11 LXI D, C090H Copy C090H into DE register pair
C004H 90
C005H C0
C006H 0E MVI C, 0AH Copy 0AH into register C
C007H 0A
Copy the contents of memory location pointed by HL pair
C008H 46 Repeat: MOV B,M
to B register.
Copy the contents of memory location pointed by DE pair
C009H 1A LDAX D to
accumulator.
Copy the content of accumulator to memory location
C00AH 77 MOV M,A
pointed by HL pair
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 1 0 1 0 1 0 0
C031H 22 20 C091H 20 22
C032H 33 30 C092H 30 33
C033H 44 40 C093H 40 44
C034H 55 50 C094H 50 55
C035H 66 60 C095H 60 66
C036H 77 70 C096H 70 77
C037H 88 80 C097H 80 88
C038H 99 90 C098H 90 99
C039H AA A0 C099H A0 AA
Practical 04
Aim:
A block of data is stored in memory location from C031H.
The length of the block is stored at C030H.
Write a program that searches for the first occurrence of the number C3H in the given block.
Store the address of this first occurrence in the HL pair.
If the number is not found, then the HL pair must contain FFFFH.
Memory Hex
Label Mnemonics Comments
Location Code
C000 21 LXI H, C030H Load HL pair with C030H.
C001 30
C002 C0
Copy the contents of memory location pointed by HL
C003 4E MOV C,M
pair into C register.
C004 23 INX H Increase the contents of the HL pair by 1.
C005 16 MVI D, C3H Copy C3H into D register.
C006 C3
Copy the contents of memory location pointed by HL
C007 7E Repeat: MOV A,M
pair into the accumulator.
Compare the contents of the accumulator and D
C008 BA CMP D
register.
C009 CA JZ Stop If Z=0 then jump to Stop.
C00A 14
C00B C0
C00C 23 INX H Increase the contents of the HL pair by 1.
C00D 0D DCR C Decrease the contents of C register by 1
C00E C2 JNZ Repeat If Z≠0 then jump to Repeat.
C00F 07
C010 C0
C011 21 LXI H,FFFFH Load HL pair by FFFFH.
C012 FF
C013 FF
C014 CF Stop: RST 1 Stop.
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 1 0 1 0 1 0 0
C031H 11 11
C032H 22 22
C033H 33 33
C034H C3 C3
C035H 55 55
C036H 66 66
C037H C3 C3
C038H 88 88
C039H 99 99
C03AH C3 C3
Practical 05
Aim:
The block of data is stored in memory location C031H.
The length of the block is stored at C030H.
Write a program that counts the occurrence of the number C3H in the given block.
Store the result in C090H.
Memory Hex
Label Mnemonics Comments
Location Code
C000 21 LXI H, CO30H Load HL pair with C030H
C001 30
C002 C0
Move the contents of the memory location pointed by
C003 4E MOV C,M
the HL pair into the C register.
C004 16 MVI D, C3H Move C3H into the D register.
C005 C3
C006 06 MVI B,00H Move 00H into the B register.
C007 00
C008 23 INX H Increase the contents of the HL pair by 1.
Move the contents of memory location pointed by HL
C009 7E Repeat: MOV A,M
pair into the accumulator.
Compare the contents of the D register with the
C00A BA CMP D
contents of the accumulator.
C00B C2 JNZ Skip If Z≠0 then jump to Skip.
C00C 0F
C00D C0
C00E 04 INR B Increase the contents of B register by 1.
C00F 23 Skip: INX H Increase the contents of the HL pair by 1.
C010 0D DCR C Decrease the contents of C register by 1.
C011 C2 JNZ Repeat If Z≠0 then jump to Repeat.
C012 09
C013 C0
C014 78 MOV A,B Move the contents of B register into the accumulator.
Store the contents of the accumulator at memory
C015 32 STA C090H
location C090H.
C016 90
C017 C0
C018 CF RST 1 Stop.
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 1 0 1 0 1 0 0
Data Memory Table:
C031H 11 11
C032H 22 22
C033H 33 33
C034H C3 C3
C035H 55 55
C036H 66 66
C037H C3 C3
C038H 88 88
C039H 99 99
C03AH C3 C3
Practical 06
Aim:
A block of data is stored in memory location from C030H to C039H.
Write a program to find the number of odd as well as even numbers in the given block.
Store the results immediately after the end of the block.
Memory Hex
Label Mnemonics Comments
Location Code
C000H 21 LXI H, C030H Initialize HL pair with C030H.
C001H 30
C002H C0
C003H 0E MVI C, 0AH
Copy 0AH in register C
C004H 0A
C005H 06 MVI B,00H
Copy 00H in register B
C006H 00
C007H 16 MVI D, 00H
Copy 00H in register D
C008H 00
Copy the contents of memory Location pointed by HL
C009H 7E Repeat: MOV A,M
pair to accumulator
C00AH 0F RRC Rotate the contents of accumulator towards right by 1 bit
C00BH DA JC Next Jump if CY = 1 to Next
C00CH 12
C00DH C0
C00EH 04 INR B Increment register B by 1
C00FH C3 JMP Skip Jump unconditionally to Skip
C010H 13
C011H C0
C012H 14 Next: INR D Increment register D by 1
C013H 23 Skip: INX H Increment HL pair by 1
C014H 0D DCR C Decrement register C by 1
C015H C2 JNZ Repeat Jump if Register C ≠0
C016H 09
C017H C0
Copy the contents of B register To the memory location
C018H 70 MOV M,B
pointed by HL pair
C019H 23 INX H Increment HL pair by 1
Copy the contents of D register To the memory location
C01AH 72 MOV M,D
pointed by HL pair
C01BH CF RST 1 Stop
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 1 0 1 0 1 0 0
Data Memory Table:
C031H 22 22
C032H 33 33
C033H 44 44
C034H 55 55
C035H 66 66
C036H 77 77
C037H 88 88
C038H 99 99
C039H AA AA
C03AH 00 05
C03BH 00 05
Practical 07
Title: Finding the largest and the smallest number from a given block of data.
Aim:
A block of data is stored in memory location from C030H TO C039H.
Write a program to find the largest as well as smallest number from this block using linear search.
Store the results immediately after the end of the block.
Memory
Hex Code Label Mnemonics Comments
Location
C000H 21 START: LXI H, C030H Load HL with starting address
C001H 30
C002H C0
C003H 46 MOV B, M Move first item to B
C004H 56 MOV D, M Move first item to D
C005H 23 INX H Increment HL
C006H 0E MVI C, 09H Initialize counter C with 09H
C007H 09
C008H 7E COMPARE: MOV A, M Move data at HL to A for comparison
C009H BE CMP B Compare
C00AH DA JC NEXT Jump if A not less than B
C00BH 0E
C00CH C0
C00DH 47 MOV B, A Update B with new value, if needed
C00EH BC NEXT: CMP D Compare
C00FH D2 JNC SKIP Jump if A not greater than D
C010H 12
C011H C0
Update register D with new value, if
C012H 57 MOV D, A
needed
C013H 23 SKIP: INX H Increment HL to next data
C014H 0D DCR C Decrement counter C
C015H C2 JNZ COMPARE Jump if not zero to COMPARE
C016H 08
C017H C0
C018H 78 STORE: MOV A, B Move B to A
C019H 32 STA C03AH Store A into C03AH
C01AH 3A
C01BH C0
C01CH 7A MOV A, D Move D to A
C01DH 32 STA C03BH Store A into C03BH
C01EH 3B
C01FH C0
C020H 76 HLT Halt the program
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 1 0 1 0 1 0 0
Data Memory Table:
C031H 44 44
C032H 02 02
C033H FE FE
C034H 2C 2C
C035H 66 66
C036H CC CC
C037H 77 77
C038H 88 88
C039H AA AA
C03AH 00 FE
C03BH 00 02
Practical 08
Aim:
Write a program that multiplies one-byte hexadecimal numbers stored in two consecutive memory
locations starting from C030H.
Store the two bytes of result in consecutive memory locations starting from C090H beginning with lower
order byte.
Memory Hex
Label Mnemonics Comments
Location Code
C000H 21 LXI H, C030H Initialize HL pair With C030H
C001H 30
C002H C0
Copy data from memory Location pointed by HL pair to
C003H 46 MOV B.M
register B
C004H 23 INX H Increment HL pair by 1
Copy data from memory Location pointed by HL pair to
C005H 4E MOV C,M
register C
C006H AF XRA A Initialize accumulator with 00H
C007H 16 MVI D, 00H Copy 00H to register D
C008H 00
Add the contents of register B with the contents of the
C009H 80 Back: ADD B contents
of accumulator
C00AH D2 JNC Next Jump to Next If CY ≠ 0
C00BH 0E
C00CH C0
C00DH 14 INR D Increment register D by 1
C00EH 0D Next: DCR C Decrement register C by 1
C00FH C2 JNZ Back Jump to Back if register C ≠ 0
C010H 09
C011H C0
C012H 21 LXI H, C090H Initialize HL pair with C090H
C013H 90
C014H C0
Copy the contents of accumulator to the memory
C015H 77 MOV M,A
location pointed by HL pair
C016H 23 INX H Increment HL pair 1
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 1 0 1 0 1 0 1
C031H 02 02 C091H 00 01
Practical 09
Aim:
Write a program that divides one-byte hexadecimal numbers where the dividend is stored in C030H and
divisor is stored in C031H.
Store the quotient and remainder in the next consecutive memory locations respectively.
Memory Hex
Label Mnemonics Comments
Location Code
C000H 21 LXI H,C030H
C001H 30 Initialize HL pair with C030H
C002H C0
Copy data from memory location pointed
C003H 7E MOV A,M
by HL pair to accumulator
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 0 0 1 0 1 0 1
C031H 05 05
C032H 00 06
C033H 00 03
Practical 10
Title:
Aim:
Write a program to add the BCD numbers in a block of memory starting at address C031H.
The length of the block is stored in BCD at address C030H and does not exceed 63H (9910).
Store the result starting from memory location C090H.
Memory Hex
Label Mnemonics Comments
Location Code
C000 21 LXI H,C030H Copy C030H in HL pair.
C001 30
C002 C0
Copy the contents of memory location pointed by HL
C003 4E MOV C,M
pair into C register.
C004 23 INX H Increase the contents of the HL pair by 1.
C005 16 MVI D,00H Initialize DE pair by 00H
C006 00
Perform EX-OR operation between the contents of the
C007 AF XRA A
accumulator and the contents of the accumulator.
Add the contents of memory location pointed by HL
C008 86 BACK: ADD M
pair with the contents of the accumulator.
C009 27 DAA Decimal Adjust Addition
C00A D2 JNC SKIP if CY≠0 then jump to skip
C00B 0E
C00C C0
C00D 14 INR D Increase the contents of D register by 1.
C00E 23 SKIP: INX H Increase the contents of the HL pair by 1.
C00F 0D DCR C Decrease the contents of C register by 1.
C010 C2 JNZ BACK if Z≠0 then jump to back
C011 08
C012 C0
C013 21 LXI H,C090H Copy C090H in HL pair.
C014 90
C015 C0
Copy the contents of the accumulator into the memory
C016 77 MOV M,A
location pointed by the HL pair.
Flag Register
7 6 5 4 3 2 1 0
S Z X AC X P X CY
0 1 0 1 0 1 0 1
Data Memory Table:
C031H 1F 1F C091H 00 06
C032H 2F 2F
C033H 3F 3F
C034H 4F 4F
C035H 5F 5F
C036H 6F 6F
C037H 7F 7F
C038H 8F 8F
C039H 9F 9F
C03AH AF AF