0% found this document useful (0 votes)
161 views40 pages

CS2 Journal

The document outlines a series of assembly language programs for computer science students, focusing on various operations with memory blocks, such as transferring data, swapping contents, and performing arithmetic operations. Each program includes detailed instructions, memory locations, and expected outputs. The document serves as a journal for students to record their programs and results in a structured format.

Uploaded by

Aryan Murarka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views40 pages

CS2 Journal

The document outlines a series of assembly language programs for computer science students, focusing on various operations with memory blocks, such as transferring data, swapping contents, and performing arithmetic operations. Each program includes detailed instructions, memory locations, and expected outputs. The document serves as a journal for students to record their programs and results in a structured format.

Uploaded by

Aryan Murarka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

XII Standard

Computer Science – II ( Hardware )


Journal Programs

Instructions:
1. Write Program in Right side of the journal.
2. Write Output in Left side of the journal with pencil.
3. Write program and output in tabular form.
Index
Programs
Sr.No.
1. Transfer/copy of a block

2. Transfer/copy of a block in reverse

3. Exchange / Swap the data contents of two blocks

4. Add the data content of a memory block

5. Add the data content of a memory block with BCD result

6. Subtraction with absolute difference

7 Largest number from the given block

8. Smallest number from the given block

9. First occurrence of the number AB H from the given block

10. Count the occurrence of the number AB H from the given block

11. Count odd numbers from the given block

12. Count even numbers from the given block

13. Count no of ones in the given number

14. Count no of zeros in the given number

15. Multiplication of two 8-bit numbers

16. Separate nibbles of a given number and multiply

17 Division

18 Interchange digits of a number and addition with new number

19 Fill the block


Program-1
A Block of data is stored in memory location starting from C040 H. Length of the block is stored in register
D. Write an Assembly language program to transfer the entire block of data to another memory location
starting from memory location C050 H.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C001 H 40
C002 H C0

C003 H LXI B, C050H ;Initialize the register pair BC to


memory location C050 H
C004 H 50

C005 H C0
C006 H MVI D, 05 H ;Set the counter for 05 numbers in
register D
C007 H 05
C008 H UP: MOV A,M ;Copy the data content of memory
location whose address is in HL pair to
Accumulator
C009 H STAX B ;Store the data content of accumulator
to memory location whose address is in
register pair BC
C00A H INX H ; To get next location ,increment
content of HL register pair by 1
C00B H INX B ;To get next location ,increment the
content of BC register pair by 1
C00C H DCR D ;Decrement the counter by 1
C00D H JNZ UP ;If counter  0 (reg. D  0)then jump
to memory location C008H
C00E H 08
C00F H C0

C010 H RST 1 ;Stop the execution


OUTPUT:

Before Execution:

C040 H = 01 H
C041 H = 02 H
C042 H = 03 H
C043 H = 04 H
C044 H = 05 H

After Execution:

A=

D=

F=

C040 H = 01 H C050 H =
C041H = 02 H C051 H =
C042 H = 03 H C052 H =
C043 H = 04 H C053 H =
C044 H = 05 H C054 H =

F= S Z X AC X P X CY
Program-2
A Block of data is stored in memory location starting from C040 H. Length of the block is stored in register
D. Write an Assembly language program to transfer the entire block of data to another memory location
starting from memory location C050 H in reverse order.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C001 H 40
C002 H C0

C003 H LXI B, C054H ;Initialize the register pair BC to


memory location C054 H
C004 H 54

C005 H C0
C006 H MVI D, 05 H ;Set the counter for 05 numbers in
register D
C007 H 05
C008 H UP: MOV A,M ;Copy the data content of memory
location whose address is in HL pair to
Accumulator.
C009 H STAX B ;Store the data content of accumulator
to memory location whose address is in
register pair BC .
C00A H INX H ; To get next location ,increment
content of HL register pair by 1
C00B H DCX B ;Decrement the content of BC register
pair by 1
C00C H DCR D ;Decrement the counter by 1
C00D H JNZ UP ;If counter  0 (reg.D  0)then jump
to memory location C008H
C00E H 08
C00F H C0
C010 H RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040 H = 01 H
C041 H = 02 H
C042 H = 03 H
C043 H = 04 H
C044 H = 05 H

