Sie sind auf Seite 1von 12

CS II (8085 ALP Codes)

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 .

Label Mnemonic Comment


LXI H, 1050H ; Initialize HL pair with 1050H
LXI B, 1070H ; Initialize BC pair with 1070H
MVI D, 0A H ; move 0A H in reg. D
: UP MOV A,M ; Move data in memory to accumulator
STAX B ;store accumulator data to BC reg pair.
INX H ; increment HL pair by 1
INX B ;Increment BC pair by 1
DCR D ;Decrement counter by 1
JNZ UP: ;Jump to label UP if D reg. is not zero
RST 1 ;stop the processing

2. Write an assembly language program to count number of even data bits occurring in a block starting
from memory location C030H to C039H

Label Mnemonic Comment


LXI H, C030H ;Initialize HL pair with C030 H
MVI D,0AH ;Initialize REG D with 0AH
MVI C,00H ;Initialize reg C with 00H
:UP MOV A,M ; Move data in memory to accumulator
RRC ;Rotate accumulator right
JC NEXT: ;Jump if Carry is present to NEXT
INR C ;Increment reg C by 1
:NEXT INX H ;Increment HL pair by 1
DCR D ;Decrement reg D by 1
JNZ UP: ;Jump if not zero to UP
MOV M,C ;Move data in reg C to HL pair
RST 1 ;stop the processing

3. Write an assembly language program to add all odd numbers stored in a memory block of 10 locations
starting from 2000H. Store two bytes sum of memory location starting from 3000H.

Label Mnemonic Comment


LXI H,2000H ;Initialize HL pair with 2000H
MVI B,0AH ;Move 0A H in B reg.
MVI D,00H ;Move 00 H in D reg.
MVI E,00H ;Move 00 H in E reg.
:UP MOV A,M ; Move data in memory to accumulator
RRC ;Rotate accumulator right
JNC DOWN: ;Jump if Carry is absent to DOWN
MOV A,E ;Move Contents of E reg. to A reg.
ADD M ; Move data in HL to Accumulator.
MOV E,A ;Move Contents of A reg. to E reg.
JNC DOWN ;Jump if Carry is absent to DOWN
INR D ;Increment reg D by 1
:DOWN INX H ;Increment HL pair by 1
DCR B ;Decrement reg B by 1
JNZ UP: ;Jump if not zero to UP
MOV A,E ;Move Contents of E reg. to A reg.
STA 3000H ;Store data in Accumulator to 3000H
MOV A,D ;Move Contents of D reg. to A reg.
STA 3001H ;Store data in Accumulator to 3001H
RST 1 ;stop the processing

4. Write a program in assembly language to find the position of data 05H in a block of memory D005H. If
data is found then store the position of a data at memory location D100H else store 00H at the same
memory location.

Label Mnemonic Comment


LXI H,D001H ;Initialize HL pair with D001H
MVI A, 05H ; Immediately move 05H to reg A
MVI B, 05 H ; Immediately move 05H to reg B
:UP CMP M ;Compare data in HL pair with Accumulator
JZ NEXT : ;Jump if Zero to NEXT
INX H ;Increment HL pair by 1
DCR B ;Decrement reg B by 1
JNZ UP : ;Jump if not zero to UP
LXI H, D100 H ;Initialize HL pair with D100H
MVI M,00H ;Move 00H to HL pair
:NEXT RST 1 ; Stop the processing.

5. Write a program is assembly language to double the contents of block memory from Doo1H and Store
the doubled contents at same memory locations.

Label Mnemonic Comment


LXI H,D001H ;Initialize HL with at D001 H
MVI B,05 H ;Move 05 counter in B reg
:UP MOV A,M ; Move memory data in A reg.
ADD A ;add A with A reg
MOV M,A ;move result in A to same memory
INX H ;increment HL pair by 1
DCR B ;decrement reg B by 1
JNZ UP: ; jump to label UP if B not zero
RST 1 ;stop execution
6. 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

7. A block of data is stored in memory locations from 8101 H to 81FF H. Write an assembly language
program to transfer the block in reverse order to Memory Locations 8200 H and onwards.

Label Mnemonic Comment


