0% found this document useful (0 votes)
22 views

CS 2 Journal

.

Uploaded by

adityaaigal1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

CS 2 Journal

.

Uploaded by

adityaaigal1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Practical 01

Title: Calculating absolute difference of two numbers.

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.

Program Memory Table:

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

Subtract the contents of memory location pointed


C005H 96 SUB M
by HL pair from the contents of accumulator

C006H F2 JP Store Jump If the subtraction result is Positive to Store

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

Register Array Values:

Register Contents Register Contents


A 03 F 14
B 00 C 00
D 00 E 00
H C0 L 31
SPH FF SPL FE
PCH 00 PCL 08

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

Register Array Values:

Register Contents Register Contents


A 03 F 04
B 00 C 00
D 00 E 00
H C0 L 31
SPH FF SPL FE
PCH 00 PCL 08

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

Input Table Output Table


Memory Before After Memory Before After
Location Execution Execution Location Execution Execution
C030H 09 09 C090H 00 03

C031H 06 06

Example - 2

Input Table Output Table


Memory Before After Memory Before After
Location Execution Execution Location Execution Execution
C030H 03 03 C090H 00 03

C031H 06 06
Practical 02

Title: Transferring a block of data in reverse order.

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.

Program Memory Table:

Memory Hex
Label Mnemonics Comments
Location Code

C000H 21 LXI H, C039H Copy C039H to HL pair.

C001H 39
C002H C0

C003H 11 LXI D, C090H Copy C090H to DE pair

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:

Register Contents Register Contents


A 11 F 54
B 00 C 00
D C0 E 9A
H C0 L 2F
SPH FF SPL FE
PCH 00 PCL 08

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:

Memory Before After Memory Before After


Location Execution Execution Location Execution Execution
C030H 11 11 C090H 00 AA

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

Title: Exchanging the contents of two blocks.

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.

Program Memory Table:

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

C00BH 78 MOV A,B Copy the contents of B register to accumulator

Store the contents of accumulator to memory location


C00CH 12 STAX D
pointed by DE pair
C00DH 23 INX H Increment HL pair by 1
C00EH 13 INX D Increment DE pair by 1
C00FH 0D DCR C Decrement C register by 1
C010H C2 JNZ Repeat Jump on Repeat If Register C≠ 0
C011H 08
C012H C0
C013H CF RST 1 Stop
Register Array Values:

Register Contents Register Contents


A AA F 54
B AA C 00
D C0 E 9A
H C0 L 3A
SPH FF SPL FE
PCH 00 PCL 08

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:

Memory Before After Memory Before After


Location Execution Execution Location Execution Execution
C030H 11 10 C090H 10 11

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

Title: Finding first occurrence of a number in a given block of data.

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.

Program Memory Table:

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.

Register Array Values:

Register Contents Register Contents


A C3 F 54
B 00 C 07
D C3 E 00
H C0 L 34
SPH FF SPL FE
PCH 00 PCL 08

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:

Memory Before After


Location Execution Execution
C030H 0A 0A

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

Title: Counting occurrences of a number in a given block of data.

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.

Program Memory Table:

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.

Register Array Values:

Register Contents Register Contents


A 03 F 54
B 03 C 00
D C3 E 00
H C0 L 3B
SPH FF SPL FE
PCH 00 PCL 08

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:

Input Table Output Table


Memory Before After Memory Before After
Location Execution Execution Location Execution Execution
C030H 0A 0A C090H 00 03

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

Title: Counting even and odd numbers in 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 number of odd as well as even numbers in the given block.
Store the results immediately after the end of the block.

Program Memory Table:

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

Register Array Values:

Register Contents Register Contents


A 55 F 54
B 05 C 00
D 05 E 00
H C0 L 3B
SPH FF SPL FE
PCH 00 PCL 08

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:

Memory Before After


Location Execution Execution
C030H 11 11

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.

Program Memory Table:

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

Register Array Values:

Register Contents Register Contents


A 02 F 54
B FE C 00
D 02 E 00
H C0 L 3A
SPH 00 SPL 00
PCH F0 PCL 1D

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:

Memory Before After


Location Execution Execution
C030H 55 55

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

Title: Multiplying two hexadecimal numbers.

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.

Program Memory Table:

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

Copy the data of register C to the memory location


C017H 72 MOV M,D
pointed by the HL pair.

C018H CF RST1 Stop

Register Array Values:

Register Contents Register Contents


A FE F 55
B FF C 00
D 01 E 00
H C0 L 91
SPH FF SPL FE
PCH 00 PCL 08

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:

Input Table Output Table


Memory Before After Memory Before After
Location Execution Execution Location Execution Execution
C030H FF FF C090H 00 FE

C031H 02 02 C091H 00 01
Practical 09

Title: Dividing two hexadecimal numbers.

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.

Program Memory Table:

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

C004H 23 INX H Increment HL pair by 1


Copy data from memory location pointed
C005H 46 MOV B,M
by HL pair to register B
C006H 16 MVI D, 00H
Copy 00H to register D
C007H 00
Subtract the contents of register B from the
C008H 90 Back: SUB B
contents of accumulator
C009H FA JM Next
C00AH 10 Jump if Minus to Next
C00BH C0
C00CH 14 INR D Increment register D by 1
C00DH C3 JMP Back
C00EH 08 Jump unconditionally to Back
C00FH C0
Add the contents of register B with the contents
C010H 80 Next: ADD B
Of accumulator.
C011H 23 INX H Increment HL pair by 1
Copy the contents of register D to memory
C012H 72 MOV M,D
location pointed by HL pair
C013H 23 INX H Increment HL pair by 1
Copy the contents of accumulator to
C014H 77 MOV M,A
memory location pointed by HL pair
C015H CF RST 1 Stop

Register Array Values:

Register Contents Register Contents


A 03 F 15
B 05 C 00
D 06 E 00
H C0 L 33
SPH FF SPL FE
PCH 00 PCL 08

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

Data Memory Table:

Memory Before After


Location Execution Execution
C030H 21 21

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.

Program Memory Table:

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.

C017 23 INX H Increase the contents of the HL pair by 1.


Copy the contents of D register into the memory
C018 72 MOV M,D
location pointed by HL pair.
C019 CF RST 1 Stop.

Register Array Values:

Register Contents Register Contents


A 82 F 55
B 00 C 00
D 06 E 00
H C0 L 91
SPH FF SPL FE
PCH 00 PCL 08

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:

Input Table Output Table


Memory Before After Memory Before After
Location Execution Execution Location Execution Execution
C030H 0A 0A C090H 00 82

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

You might also like