After Execution:

A=

D=

F=

C040 H = 01 H C050 H =
C041 H = 02 H C051 H =
C042 H = 03 H C052 H =
C043 H = 04 H C053 H =
C044 H = 05 H C054 H =

F= S Z X AC X P X CY
Program-3
A block of data is stored in memory location starting from memory location C040 H. Another block of data
is stored in memory location starting from memory location C050 H. Length of the blocks is stored in
register D. Write a program to exchange / swap the data contents of both these blocks

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to memory
location C040H
C001 H 40

C002 H C0

C003 H LXI B, C050H ;Initialize the register pair BC to memory


location C050H
C004 H 50

C005 H C0

C006 H MVI D, 05 H ;Set the counter for 05 numbers in


register D
C007 H 05

C008 H LDAX B ;Load the data contents of memory


UP: location whose address is in register
pair BC to accumulator

C009 H MOV E , A ;Copy the data content of accumulator to


register E
C00A H MOV A ,M ; Copy the data content of memory
location whose address is in register
pair HL to accumulator.

C00B H STAX B ;Store the data content of accumulator


to memory location whose address is in
register pair BC

C00C H MOV M , E ;Copy the data content of register E to


memory whose address is in register
pair HL
C00D H INX H ; Increment the content of HL register
pair by 1 to get next location.

C00E H INX B ; Increment the content of BC register


pair by 1 to get next location.

C00F H DCR D ;Decrement the counter by 1

C010 H JNZ UP ; If counter  0 (reg. D  0) then jump to


memorylocation C008H
C011 H 08

C012 H C0

C013 H RST 1 ;Stop the execution


OUTPUT:

Before Execution:

C040H = 01 H C050H= 06H

C041H = 02 H C051H= 07H


C042H = 03 H C052H= 08H
C043H = 04 H C053H= 09H
C044H = 05 H C054H= 0AH

After Execution

:A =

D =

F=

C040H = C050H=
C041H = C051H=
C042H = C052H=
C043H = C053H=
C044H = C054H =

F= AC CY
Program-4
A block of data is stored in memory location starting from C040 H. Length of the block is stored in register
B. Write an Assembly language program to add the data content of the memory location and store 16-bit
result at the end of the block.

Memory Op- Code Labels Mnemonics Comments


Location
C000 H XRA A ;Clear the data content of accumulator
C001 H MVI C , 00 H ; Initialize Reg. C to zero
C002 H 00
C003 H MVI B, 05 H ;Set the counter for 05 numbers in
C004 H 05 register B
C005 H LXI H, C040H ;Initialize the register pair HL to
C006 H 40 memory location C040 H
C007 H C0
C008 H UP: ADD M ;Add the Memory content pointed by
register pair HL to accumulator
C009 H JNC Down ; Check carry flag. Jump if cy=0,store
result and if cy=1 store carry and result

C00A H 0D
C00B H C0
C00C H INR C ;Increment reg. C for carry
C00D H Down: INX H ; Increment the content of HL register
pair by 1 to get next location.
C00E H DCR B ;Decrement the counter by 1
C00F H JNZ UP ;If counter  0 (reg. B  0 )then jump
C010 H 08 to memory location C008H.
C011 H C0
C012 H MOV M ,A ; Copy the data content of accumulator
to Memory Location pointed by HL
register pair.
C013 H INX H ;Increment the memory location HL
register pair by 1
C014 H MOV M,C ; Copy the data content(carry) of reg. C
to Memory pointed by HL register pair.
C015 H RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040 H = 01H
C041 H = 02H
C042 H = 03 H
C043 H = 04 H
C044 H = 05 H
C045 H = ?
C046 H = ?