LXI H, 8101H ; Initialize HL pair with 8101H
LXI B, 82FEH ; Initialize BC pair with 82FEH
MVI D, FE H ; move FE H in reg.D
: UP MOV A,M ; Move data in memory to accumulator
STAX B ; store accumulator data to BC reg pair.
INX H ; increment HL pair by 1
DCX B ; Decrement BC pair by 1
DCR D ;Decrement counter by 1
JNZ UP: ;Jump to label UP if D reg. is not zero
RST 1 ;stop the processing

8. Write an assembly language program to exchange 8 bit number stored in memory location 4000 H.
Store new number at memory locations 4001 H.

Label Mnemonic Comment


LXI H,4000H ;Initialize HL pair with 4000 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 4001 H ;Store accumulator contents in address 4001 H
RST 1 ;stop the processing
9. Write an assembly language program to count the number of even data bytes occurring in a block
starting from the memory location 7501 H to 75FF H . Store the result at the memory location 7600 H

Label Mnemonic Comment


LXI H, 7501H ;Initialize HL pair with 7501 H
MVI D,FEH ;Initialize REG D with FEH
MVI C,00H ;Initialize reg C with 00H
:UP MOV A,M ; Move data in memory to accumulator
RRC ;Rotate accumulator right
JC NEXT: ;Jump if Carry is present to NEXT
INR C ;Increment reg C by 1
:NEXT INX H ;Increment HL pair by 1
DCR D ;Decrement reg D by 1
JNZ UP: ;Jump if not zero to UP
MOV M,C ;Move data in reg C to HL pair
RST 1 ;stop the processing

10. Write an assembly language program to copy the contents of a block of memory which is from
2501H to 2505H, to another block begins from 3501H.

Label Mnemonic Comment


LXI H, 2501H ; Initialize HL pair with 2501H
LXI B, 3501H ; Initialize BC pair with 3501H
MVI D, 05 H ; move 05 H in reg.D
: UP MOV A,M ; Move data in memory to accumulator
STAX B ;store accumulator data to BC reg pair.
INX H ; increment HL pair by 1
INX B ;Increment BC pair by 1
DCR D ;Decrement counter by 1
JNZ UP: ;Jump to label UP if D reg. is not zero
RST 1 ;stop the processing

11)Write an ALP to rotate the contents of memory which is starting from D000H towards left by one bit
position and add the original contents with the rotated number and store the result from D0001H.

Label Mnemonics Comments


LXI H, D000H ;Initialize HL rp to D000H memory location
MOV B,M ;Copy the contents of memory location to register B.
MOV A,M ;Copy the contents of memory location to Acc..
RLC ;Rotate Acc to left by one bit
ADD B ;Add the contents of B with Acc.
STA D0001H ;Store the result in Acc. to D001H
HLT ;Stop processing
12) Write an ALP to subtract the number stored in memory location 3601H from the number stored in
memory location 3600H. Store the positive result at D0002H.

Label Mnemonics Comments


LXI H, 3600H ;Initialize HL rp to 3600H memory location
MOV A,M ;Copy the contents of memory location to Acc.
INX H ;Increment HL rp by one
SUB M ;Subtract the contents of memory location from Acc.
JM DOWN: ;Jump if result is negative to down.
STA D0002H ;Store the result in Acc. at D002H.
:DOWN CMA ;Complement Acc.
INR A ;Increment Acc. by one.
STA D0002H ;Store the result in Acc. at D002H.
HLT ;Stop processing

13)Write an ALP to divide the number stored in memory location 2050H by the non-zero byte stored in
memory location 2501H.Place the result at memory location 2052H and store the remainder at 2053H.

Label Mnemonics Comments


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
CMP M ;Compare the contents of HL rp with Acc.
JC DOWN: ;Jump if carry flag is set to label DOWN.
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.
HLT ;Stop processing

14)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.

Label Mnemonics Comments


LXI H, D100H ;Initialize HL rp to D100H memory location
LXI B, D2FFH ;Initialize HL rp to D2FFH memory location
MVI D,FFH ;Initialize counter to FFH.
UP: MOV A,M ;Copy the contents of memory location to Acc.
STAX B ;Store contents of Acc.to mem location pointed by BC rp
INX H ;Increment HL rp by one
DCR B ;Decrement BC rp by one
DCR D ;Decrement counter by one
JNZ UP ;Jump if D≠0 to label UP
HLT ;Stop processing
15) 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 Mnemonics Comments


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 thye 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
HLT ;Stop Processing

