1.
Write a Program in assembly language to transfer a block of data from 1050 to 1059
to memory location whose starting addresses 1070 H.
Memory
Label Mnemonic Comment
Location
C500H LXI H, 1050H ; Initialize HL pair with 1050H
C503H LXI B, 1070H ; Initialize BC pair with 1070H
C506H MVI D, 0A H ; move 0A H in reg. D
C508H UP: MOV A,M ; Move data in memory to accumulator
C509H STAX B ;store accumulator data to BC reg pair.
C50AH INX H ; increment HL pair by 1
C50BH INX B ;Increment BC pair by 1
C50CH DCR D ;Decrement counter by 1
C50DH JNZ UP ;Jump to label UP if D reg. is not zero
C510H RST 1 ;stop the processing
2. Write an ALP to transfer of block of data which is starting from D100H to D1FFH, in
reverse order in new memory location at D200H.
Memory
Label Mnemonic Comment
Location
C500H LXI H, D100H ;Initialize HL rp to D100H memory location
C503H LXI B, D2FFH ;Initialize HL rp to D2FFH memory location
C506H MVI D,FFH ;Initialize counter to FFH.
C508H UP: MOV A,M ;Copy the contents of memory location to Acc.
C509H STAX B ;Store contents of [Link] mem location pointed by BC
C50AH INX H ;Increment HL rp by one
C50BH DCX B ;Decrement BC rp by one
C50CH DCR D ;Decrement counter by one
C50DH JNZ UP ;Jump if D≠0 to label UP
C510H RST 1 ;Stop processing
3. Write an assembly Language Program to fill the memory locations 4500H to 4504H
with the Hexadecimal numbers 09H to 0DH respectively.
Label Mnemonic Comment
MVI C, 05H ;Store 05H in C register
MVI A, 09H ;Store 09H in Accumulator
LXI H,4500H ;Set HL with 4500H
UP: MOV M,A ;Copy Accumulator to memory location.
INX H ;Increment HL rp by one
INR A ;Increment Accumulator by one
DCR C ;Decrement counter (Reg C) by one
JNZ UP ;Jump if D≠0 to label UP
RST 1 ;Stop processing
4. 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
Label Mnemonics Comments
LXI H, C040H ;Initialize the register pair HL to memory location C040H
LXI B, C050H ;Initialize the register pair BC to memory location C050H
MVI D, 05 H ;Set the counter for 05 numbers in register D
;Load the data contents of memory location whose
UP: LDAX B
address is in register pair BC to accumulator
MOV E , A ;Copy the data content of accumulator to register E
;Copy the data content of memory location whose
MOV A ,M
address is in register pair HL to accumulator.
;Store the data content of accumulator to memory
STAX B
location whose address is in register pair BC
MOV M , E ;Copy the data content of register E to register pair HL
INX H ; Increment the content of HL register pair by 1 .
INX B ; Increment the content of BC register pair by 1 .
DCR D ; Decrement the counter by 1
JNZ UP ; If reg. D i s 0 then jump to memory location C008H
RST 1 ;Stop the execution
5. 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.
Labels Mnemonics Comments
XRA A ;Clear the data content of accumulator
MVI C , 00 H ; Initialize Reg. C to zero
MVI B, 05 H ;Set the counter for 05 numbers in register B
LXI H, C040H ;Initialize HL to memory location C040 H
UP: ADD M ;Add the Memory content M to accumulator
JNC Down ;If cy=0,store result and if cy=1 store carry & result
INR C ;Increment reg. C for carry
Down: INX H ; Increment the content of HL register pair by 1 .
DCR B ;Decrement the counter by 1
JNZ UP ;If reg. B = 0 then jump to memory location C008H.
MOV M ,A ;Copy content of accumulator to Memory location
INX H ;Increment the memory location HL by 1
MOV M,C ; Copy content of reg. C to Memory location.
RST 1 ;Stop the execution
6. Write an ALP to add two numbers stored at locations AB00H and AB01 H. Store BCD
result in location AB02 H and onwards starting with LSB.
Label Mnemonic Comment
LHLD AB00 H ;Load H and L reg. with contents AB00 And AB01 H
MVI C,00 H ;Move 00 H in C reg.
MOV A,H ;Move H reg. contents to A reg.
ADD L ;Add contents of A and L reg
DAA ;Adjust the result in accumulator
JNC DOWN ;Jump to label DOWN
INR C ;Increment reg. C by one
DOWN: STA AB02 H ;Store A reg. contents to address AB02 H
MOV A,C ;Move Contents of C reg. to A reg.
STA AB03 H ;Store A. reg contents to AB03 H.
RST1 ;stop the processing
7. 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.
Labels Mnemonics Comments
XRA A ;Clear the data content of accumulator
MVI C, 00H ;Initialize Reg. C to zero
LXI H, C040H ;Initialize register pair HL to memory location C040 H
MOV B, M ;Copy the first number as counter reg. B
INX H ; Increment Reg pair HL by 01.
UP: ADD M ;Add the data content of memory to accumulator
JNC DOWN ; Jump to memory location DOWN if cy=0.
INR C ;Increment reg. C as carry
DOWN: DCR B ;Decrement the counter by 1
JNZ UP ;If reg. B = 0 then jump to memory location C008H.
INX H ; Increment the HL register pair by 1.
MOV M ,A ; Copy content of accumulator to memory location.
INX H ; Increment the HL register pair by 1.
MOV M, C ; Copy content of reg C to memory location.
RST 1 ;Stop the execution
8. Write an ALP to divide the number stored in memory location 2050H by the non-zero
byte stored in memory location [Link] the result at memory location 2052H
and store the reminder at 2053H.
Label Mnemonic Comment
LXI H, 2050H ;Initialize HL rp to 2050H memory location
MVI C,00H ;Initialize register C to 00.
MOV A,M ;Copy the contents of memory location to Acc.
INX H ;Increment HL rp by one
UP: CMP M ;Compare the contents of HL rp with Acc.
JC DOWN ;Jump if carry flag is set to label DOWN.
SUB M ;Subtract memory contents from A.
INR C ;Increment reg C by 1
JMP UP ;Jump to label UP
DOWN: INX H ;Complement Acc.
MOV M,C ;Copy the count in register C to memory location.
INX H ;Increment HL rp by one
MOV M,A ;Copy the contents of Acc to memory location.
RST 1 ;Stop processing
9. 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.
Labels Mnemonics Comments
LXI H, C040H ;Initialize the register pair HL to memory location C040 H
MOV A , M ;Copy the data content of register pair HL to accumulator
INX H ;Increment the memory location of HL register pair by 1
SUB M ;Subtract the data content of memory from accumulator
JP DOWN ; If the result in accumulator is positive then jump to DOWN.
CMA ;Compliment the data content of accumulator
INR A ;Increment the data content of accumulator by 1
DOWN: INX H ; Increment the content of HL register pair by 1 .
MOV M ,A ;Copy the data content of accumulator to memory location .
RST 1 ;Stop the execution
10. A series of number are stored in the memory location from C000H to C008H. Write
an ALP to find largest number among these numbers. Store the largest number in
memory location C009H.
Label Mnemonic Comment
LXI H, C000H ;Initialize HL rp to C000H memory location
MVI B,09H ;Copy the contents of memory location to register B.
MOV A,00H ;Initialize Acc to smallest number FFH.
UP: CMP M ;Compare the contents of Acc and memory location.
JNC DOWN ;If Carry flag is set(C=1) then jump to DOWN label
MOV A, M ;Copy thye contents of memory location to Acc.
DOWN: INX H ;Increment HL rp by one.
DCR B ;Decrement counter by one.
JNZ UP ;If B≠0 then jump to UP label
MOV M,A ;Copy thye contents of Acc. To memory location
RST 1 ;Stop Processing
11. A one byte data is stored in memory location C040H. WAP to separate the two
nibbles of the one byte number and store it in the next memory location.
Labels Mnemonics Comments
LXI H, C040H ;Initialize the register pair HL to memory location C030 H
MOV A , M ; Copy the memory content pair to accumulator
MOV B, A ; Copy original number in B register.
ANI 0F H ;AND immediately the data 0F H with accumulator
INX H ;Increment HL register pair by 1
MOV M ,A ; Store the separated nibble to memory location.
MOV A,B ;Copy the original no again in accumulator
;Rotate the data bit of accumulator one bit position to right
RRC
L.S.B will shift in carry as well as in M.S.B
;Rotate the data bit of accumulator one bit position to right
RRC
L.S.B will shift in carry as well as in M.S.B
;Rotate the data bit of accumulator one bit position to right
RRC
L.S.B will shift in carry as well as in M.S.B
;Rotate the data bit of accumulator one bit position to right
RRC
L.S.B will shift in carry as well as in M.S.B
ANI 0F H ;AND immediately the data 0F H with accumulator
INX H ;Increment HL register pair by 1
MOV M , A ;Store the separated nibble to memory location .
RST 1 ;stop the processing
12. A series of number are stored in the memory location from C000H to C008H. Write
an ALP to find smallest number among these numbers. Store the smallest number in
memory location C009H.
Label Mnemonic Comment
LXI H, C000H ;Initialize HL rp to C000H memory location
MVI B,09H ;Copy the contents of memory location to register B.
MOV A,FFH ;Initialize Acc to largest number FFH.
UP: CMP M ;Compare the contents of Acc and memory location.
JC DOWN ;If Carry flag is set(C=1) then jump to DOWN label
MOV A, M ;Copy thye contents of memory location to Acc.
DOWN: INX H ;Increment HL rp by one.
DCR B ;Decrement counter by one.
JNZ UP ;If B≠0 then jump to UP label
MOV M,A ;Copy thye contents of Acc. To memory location
RST 1 ;Stop Processing
13. Write a program to exchange the two nibbles, stored at 2500H. Store the exchanged
number at 2501H.
Label Mnemonic Comment
LXI H,2500H ;Initialize HL pair with 2500 H
MOV A,M ;Move HL data to accumulator
RRC ;Rotate accumulator right
RRC ;Rotate accumulator right
RRC ;Rotate accumulator right
RRC ;Rotate accumulator right
STA 2501 H ;Store accumulator contents in address 2501 H
RST 1 ;stop the processing
14. A block of data is stored in memory location starting from D001H. Length of the
block is stored in memory location D000H. Write an ALP to sort the contents of the
block in ascending order.
Label Mnemonic Comment
START: MVI B,00H ;Initialize register B to 00H
LXI H, D000H ;Initialize HL rp to D000H memory location
MOV C,M ;Copy the contents of memory location to register C.
INX H ;Increment HL rp by one
MOV A,M ;Copy the contents of memory location to Acc.
DCR C ;Increment BC rp by one
UP: INX H ;Decrement counter by one
CMP M ;Compare the contents of Acc and memory location.
JC DOWN ;If Carry flag is set(C=1) then jump to DOWN label
MOV D,M ;Copy the contents of memory location to register D.
MOV M,A ;Copy the contents of Acc to memory location.
DCX H ;Decrement HL rp by one
MOV M,D ;Copy the contents of register D to memory location.
INX H ;Increment HL rp by one
MVI B,01H ;Initialize register B to 01H
DOWN: DCR C ;Decrement counter C.
JNZ UP ;Jump if C≠0 to label UP
DCR B ;Decrement register B
JZ START ;If B=0 then jump to label START.
HLT ;Stop processing
15. Write an ALP to count occurrence of the data ABH in a memory block starting from
C400H and length of a block is 05. Store count in memory location 4500 H.
Label Mnemonic Comment
LXI H, C400H ;initialize HL pair by C400 H
MVI A, AB H ; move immediate no AB H in A reg
MVI B, 05 H ; move Immediate no. 05 in B reg a block counter.
MVI C,00H ; Use C reg as counter to count occurrence
UP: CMP M ; compare memory with A reg.
JNZ NEXT ;if zero flag not set go to label NEXT
INR C ; increment reg.C by 1
NEXT: INX H ;increment HL pair by 1
DCR B ;Decrement B reg
JNZ UP ; if not zero jump to label UP
LXI H, C500H ;initialize HL pair by C500 H
MOV M,C ;move Count in C to next memory location
RST 1 ; stop execution.
16. 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.
Labels Mnemonics Comments
LXI H, C040H ;Initialize register pair HL to memory location C040H
MVI A, AB H ;Load the data AB H to accumulator
MVI B, 05 H ;Set the counter for 05 numbers in register B
UP: CMP M ;Compare content of memory with accumulator
JZ DOWN ;If Zero flag is set then jump to memory location DOWN.
INX H ;Increment the content of HL register pair by 1
DCR B ;Decrement the counter by 1
JNZ UP ;If reg. B is 0 then jump to memory location UP
LXI H, FFFF H ;Initialize the register pair HL to memory location FFFF H
DOWN: RST 1 ;Stop the execution
17. Write an ALP to count the number of odd data bytes occurring in a block starting
from memory location A001H to A0FFH. Place the result at memory location B000H.
Label Mnemonic Comment
LXI H, A001H ;Initialize HL rp to A001H memory location
MVI B,FFH ;Copy the contents of memory location to register B.
MVI D,00H ;Initialize register D to 00H
UP: MOV A,M ;Copy the contents of memory location to Acc.
RRC ;Rotate Acc. To right by one bit.
JNC NEXT ;If not carry flag set(C=0) then jump to label NEXT
INR D ;Increment D reg
NEXT: INX H ;Increment HL rp by one.
DCR B ;Decrement counter by one.
JNZ UP ;If B≠0 then jump to UP label
MOV A,D ;Copy thye contents of register D to Acc.
STA B000H ;Store the count at B000H
RST 1 ;Stop processing
18. An 8 bit number is stored in the memory in the memory location 4400H. Write an
ALP to count ‘zero’ in the given number. Store the count in memory location 4500H.
Label Mnemonic Comment
LXI H, 4400H ;Initialize HL rp to 4400H memory location
UP: MOV B,M ;Copy the contents of memory location to register B.
MVI C,00H ;Initialize C to 00H
MVI E,08H ;Initialize register E to 08H(since data is 8 bit)
MOV A,B ;Copy the contents of register B to Acc.
RLC ;Rotate Acc. Left by one bit
MOV B,A ;Copy the contents of Acc. To register B
JC DOWN ;If Carry flag is set(C=1) then jump to DOWN label
INR C ;Increment register C
DCR E ;Decrement register E
JNZ UP ;If E≠0 then jump to UP.
MOV A,C ;Copy the contents of register C to Acc.
STA C500 ;Store the result at memory location C500H
RST 1 ;Stop Processing