After Execution:

A=

B=

C=

F=

C040 H = 01 H
C041 H = 02 H
C042 H = 03 H
C043 H = 04 H
C044 H = 05 H
C045 H =
C046 H =

F= S Z X AC X P X CY
Program-5
A block of data is stored in memory location starting from C041 H. Length of the block is stored in
memory location C040 H. Write an Assembly language program to add the data content of the memory
location and store the BCD result at the end of the block.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H XRA A ;Clear the data content of accumulator
C001 H MVI C , 00 H ; Initialize Reg. C to zero
C002 H 00
C003 H LXI H, C040H ;Initialize the register pair HL to
C004 H 40 memory location C040 H
C005 H C0
C006 H MOV B, M ;Move memory content to set the
counter
C007 H INX H ; Increment HL reg. pair by one.
C008 H UP: ADD M ;Add the Memory content pointed by
register pair HL to accumulator
C009 H DAA ;Convert result into BCD format

C00A H JNC Down ; Check carry flag. Jump if cy=0,store


result and if cy=1 store carry and result

C00B H 0E
C00C H C0
C00D H INR C ;Increment reg. C for carry
C00E H Down: INX H ;Increment the memory location of HL
register pair by 1
C00F H DCR B ;Decrement the counter by 1
C010 H JNZ UP ;If counter  0 (reg. B  0 )then jump to
C011 H 08 memory location C008 H.
C012 H C0
C013 H MOV M ,A ;Copy the data content of accumulator
to Memory location pointed by HL
register pair.
C014 H INX H ;Increment the memory location HL
register pair by 1
C015 H MOV M,C ;Copy the data content of reg. C
to Memory location pointed by HL
register pair.
C016 H RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040 H = 05H
C041 H = 01 H
C042 H = 02H
C043 H = 03 H
C044 H = 04H
C045 H = 05H
C046 H = ?
C047 H = ?

After Execution:

A=

B=

C=

F=

C040 H = 05H
C041 H = 01 H
C042 H = 02H
C043 H = 03 H
C044 H = 04H
C045 H = 05H
C046 H =
C047 H =

F= S Z X AC X P X CY
Program-6
Two numbers are stored in consecutive memory location starting from C040 H. Write an Assembly
language program to subtract the numbers and store the absolute difference result in the next memory
location.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C001 H 40
C002 H C0

C003 H MOV A , M ;Copy the memory location content


pointed by HL register pair to
accumulator
C004 H INX H ;Increment the memory location of HL
register pair by 1
C005 H SUB M ;Subtract the data content of memory
pointed by register pair HL with the
data content of accumulator
C006 H JP DOWN ; If the result in accumulator is
positive (S=0) then jump to memory
C007 H 0B location C00BH.
C008 H C0

C009 H CMA ;Compliment the data content of


accumulator
C00A H INR A ;Increment the data content of
accumulator by 1
C00B H DOWN: INX H ; Increment the content of HL register
pair by 1 to get next location.
C00C H MOV M ,A ;Copy the data content of accumulator
to memory location pointed by HL
register pair
C00D H RST 1 ;Stop the execution
OUTPUT:

Case I:

Before Execution:

C040 H = 09 H
C041 H = 04 H
C042 H = ?

After Execution:

A=

F=

C040 H = 09 H
C041 H = 04 H
C042 H =

F= S Z X AC X P X CY

Case II:

Before Execution:

C040 H = 04 H
C041 H= 09 H
C042 H = ?

After Execution:

A=

F=

C040 H = 04 H
C041 H= 09 H
C042 H =

F= S Z X AC X P X CY
Program-7
A block of data is stored in memory location starting from C040 H. Length of the block is stored in register B.
Write an Assembly language program to find the largest number from the given block of data and store it at
the end of the block.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C001 H 40
C002 H C0