16) 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 Mnemonics Comments


LXI H, C001H ;Initialize HL rp to 2501H memory location
UP: MOV B,M ;Copy the contents of memory location to register B.
MOV A,FFH ;Initialize Acc to largest number FFH.
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.
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
HLT ;Stop Processing

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 Mnemonics Comments


LXI H, A001H ;Initialize HL rp to 2501H memory location
UP: MOV B,M ;Copy the contents of memory location to register B.
MVI D,00H ;Initialize register D to 00H
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
HLT ;Stop processing

18) Write an ALP to copy the contents of block of data having starting address from 2000H to new destination
3000H. Length of the block is stored at 1FFFH.

Label Mnemonics Comments


LXI H, 1FFFH ;Initialize HL rp to 1FFFH memory location
MOV D,M ;Move memory contents to Reg D.
LXI B, 3000H ;Initialize HL rp to 3000H memory location
:UP MOV A,M ;Copy the contents of memory location to Acc.
STAX B ;Store contents of Acc. to mem location pointed by BC rp.
INX H ;Increment HL rp by one
INX B ;Increment BC rp by one
DCR D ;Decrement counter by one
JNZ UP: ;Jump if D≠0 to label UP
HLT ;Stop processing

19) A block of data is stored in memory starting from memory location 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 Mnemonics Comments


START: MVI B,00H ;Initialize register B to 00H
LXI H, D000H ;Initialize HL rp to 2501H 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
20. Write an ALP to exchange the two hexadecimal digits of a number stored at memory location 2500H. store the new
number at memory location 2501 H.

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
HLT ;stop the processing

21. A hex number is stored at location AB00 H. Write an ALP to interchange its digit .The new no is to be stored At
AB01 H. Add the original number with new number and store result at location ABCD H.

Label Mnemonic Comment


LXI H,AB00H ;Initialize HL pair with AB00 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
INX H ;Increment HL pair by 1
MOV M,A ;move accumulator data to AB01 H
ADD M ;Add data at AB01H
STA ABCD H ;Store result at ABCD H
RST 1 ; Stop the execution

22. Write an ALP to add two BCD 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
23. Write an ALP to find 2’s complement of 8 bit number stored in memory location C000 H. Store the
Result at memory location C001 H.

Label Mnemonic Comment


LXI H,C000 H ;Initialize HL pair with C000H
MOV A,M ; Move data in HL to Accumulator.
CMA ; Complement accumulator data.
ADI 01H ;Add 01 H to Accumulator
INX H ;Increment HL by 1
MOV M,A ; Move Accumulator data to Memory.
RST1 ; Stop the processing.

24. Write an ALP to copy the contents of a block of memory which is from 2501H to 2505 H, to another
Block begins from 3501 H.

Label Mnemonic Comment


LXI H, 2501H ; Initialize HL pair with 2501H
LXI B, 3501H ; Initialize BC pair with 3501H
MVI D, 05 H ; move 05 H in reg.D
: UP MOV A,M ; Move data in memory to accumulator
STAX B ;store accumulator data to BC reg pair.
INX H ; increment HL pair by 1
INX B ;Increment BC pair by 1
DCR D ;Decrement counter by 1
JNZ UP: ;Jump to label UP if D reg. is not zero
RST 1 ;stop the processing

25. Write an ALP to rotate the content of memory location 0000 H towards left by one bit position and add original
contents with the rotated number and store the result from 00001 H.

Label Mnemonic Comment


LXI H,0000 H ; Initialize HL pair with 0000 H
MOV B,M ; Move memory data to B reg.
MOV A,M ;Move memory data to reg A reg.
RAL ;Rotate accumulator left .
ADD B ; Add reg. A and B
STA 0001 H ; Store accumulator data to address 0001 H
RST 1 ; stop the processing.
26. Write an ALP to double the contents of block of memory from 0001 H to 0000A H. Store the double contents at
same memory locations.