C003 H MVI A, 00 H ;Assign the lowest value of data to


accumulator
C004 H 00
C005 H MVI B, 05 H ;Set the counter for 05 numbers in
register B
C006 H 05

C007 H UP: CMP M ;Compare the data content of memory


pointed by HL register pair with the
data content of accumulator
C008 H JNC DOWN ; If carry flag is not set (CY=0) then jump
to memory location C00CH to get next
C009 H 0C number.
C00A H C0
C00B H MOV A , M ;Copy the data content of memory
location pointed by HL register pair to
accumulator
C00C H DOWN: INX H ;Increment the memory location
pointed HL register pair by 1
C00D H DCR B ;Decrement the counter by 1

C00E H JNZ UP ;If counter  0 (reg. B  0 )then jump


to memory location C007H.
C00F H 07
C010 H C0

C011 H MOV M , A ;Store the largest number at the end of


memory block
C012 H RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040 H = 01 H
C041 H = 02 H
C042 H = 0A H
C043 H = 04 H
C044 H = 05 H
C045 H = ?

After Execution:

B=

F=

C040 H = 01 H
C041 H = 02 H
C042 H = 0A H
C043 H = 04 H
C044 H = 05 H
C045 H =

F= S Z X AC X P X CY
Program-8
A block of data is stored in memory location starting from C040 H. Length of the block is stored in register
B. Write an Assembly language program to find the smallest number from the given block of data and
store it at the end of the block.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C001 H 40
C002 H C0

C003 H MVI A, FF H ;Assign the highest value of data to


accumulator
C004 H FF
C005 H MVI B, 05 H ;Set the counter for 05 numbers in
register B
C006 H 05
C007 H UP: CMP M ;Compare the data content of memory
whose address is in register pair HL with
the data content of accumulator
C008 H JC DOWN ;If carry flag is set then jump to
memory location C00C
C009 H 0C
C00A H C0
C00B H MOV A , M ;Copy the data content of memory
whose address is in HL register pair
to the accumulator
C00C H DOWN: INX H ;Increment the memory location of HL
register pair by 1
C00D H DCR B ;Decrement the counter by 1
C00E H JNZ UP ;If counter  0 (reg. B  0 )then jump
to memory location C007H.
C00F H 07
C010 H C0

C011 H MOV M , A ;Store the smallest number at the end


of memory block
C012 H RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040 H = 06 H
C041 H = 07 H
C042 H = 0A H
C043 H = 08 H
C044 H = 01 H
C045 H = ?

After Execution:

A=

B=

F=

C040 H = 06 H
C041 H = 07 H
C042 H = 0A H
C043 H = 08 H
C044 H = 01 H
C045 H =

F= S Z X AC X P X CY
Program-9
A block of data is stored in memory location starting from C040 H. Length of the block is stored in
register B. Write an Assembly language program to find the first occurrence of the number AB H from
the given block of data and if the number is not found store FFFF H in HL – pair.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C001 H 40

C002 H C0
C003 H MVI A, AB H ;Load the data AB H to accumulator

C004 H AB
C005 H MVI B, 05 H ;Set the counter for 05 numbers in
register B
C006 H 05
C007 H UP: CMP M ;Compare content of memory pointed
by HL register pair with the data
content of accumulator
C008 H JZ DOWN ;If Zero flag is set then jump to
memory location C013H.
C009 H 13
C00A H C0

C00B H INX H ;Increment the content of HL


register pair by 1
C00C H DCR B ;Decrement the counter by 1
C00D H JNZ UP ;If counter  0 (reg. B  0 )then jump
to memory location C007H
C00E H 07

C00F H C0

C010 H LXI H, FFFF H ;Initialize the register pair HL to


memory location FFFF H
C011 H FF
C012 H FF

C013 H DOWN: RST 1 ;Stop the execution


OUTPUT:

Case I:
Before Execution:
C040H = 01 H
C041H = 02 H
C042H = AB H
C043H = 04 H
C044H= AB H

After Execution:

A=

B=

H=

L =

F =

F= S Z X AC X P X CY

Case II:
Before Execution:
C040H= 01 H
C041H = 02 H
C042H = 03 H
C043H = 04 H
C044H = 05 H

After Execution:

A=

B=

H=

L =

F =

F= S Z X AC X P X CY
Program-10
A block of data is stored in memory location starting from C040 H. Length of the block is stored in register
B. Write an Assembly language program to find the number of times (COUNT) the data AB H occurred
from the given block of data and store the result at the end of the block.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C001 H 40
C002 H C0

C003 H MVI A, AB H ;Load the data AB H to accumulator


C004 H AB
C005 H MVI B, 05 H ;Set the counter for 05 numbers in
register B
C006 H 05
C007 H MVI C , 00 H ;Clear the data content of register C
C008 H 00
C009 H UP: CMP M ;Compare content of memory pointed
by HL register pair with the data
content of accumulator
C00A H JNZ DOWN ;If Zero flag is reset (Z 0) then
jump to memory location C00EH
C00B H 0E
C00C H C0
C00D H INR C ;Increment the data content of
register C by 1
C00E H DOWN: INX H ;Increment HL register pair by 1

C00F H DCR B ;Decrement the counter by 1

C010 H JNZ UP ;If counter  0 (reg. B  0 )then jump


to memory location C009H.
C011 H 09

C012 H C0

C013 H MOV M , C ;Copy the data content of register C to


memory location pointed by HL
register pair
C014 H RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040 H = AB H
C041 H = 02 H
C042 H = AB H
C043 H = 04 H
C044 H = AB H
C045 H = ?

After Execution:

A=

B=

C=

F=

C040 H = AB H
C041 H = 02 H
C042 H = AB H
C043 H = 04 H
C044 H = AB H
C045 H =

F= S Z X AC X P X CY
Program-11
A block of data is stored in memory location starting from C040 H. Length of the block is stored in
register B. Write a program to find the total count of odd numbers from the given block of data and
stored it at the end of block.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C001 H 40

C002 H C0
C003 H MVI B, 05 H ;Set the counter for 05 numbers in
register B
C004 H 05
C005 H MVI C , 00 H ;Clear the data content of register C
C006 H 00
C007 H UP: MOV A , M ;Copy the memory content pointed by HL
register pair to accumulator
C008 H RRC ;Rotate the data content of accumulator
1-bit position to the right L.S.B. will shift
in carry as well as in M.S.B.

C009 H JNC DOWN ;If carry flag is reset then jump to


memory location C00DH
C00A H 0D

C00B H C0
C00C H INR C ;Increment the data content of
Register C by 1
C00D H DOWN: INX H ;Increment the memory location of HL
register pair by 1
C00E H DCR B ;Decrement the counter by 1
C00F H JNZ UP ; If counter  0 (reg. B  0) then jump to
memory location C007H.
C010 H
07
C011 H
C0
C012 H MOV M , C ;Store the count of odd numbers in the
next memory location pointed by HL
register pair.
C013 RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040H = 01 H
C041H = 02 H
C042H = 03 H
C043H = 04 H
C044H = 05 H

After Execution:

A=

B=

C=

F=

C040H = 01 H
C041H = 02 H
C042H = 03 H
C043H = 04 H
C044H = 05 H
C045H=

F= AC CY
Program-12
A block of data is stored in memory location starting from C040 H. Length of the block is stored in
register B. Write a program to find the total count of even numbers from the given block of data and
stored it at the end of block.

Memory Op- Labels Mnemonics Comments


Location Code
C000 LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C001 H 40
C002 H C0

C003 H MVI B, 05 H ;Set the counter for 05 numbers in


register B
C004 H 05

C005 H MVI C , 00 H ;Clear the data content of register C