Label Mnemonic Comment


LXI H,0001H ;Initialize HL with at 0001 H
MVI B,0A H ;Move 0A counter in B reg
:UP MOV A,M ; Move memory data in A reg.
ADD A ;add A with A reg
MOV M,A ;move result in A to same memory
INX H ;increment HL pair by 1
DCR B ;decrement reg B by 1
JNZ UP: ; jump to label UP if B not zero
RST 1 ;stop execution

27. Write an ALP to count occurrence of the data ABH in a memory block .store count in memory location 4500 H.

Label Mnemonic Comment


LXI H, 44FBH ;initialize HL pair by 44FB 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 , 00 H ; 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 ; or 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
MOV M,C ;move Count in C to next memory location
RST 1 ; stop execution.

28. Write an ALP to find largest element in block of data. The length is in memory location D000 H.
Assume that all numbers are 8 bit unsigned binary numbers.

Label Mnemonic Comment


MVI A, 00 H ;Move 00 H in accumulator
LXI H, D000H ;initialize HL pair by D000 H
MOV B,M ; move D000 h data to B reg as counter.
INX H ;increment HL pair
:UP CMP M ;Compare Accumulator with memory
JNC NEXT : ; Jump if no carry to label NEXT
MOV A , M ; move larger no to accumulator
:NEXT INX H ; increment HL pair
DCR B ; Decrement block counter by 1.
JNZ UP : ;if not zero jump to label UP
MOV M , A ; move the largest no to next memory.
RST 1 ; stop execution.
CS II Programs
(Practice Questions)

29. Write an assembly language program to fill the memory block of 20 memory locations starting from
2000 H with data bytes 00 H to FF H at every alternate memory location.
30. A block of data is stored in memory location starting from memory location C040 . Another block of
data is stored in memory location starting from memory location C050. Length of the blocks is stored in
register D. Write a program to exchange / swap the data contents of both these blocks.
31. Two numbers are stored in consecutive memory location starting from C040. Write a program to
multiply the numbers and store the result in the next memory location.
32. Write a program to add all the even numbers stored in a memory Write a program to add all the
even numbers stored in a memory memory location starting from 3000 H.
33. A 4-byte number is stored in memory location starting from C040 beginning with lower order byte
byte. Another 4- byte number is stored in memory location starting from C050 beginning with lower
order byte. Write a program to add these two 4- byte numbers and store the result in memory location
starting from C040 beginning with lower order byte.
34. A block of data is stored in memory location starting from C041 . Length of the block is stored in
memory location C040. Write a program to add the data content of the memory location and store the
result at the end of the block.
35. An one byte data is stored in memory location starting from C040. Write a program to separate the
two nibbles of the one byte number and store it in the next memory location. Also write a program to
multiply the separated nibbles and store it at the end of the same block
36. Write a program to add twenty numbers store in memory location starting from C030 H. The length
of the block is stored at reg C. Store the two byte result at the end of the block beginning with lower
order byte.
37. A block of data is stored in memory location starting from C040 to C049. The length of block is stored
in reg.C. Write a program to find the smallest number from the given block of data and store it and the
end of the block.
38. A block of data is stored in memory location starting from D040 to D04A.Length of the block is
stored in register B Write a program to find the the first occurrence of the number 2A H. If the number
is not found store FFFF H in register pair HL.
39. Write an assembly language program to divide two numbers stored in consecutive memory location
starting from F030. Store the quotient and remainder at the end of the block.

40. A block of data is stored in memory location starting from C041. Length of the block is stored in
memory location C040. Write a program to add the data content of the memory location and store the
two byte result at the end of the block beginning with lower order byte.
41. Write a program to divide number at D068 H by a non zero number at D067H.Store the quotient at
D069 and remainder at D06AH.
42. A 4-byte number is stored in memory location starting from F050 beginning with lower order byte
byte. Another 4- byte number is stored in memory location starting from F060 beginning with lower
order byte. Write a program to add these two 4- byte numbers and store the result in memory location
starting from F050 beginning with lower order byte.
43. Write a program to find 2’s complement of a number stored in memory location E090 Store the
result to memory location C060.

Das könnte Ihnen auch gefallen