C006 H 00
C007 H UP: MOV A , M ;Copy the memory content pointed by
HL register pair to accumulator
C008 H RRC ;Rotate the data content of accumulator
1-bit position to the right L.S.B. will shift
in carry as well as in M.S.B.

C009 H JC DOWN ;If carry flag is set then jump to


memory location C00DH
C00A H 0D
C00B H C0
C00C H INR C ;Increment the data content of
register C by 1
C00D H DOWN: INX H ; Increment HL register pair by 1to get
next memory location.
C00E H DCR B ;Decrement the counter by 1
C00F H JNZ UP ; If counter  0 (reg. B  0 ) then jump
to memory location C007H.
C010 H
07
C011 H
C0
C012 H MOV M , C ;Store the count of odd numbers in the
next memory location pointed by register
pair HL
C013 H RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040H = 01 H
C041H = 02 H
C042H = 03 H
C043H= 04 H
C044H = 05 H

After Execution:

A=

B=

C=

F=

C040H = 01 H
C041H = 02 H
C042H = 03 H
C043H = 04 H
C044H = 05 H
C045H=

F= AC CY
Program-13
An 8-bit number is stored in memory location C040H. Write a program to find the total number of
ones present in the given number and store result in C050H.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to memory
location C040 H
C001 H 40
C002 H C0
C003 H MVI B, 08 H ;Set counter for 08 numbers in register B

C004 H 08
C005 H MVI C , 00 H ;Clear the data content of register C

C006 H 00
C007 H MOV A , M ; Copy the memory content pointed by HL
register pair to accumulator.
C008 H UP: RRC ;Rotate the data content of accumulator 1-bit
position to the right L.S.B. will shift in carry as
well as in M.S.B.
C009 H JNC DOWN ;If carry flag is reset then jump to memory
location C00DH
C00A H 0D

C00B H C0
C00C H INR C ;Increment the data content of
register C by 1
C00D H DOWN: DCR B ;Decrement the counter by 1
C00E H JNZ UP ;If counter  0 (reg. B  0 )then jump to
memory location C008H.
C00F H
08
C010 H
C0
C011 H MOV A, C ; Move the data content of C register to
accumulator.
C012 H STA C050H ;Store the count of 1s in memory location
C050H
C013 H 50

C014 H C0

C015 H RST 1 ;Stop the execution


OUTPUT:

Before Execution:

C040H = 23 H

After Execution:

A=

B=

C=

F=

C040H = 23 H
C050H =

F= AC CY
Program-14
An 8-bit number is stored in memory location C040H. Write a program to find the total number of
zeros present in the given number and store result in C050H.

Memory Op- Labels Mnemonics Comments


Location Code
C000 LXI H, C040H ;Initialize the register pair HL to memory
location C040 H
C001 H 40
C002 H C0
C003 H MVI B, 08 H ;Set counter for 08 numbers in register B

C004 H 08
C005 H MVI C , 00 H ;Clear the data content of register C

C006 H 00
C007 H MOV A , M ; Copy the memory content pointed by HL
register pair to accumulator
C008 H UP: RRC ;Rotate the data content of accumulator 1-bit
position to the right L.S.B. will shift in carry as
well as in M.S.B.
C009 H JC DOWN ;If carry flag is set then jump to memory
location C00DH
C00A H 0D

C00B H C0
C00C H INR C ;Increment the data content of
register C by 1
C00D H DOWN: DCR B ;Decrement the counter by 1
C00E H JNZ UP ;If counter  0 (reg. B  0 )then jump to
memory location C008H
C00F H
08
C010 H
C0
C011 H MOV A, C ; Move the data content of C register to
accumulator.
C012 H STA C050H ;Store the count of 0s in memory location
C050H
C013 H 50

C014 H C0

C015 H RST 1 ;Stop the execution


OUTPUT:

Before Execution:

C040H = 23 H

After Execution:

A=

B=

C=

F=

C040H = 23 H
C050H =

F= AC CY
Program-15
Two numbers are stored in consecutive memory location starting from C040 H. Write an Assembly
language program to multiply the numbers and store the result in the next memory location.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H XRA A ;Clear the data content of accumulator

C001 H MVI C, 00H ; Initialize Reg. C to zero


C002 H 00
C003 H LXI H, C040H ;Initialize the register pair HL to
memory location C040 H
C004 H 40
C005 H C0
C006 H MOV B, M ;Copy the first number as counter stored
at memory location pointed by register
pair HL to reg. B
C007 H INX H ; Increment the memory location pointed
by HL register to get next location.
C008 H UP: ADD M ;Add the data content memory whose
address is in register pair HL to
accumulator
C009 H JNC DOWN ; jump to memory location C00DH if
cy=0,
C00A H 0D
C00B H C0
C00C H INR C ; Increment reg. C as carry

C00D H DOWN: DCR B ;Decrement the counter by 1


C00E H JNZ UP ; If counter  0(reg. B  0) then jump to
memory location C008H.
C00F H 08

C010 H C0
C011 H INX H ; Increment the memory location pointed
by HL register to get next location.
C012 H MOV M ,A ;Copy the data content of accumulator to
memory location pointed by register pair
HL
C013 H INX H ; Increment the memory location pointed
by HL register to get next location.
C014 H MOV M, C ;copy carry content(reg. C) in memory
location pointed by register pair HL
C015 H RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040 H = 05H
C041 H = 02H
C042 H = ?
C043 H = ?

After Execution:

A=

B=

F=

C040 H = 05 H
C041 H = 02 H
C042 H =
C043 H =

F= S Z X AC X P X CY
Program-16
A one byte number is stored in memory location starting from C030 H. Write a program to separate the
two nibbles of the one byte number and store them in the next memory location. Also write a program to
multiply the separated nibbles and store the result at the end of the block

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C030H ;Initialize the register pair HL to
memory location C030 H
C001 H 30
C002 H C0
C003 H MOV A , M ; Copy the memory content pointed by HL
register pair to accumulator
C004 H MOV B, A ; Copy original number in B register.
C005 H ANI , 0F H ;AND immediately the data 0F H with
the data content of accumulator
C006 H 0F
C007 H INX H ;Increment the memory location pointed
by HL register pair by 1
C008 H MOV M ,A ;Store the separated nibble to memory
location pointed by HL register pair
C009 H MOV C,A ;store separated nibble in reg. C also to
make counter
C00A H MOV A,B ;Copy the original no again in accumulator

C00B H RRC ;Rotate the data bit of accumulator one bit


position to right L.S.B will shift in carry as
well as in M.S.B
C00C H RRC ;Rotate the data bit of accumulator
one bit position to right L.S.B will shift in
carry as well as in M.S.B
C00D H RRC ;Rotate the data bit of accumulator one bit
position to right L.S.B will shift in carry as
well as in M.S.B
C00E H RRC ;Rotate the data bit of accumulator one bit
position to right L.S.B will shift
in carry as well as in M.S.B
C00F H ANI , 0F H
;AND immediately the data 0F H with the
C010 H data content of accumulator
0F
C011 H INX H ;Increment the memory location pointed
HL register pair by 1
C012 H MOV M , A ;Store the separated nibble to memory
location pointed by register HL pair
C013 H XRA A ;Clear the data content of accumulator

C014 H UP: ADD M ;Add the data content of register pair


HL to accumulator
C015 H DCR C ;Decrement the data content of
register B by 1
C016 H JNZ UP ;If counter  0(reg. C  0 ) then jump to
memory location C014
C017 H 14

C018 H C0

C019 H INX H ;Increment the memory location pointed by


HL register pair by 1
C01A H MOV M ,A ;Store the result of multiplication of the
separated nibble at the end of
block
C01B H RST 1 ;Stop the execution

OUTPUT:

Before Execution:

C030H = 32 H

After Execution:

A=

B=

C=

F=

C030 H = 32H
C031 H =
C032 H =
C033 H =

F= AC CY
Program-17
Two numbers are stored in memory location starting from C040H. Write a program to divide the two
numbers and store the quotient and remainder in the next consecutive memory locations.

Memory Op- Labels Mnemonics Comments


Location Code
C000 H LXI H, C040H ;Initialize the register pair HL to
memory location C040H
C001 H 40

C002 H C0

C003 H MVI C , 00H ;Clear the data content ofregister C


C004 H 00
C005 H MOV A , M ; Copy the memory content pointed by
HL register pair to accumulator
C006 H INX H ;Increment the content of HL register
pair by 1
C007 H UP: CMP M ;Compare the memory content pointed
by HL pair with the data content of
accumulator
C008 H JC DOWN ;If carry flag is set then jumpto memory
location C010H.
C009 H 10
C00A H C0
C00B H SUB M ;Subtract the memory content pointed by
register pair HL from data content of
accumulator
C00C H INR C ;Increment the data content of register
C by 1
C00D H JMP UP ;Jump to memory location
C007H unconditionally.
C00E H 07
C00F H C0

C010 H DOWN: INX H ;Increment HL register pair by 1

C011 H MOV M , C ;Store the quotient in thenext


memory location
C012 H INX H ;Increment HL register pair by 1

C013 H MOV M , A ;Store the remainder in the next


memory location
C014 H RST 1 ;Stop the execution
OUTPUT:

Before Execution:

C040 = 09 H
C041 = 02 H

After Execution:

A=

C=

F=

C042 =
C043 =

F= AC CY
Program-18
Write a program in assembly language to interchange digits of a number stored in C040H. Store
new number in C041H. Add new number with original number and store result in C042H.

Address Hex code Label Mnemonics Comments

C000 Start: LDA CO40 ; Load accumulator with the content of


memory location C040H.
C001 40

C002 C0

C003 MOV B, A ; Store original number in reg. B

C004 RLC ; Rotate Accumulator content by 1 bit

C005 RLC ; Rotate Accumulator content by 1 bit

C006 RLC ; Rotate Accumulator content by 1 bit

C007 RLC ; Rotate Accumulator content by 1 bit

C008 STA C041 ; Store new number in C041H

C009 41

C00A C0

C00B 80 ADD B ; Add new number with original number.

C00C STA C042 ; Store final result in C042H

C00D 42

C00E C0

C00F CF RST 1 ; Stop Program


OUTPUT:

Before Execution:

C040 = 09 H

After Execution:

A=

B=

F=

C041 =
C042 =

F= AC CY
Program-19

Write a program in assembly language to fill the memory locations C400H to C40FH with hex
number 00H to 0FH.

Address Hex code Label Mnemonics Comments

C000 Start: LXI H, CO40 ; Initialize the register pair HL to memory


location C040H
C001 40

C002 C0

C003 MVI B, 10H ; Set counter for 16 numbers in register B

C004 10

C005 MVI A, 00H ; Store first number in Accumulator

C006 00

C007 UP: MOV M, A ; copy accumulator content in to memory


location whose address is in HL register pair.
C008 INR A ; Increment accumulator content by one.

C009 INX H ; Increment HL register pair by 1

C00A DCR B ; Decrement counter by 1.

C00B JNZ UP ; If counter  0(reg. B  0 ) then jump to memory


location C007H.
C00C 07

C00D C0

C00E CF RST 1 ; Stop Program


OUTPUT:

After Execution:

A=

B=

F=

C040 H =
C041 H =
C042 H =
C043 H =
C044 H =
C045 H =
C046 H =
C047 H =
C048 H=
C049 H=
C04A H=
C04B H=
C04C H=
C04D H=
C04E H=
C04F H=

F= S Z X AC X P X CY

You might also like